android

how to update the Android Plugin for Gradle

Here we learn how to update Gradle plugin to the latest version. Normally IDE automatically asks you to update Gradle when you update Android Studio IDE or importing a new project into the IDE.

I. You can specify the Android plugin for Gradle version in either the File > Project Structure > Project menu in Android Studio, or the top-level build.gradle file.

The following example sets the Android plugin for Gradle to version 3.1.0 from the build.gradle file:

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

Note: You should not use dynamic dependencies in version numbers, such as ‘com.android.tools.build:gradle:2.+’. Using this feature can cause unexpected version updates and difficulty resolving version differences.

II. Update Gradle

Updating the Gradle actually downloads the corresponding zip file from the online Gradle repository to a directory under your project root folder. Please follow the below instructions to update Gradle using wrapper.
You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or by editing the Gradle distribution reference in the gradle/wrapper/gradle-wrapper.properties file.
Follow the below instructions to update Gradle using wrapper.

#Sat Aug 13 08:42:56 IST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl = https\://services.gradle.org/distributions/gradle-4.1-all.zip

Change value of distributionUrl, which is the last line, like the following as shown

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

After making this modification,click Tools > Android > Sync Project with Gradle Files from the Android Studio main menu. You are all done!

Another method is to run the wrapper task from the command line:

[PATH OF PROJECT ROOT DIRECTORY]gradle wrapper --Gradle-version 4.1

Leave a Reply

Your email address will not be published. Required fields are marked *