40

I've just noticed Gradle has released version 2.12 and according to the release notes the scripts should compile up to 20% faster. I'd like to upgrade to that version in Android Studio.

I'm using v1.5.1 and in the settings I've selected the "Use default gradle wrapper" option, which means that instead of using a local gradle install for every project, a specific gradle version will be used for each project. The version used is the one defined in the build.gradle file. Example:

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

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

Now if I change that to this:

classpath 'com.android.tools.build:gradle:2.12'

then Android Studio can't find that version and throws an error. Apparently AS tries to find the binaries in a local cache first (Android Studio/gradle/m2repository) and then it tries to download it from bintray:

https://jcenter.bintray.com/com/android/tools/build/gradle/2.12/gradle-2.12.jar

Browsing the published builds it looks like the last version available here is v2.1.0-alpha1.

  • Why is v2.12 not in bintray yet? Is it not compatible with Android Studio?
  • If it were compatible, is there a way to download it and use a local install in a per-project basis? (I don't want to break older projects already in version control)
4

5 回答 5

45

com.android.tools.build:gradle是android的gradle插件。它与 gradle 分布不同。有关 gradle android 插件的发布/版本信息,请参见此处:https ://maven.google.com/web/index.html?q=gradle#com.android.tools.build:gradle

要更改插件使用的 gradle 版本,请编辑文件:

<Project>/gradle/wrapper/gradle-wrapper.properties

并将这一行更改为您想要的 gradle 版本:

distributionUrl=http\://services.gradle.org/distributions/gradle-2.12-all.zip

然后重建你的项目。

请记住,您使用的 android 插件版本可能尚未使用这个全新的 gradle 版本进行测试,并且可能会导致意外问题。


android gradle 插件到 2020 年 2 月的 Gradle 版本兼容性

Plugin version      Required Gradle version
--                  --
1.0.0 - 1.1.3       2.2.1 - 2.3
1.2.0 - 1.3.1       2.2.1 - 2.9
1.5.0               2.2.1 - 2.13
2.0.0 - 2.1.2       2.10 - 2.13
2.1.3 - 2.2.3       2.14.1+
2.3.0+              3.3+
3.0.0+              4.1+
3.1.0+              4.4+
3.2.0 - 3.2.1       4.6+
3.3.0 - 3.3.2       4.10.1+
3.4.0 - 3.4.1       5.1.1+
3.5.0 - 3.5.3       6.0.1+
3.6.0+              6.0.1+
于 2016-03-16T15:31:15.233 回答
34

对于 AS 2

最新的插件是:

下载

classpath 'com.android.tools.build:gradle:[INSERT LATEST HERE]'

对于 AS 3

您应该更新存储库以包含google(),您还需要 gradle > 4.1 并且最新版本在这里:

https://developer.android.com/studio/releases/gradle-plugin.html

在撰写本文时是:

buildscript {
    repositories {
        // Gradle 4.1 and higher include support for Google's Maven repo using
        // the google() method. And you need to include this repo to download
        // Android plugin 3.0.0 or higher.
        google()
        ...
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
    }
}
于 2016-10-27T14:06:16.377 回答
3

除了上述内容(更改 distibitionURL)之外,对我有用的是在 build.gradle (Modile:app)中将我的类路径保持为 2.0.0:

classpath 'com.android.tools.build:gradle:2.0.0'

在文件 > 项目结构 > 项目中:将“Gradle 版本”更改为 2.12

在 File > Settings > Build, Execution, Deployment > Build Tools > Gradle 中:在“Project-level settings”部分下,有 2 个选项:

  1. 使用默认的 gradle 包装器(推荐)

  2. 从http://gradle.org/post-download-gradle/下载 gradle-2.12-all.zip 然后选择“使用本地 gradle 分发”并映射“Gradle home:”即 C:/Gradle/gradle-2.12

请注意,选项 2 将要求您下载每个 gradle 版本更新。

于 2016-04-08T17:23:53.650 回答
2

如果你想使用最新的,你不能使用默认的 gradle 包装器,你必须去设置,检查“使用可自定义的 gradle 包装器”,然后更改

Project/gradle/wrapper/gradle-wrapper.properties

distributionUrl价值_

distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip

摇篮设置

于 2016-03-16T15:27:44.737 回答
2

试试这个: - 根据 gradle-wrapper.properties 中的最新版本更改此 url,然后更改 gradle。

   distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip

希望有帮助 谢谢

于 2016-03-16T15:25:32.197 回答