44

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)
RaGe
  • 22,696
  • 11
  • 72
  • 104
Mister Smith
  • 27,417
  • 21
  • 110
  • 193

5 Answers5

49

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+
RaGe
  • 22,696
  • 11
  • 72
  • 104
  • 2
    Is there a way to know which gradle versions are compatible with the plugin? I see nothing in the page you linked. – Mister Smith Mar 16 '16 at 15:40
  • 2
    Well, they do tell you what is the minimum gradle version to use, in the plugin release notes. For 1.5.0, the minimum gradle version is apparently is 2.2.1 They don't quite say how high you can go before things break. See here: http://developer.android.com/tools/revisions/gradle-plugin.html See also "Gradle Requirements" section here: http://tools.android.com/tech-docs/new-build-system/gradle-experimental – RaGe Mar 16 '16 at 15:47
  • 1
    Bintray is no more. – IgorGanapolsky May 12 '21 at 17:33
34

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'
    }
}
Nadeem Iqbal
  • 2,357
  • 1
  • 28
  • 43
weston
  • 54,145
  • 21
  • 145
  • 203
  • 8
    Nice one! Much better than 12 year old posts – behelit Apr 12 '17 at 05:41
  • Are you sure? That image currently shows '2.3.3', whereas https://developer.android.com/studio/releases/gradle-plugin.html contains the text `classpath 'com.android.tools.build:gradle:3.0.1'` – Don Hatch Nov 25 '17 at 05:03
  • 1
    They've started using their own maven repo... I'll see what I can do. – weston Nov 25 '17 at 12:31
  • @weston Do you have any idea if a newer Gradle version could be used with Android Studio than the version that it ships with? For example I tried Gradle 5.0 with AS 3.2 but it sync fails with unclear errors/exceptions. Or is Android Studio supposed to work with older versions only? I can't find any docs confirming the one or the other. – Zingam Nov 27 '18 at 12:11
  • @Zingam I would see if it worked on command line first. e.g. ’./gradlew assembleDebug’ I would expect that you will see the very same errors. – weston Nov 27 '18 at 12:16
3

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.

Mach1
  • 31
  • 3
2

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

Jagjit Singh
  • 1,909
  • 1
  • 14
  • 19
2

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

Gradle Settings

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245