How to use the latest gradle version in Android Studio

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


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://maven.google.com/web/index.html?q=gradle#com.android.tools.build:gradle

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+

For AS 2

The latest plugin is:

Download

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.