Android IDEGradle

How To Update Gradle Plugin In Android Studio

This article will explain how to update Gradle plugin to latest version. You can check the latest version through this weblink where Gradle Team announces their latest releases https://gradle.org/releases/

Note: Gradle and Gradle Plugin are different. Android Plugin can run/update independent of Android Studio.

Normally IDE will automatically ask you to update Gradle when you update Android Studio IDE or importing a new project into the IDE.

devdeeds update gradle alert IDE

Note: Gradle version and Gradle Plugin version are dependent

But if you want to do this manually then you can do it in 2 methods i.e, either

  • through Android Studio IDE menu
  • or through Code.

Method 1: Through Android Studio IDE

This is the simplest method. Go to File > Project Structure > Project Tab
Where it will open a window like below,

Gradle Settings In Android Project
Gradle Settings In Android Project (Android Studio 4.0.1)

After entering required version for both Gradle and Plugin press Ok. It will Sync modified gradle files. After that you can start working with new Gradle version.

Method 2: Through Code

  • Update Android Plugin For Gradle
  • Update Gradle

i. Update The Android Plugin For Gradle

Updating the plugin is like changing the dependency classpath mentioned in the project gradle file. For this please open Project level build.gradle file located outside all the modules. This is the Top-level build file where you can add configuration options common to all sub-projects/modules.

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 Gradle plugin 3.0.0 or higher.
        google()
        ...
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
    }
}

ii. Update Gradle

Updating the Gradle actually downloads the corresponding zip file from the online Gradle repository to a directory of Gradle Home (By default under OS User folder). Please follow the below instructions to update Gradle using wrapper.

The Wrapper is a script that invokes a declared version of Gradle, downloading it beforehand if necessary. This is project level script. By default it is selected in Android Studio Gradle Settings.

Please open [PROJECT ROOT DIRECTORY]gradle/wrapper/gradle-wrapper.properties file.

#Tue Aug 04 17:12:42 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

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

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

After making this modification, please 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 6.1.1

SEE OFFICIAL RELEASE CANDIDATES

Running the above command will look for gradle version 6.1.1 in the gradle path [android_studio_installed_location]/gradle if not present it will start downloading from online repository. After this process it will automatically change gradle-wrapper.propertiesfile.

Also make sure you are using Build Tools 26.0.2 or higher.

If any error occurred during Sync saying missing build tools then please install it and Sync again

About author

Geethu is a teacher by profession, but she likes to research new things and is also interested in writing. Devdeeds is her blog, where she writes all the blog posts related to technology, gadgets, mobile apps, games, and related content.

Leave a Reply

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