Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

How to use the latest gradle version in Android Studio

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)
question from:https://stackoverflow.com/questions/36039815/how-to-use-the-latest-gradle-version-in-android-studio

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

com.android.tools.build:gradle is android's plugin for gradle. It is not the same as gradle distribution. See here for release/version information of gradle android plugin: https://bintray.com/android/android-tools/com.android.tools.build.gradle/view

To change the gradle version that the plugin uses, edit the file:

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

and change this line to the gradle verison you want:

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

Then rebuild your project.

Do keep in mind that the android plugin version you're using may not have been tested with this brand new gradle version and could potential cause unexpected issues.


android gradle plugin to Gradle version compatibility as of Feb2020

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+

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...