How to use the latest gradle version in Android Studio

半腔热情 提交于 2019-11-28 20:18:41

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 Aug2020

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               5.4.1+

For AS 2

The latest plugin is:

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

For AS 3

You should update the repositories to include google(), you also need gradle > 4.1 for that and the latest is then here:

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

At time of writing that was:

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'
    }
}

What worked for me in addition to the above (changing the distibutionURL) was to keep my classpath as 2.0.0 in build.gradle (Modile:app):

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

In File > Project Structure > Project: change 'Gradle version' to 2.12

In File > Settings > Build, Execution, Deployment > Build Tools > Gradle : Under 'Project-level settings' section, there are 2 options:

  1. Use default gradle wrapper (recommended)

  2. Download gradle-2.12-all.zip from http://gradle.org/post-download-gradle/ then select 'Use local gradle distibution' and map 'Gradle home:" i.e. C:/Gradle/gradle-2.12

Note that option 2 will require you to download each gradle version update.

Try this: - change this url according to latest version in gradle-wrapper.properties and then change gradle.

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

Hope it helps Thanks

You can't use the default gradle wrapper if you want to use the latest, you have to go it the settings, check "Use customizable gradle wrapper", then change in

Project/gradle/wrapper/gradle-wrapper.properties

the distributionUrl value

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!