本文介绍了更新到 Android Studio 2.3 后出现 Gradle 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gradle 构建失败并显示消息

The gradle build is failing with the message

 Error:Could not create parent directory for lock file C:\Program Files\Android\Android Studio\gradle\gradle-2.14.1\wrapper\dists\gradle-2.14.1-all\8bnwg5hd3w55iofp58khbp6yv\gradle-2.14.1-all.zip.lck

这是我的 build.gradle(Project)

This is my build.gradle(Project)

 // Top-level build file where you can add configuration options common to all sub-projects/modules.

 buildscript {
   repositories {
    jcenter()
}
    dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
 }

allprojects {
  repositories {
    jcenter()
  }
}

  task clean(type: Delete) {
    delete rootProject.buildDir
}

更新后所有项目都显示相同的错误.

All projects show the same error after the update.

推荐答案

我也遇到了类似的错误,下面的更改完成了工作.

I was also facing the similar error, below changes did the job.

问题是 Android Studio 2,3,它的默认 gradle 版本是 3.3.

The issue was Android Studio 2,3 and it's default gradle version is 3.3.

我不小心将 SDK 构建工具更新到最新的 25.0 .0,在 Android Studio 弹出消息更新和 Gradle 插件版本到 2.3.0 之后 所需的 gradle 版本是 3.3+.

I accidentally updated SDK build tools to latest one 25.0 .0, after Android Studio popped up message to update and Gradle plugin version to 2.3.0 for which required gradle version is 3.3+.

我做了以下更改来解决这个问题:

I did the below changes to fix the issue:

  1. 安装了旧版 SDK 构建工具 19.1.0 以使用旧版 Gradle版本
  2. File> Project Structure > Project > 并将gradle版本改为2.3.0
  3. 将 build.gradle(Project: app_name) > classpath 'com.android.tools.build:gradle:3.3.0' 更改为'com.android.tools.build:gradle:2.1.2'

最后,使缓存无效/重新启动或同步.

Finally, do Invalidate Caches / Restart or Sync.

看来还是不要使用 3.3 比较好.来源 &积分

It seems like it's better not to use 3.3 yet. Source & Credits

这篇关于更新到 Android Studio 2.3 后出现 Gradle 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 12:39