How to update gradle in android studio?
Asked Answered
D

18

451

I installed Android Studio 0.1.9. Today I got and update to version 0.2 and of course I updated. After the installation I restarted Android Studio but now I get this message:

Project is using an old version of the Android Gradle plug-in. The minimum supported version is 0.5.0. Please update the version of the dependency 'com.android.tools.build:gradle'

How do I do that? I can't find any update tools for the gradle plugin in android studio.

Deleterious answered 18/7, 2013 at 15:25 Comment(1)
$Sometimes$ Android Studio will prompt to upgrade (with a non-modal popup at bottom-right of screen), if you click the link on that another popup (this time modal) will display in the middle of the screen, you should check what you are upgrading from before accepting but the modal nature means you need to dismiss it...then wait for that $sometime$ situation to happen again (if you want to do it via the popups...). This is a message for Android Studio Tooling team: let us trigger that popup flow.Naylor
O
605

Step 1 (Use default gradle wrapper)

FileSettingsBuild, Execution, DeploymentBuild Tools→GradleUse default Gradle wrapper (recommended)

Android studio settings Gradle Wrapper

Changing to Gradle Wrapper in the new version of Android Studio: Android Studio Setting Gradle Wrapper new version

Step 2 (Select desired gradle version)

FileProject StructureProject

Android Studio project structure

The following table shows compatibility between Android plugin for Gradle and Gradle:

Compatibility table

Latest stable versions you can use with Android Studio 4.1.2 (March 2021):

Android Gradle Plugin version: 4.1.2
Gradle version: 6.5

Official links

Outfight answered 8/2, 2016 at 14:50 Comment(18)
With all these steps: Gradle 'Project' project refrash failed. Error: Cause: ....../gradle-3.0.0-all.zipTape
@Tape It's most likely that you're using an incompatible version. Check the Compatibility table to pick the correct one.Outfight
this is only how to setup your default gradle, but it doesn't update it... If you have it configured to update automaticaly, so explain that, not this. ThanxSkunk
@AriWais What do you mean ? To update Gradle Plugin and Gradle just increase the version as I showed above but remember to use compatible versions.Outfight
for me it didn't... I did what you said and I receive an error "gradle version not installed" so I had to download it manually from gradle.orgSkunk
@AriWais Maybe you're using an old version of Android Studio.Outfight
Updated it in an old project and it worked. After this process I needed to make a couple of instalations android studio told me to do so. It took me around 20 minutes to finsh the process and then I was able to run this old project.Groos
Should I also update the version number in the toplevel build.gradle under buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.13' } ... }?Fish
@Keith No, past self! Don't do that: that's the "plugin version". Set that to 3.1.3Fish
Had to just upgrade Gradle to 4.7 to work with the Spek 2.x framework. Thanks!Volute
Google, what a mess! Here are some suggested points which someone might want to edit into the current answer. As of v3.4.2, AS lets you type any version you want into the Gradle Version textbox, and the drop-down has no suggestions even when using the "default" (internal, recommended) gradle wrapper. So go into the AS/gradle folder and see what version you have. I have 5.1.1, so I typed that in and ended 20 minutes of frustration. (4 years since I last used AS.)Frederick
Gives this error: #53709782Transmittal
In the latest version of AS, the option in step 1 is called "Use Gradle from gradle-wrapper.properties file" rather than "Use default Gradle wrapper"Amie
This answer is no longer valid as of today. When you enter the options in step 1, not all of the options listed there are displayed i.imgur.com/bCnqiFN.pngSkerrick
@Skerrick Thank you. I've added the screenshot for the new version as well.Outfight
This answer is no longer valid, because of the changes in UI in Android studio.Duff
I don't have a Build Tools option.Progenitor
@Progenitor Which Android Studio version are you using?Outfight
D
98

This may not be the exact answer for the OP, but is the answer to the Title of the question: How to Update Gradle in Android Studio (AS):

  • Get latest version supported by AS: http://www.gradle.org/downloads (Currently 1.9, 1.10 is NOT supported by AS yet)
  • Install: Unzip to anywhere like near where AS is installed: C:\Users[username]\gradle-1.9\
  • Open AS: File->Settings->Gradle->Service directory path: (Change to folder you set above) ->Click ok. Status on bottom should indicate it's busy & error should be fixed. Might have to restart AS
Desmoid answered 23/1, 2014 at 0:39 Comment(2)
Here you can find all the versions of Gradle: services.gradle.org/distributionsHeisser
Tried this and Android Studio seems to override from my custom-installed Gradle to the AS-bundled Gradle despite successfully applying the change.Stockmon
Z
60

after release of android studio v 3.0(stable), It will show popup, If gradle update is available

OR

Manually, just change version of gradle in top-level(project-level) build.gradle file to latest,

   buildscript {
      ...
      dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
      }
    }

check below chart

The Android Gradle Plugin and Gradle

 Android Gradle Plugin            Requires Gradle
 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.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.1                    4.10.1+ 
 3.4.0 - 3.4.1                    5.1.1+
 3.5.0                            5.4.1+

check gradle revisions

Zygote answered 17/5, 2016 at 4:33 Comment(3)
Is there a way to trigger this popup manually? I started Android Studio 3.0 while the SDK Update was running in the background (not using AS for SDK management), so I clicked "Ask again tomorrow" just in case this would rely on the new Build Tools which the SDK Update was installing.Palette
ok but you can change it by updating it in application level .gradle file@DanielFZygote
@DanielF close your project, then open the .idea/workspace.xml and remove the line <property name="show.do.not.ask.upgrade.gradle.plugin" value="2.3.3" /> (you might need to search for it). Save the file and open the project again.Pecker
B
48

Open File > Project Structure > Project Tab

Instructions

Android Studio has a built in project structure menu to check and update the gradle and plugin used in the current project.

Barnwell answered 26/11, 2016 at 12:39 Comment(1)
So many different answers on how to resolve this and this was finally the secret handshake I needed to know.Beltz
E
23

You can try "AGP (Android Gradle Plugin) Upgrade Assistant..." from the Tools menu.

AGP Assistant

Endocarditis answered 17/5, 2022 at 8:39 Comment(2)
Nothing happens when I click that.Progenitor
"The APG Upgrade Assistant opens only when you open the Android folder as an Android project" https://mcmap.net/q/44885/-agp-upgrade-assistant-window-not-opening-in-android-studioSamurai
B
16

For those who still have this problem (for example to switch from 2.8.0 to 2.10.0), move to the file gradle-wrapper.properties and set distributionUrl like that.

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

I changed 2.8.0 to 2.10.0 and don't forget to Sync after

Bollen answered 14/7, 2016 at 13:33 Comment(1)
No, if you only change this file, your project will can not be sync settings. You should change through Project Structure.Danged
R
9

On Mac, open terminal and run the following commands as per instructions:

$ curl -s https://get.sdkman.io | bash

then

$ sdk install gradle 3.0

Once the installation is complete, the terminal would ask whether to set it as a default version so type y and make it the default version.

Now open Android Studio -> Terminal and run the following command

Gradle --version
Robertoroberts answered 23/8, 2016 at 8:23 Comment(3)
Worth noting that you will need to restart your shell or (in bash) source ~/.bash_profile to make the sdk executable if it's not already in your pathRolanda
I'd be very wary of curling [internet] | bash, especially when following the instructions posted by a (essentially) anonymous post to a random website.Hydroxylamine
download a file and piping it straight into bash checking the file in an editor to see what it does ?Chinua
P
6

Open your root build.gradle file and change Gradle version like this

Old version:

 dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    } 

New version:

dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }

For Gradle version compatibility see this.

Paquito answered 6/4, 2016 at 11:29 Comment(0)
B
4

I can't comment yet.

Same as Kevin but with different UI step:

This may not be the exact answer for the OP, but is the answer to the Title of the question: How to Update Gradle in Android Studio (AS):

  • Get latest version supported by AS: http://www.gradle.org/downloads (Currently 1.9, 1.10 is NOT supported by AS yet)
  • Install: Unzip to anywhere like near where AS is installed: C:\Users[username]\gradle-1.9\
  • Open AS: File->Settings->Build, Execution, Deployment->Build Tools-> Gradle->Service directory path: (Change to folder you set above) ->Click ok. Status on bottom should indicate it's busy & error should be fixed. Might have to restart AS
Buchenwald answered 10/10, 2015 at 19:0 Comment(0)
L
4

Try this command in the command line:

./gradlew wrapper --gradle-version latest
Lactoflavin answered 14/4, 2023 at 17:35 Comment(0)
U
3

Go to File > Settings > Builds,Execution,Deployment > Build Tools > Gradle >Gradle home path

Now, set Use default gradle wrapper and edit Project\gradle\wrapper\gradle-wrapper.properties files field distributionUrl like this

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

Undershot answered 30/3, 2016 at 6:11 Comment(1)
deprecated no longer in menuProgenitor
S
1

This works if you only need to set Gradle Version anew:

  1. Open Android Project Studio Settings: Go to File -> Settings -> Build, Execution, Deployment -> Android -> Android Project Structure
  2. Select Project
  3. Choose the Gradle Version which is compatible to the Gradle Plugin you're using Navigate to Android Project Structure to set the Gradle Version
Succedaneum answered 2/4, 2023 at 7:21 Comment(0)
A
0

It works for me:

just go to '/home/your-user/.gradle/wrapper/dists/'

delete everything inside of this

It will be replaced by android studio

on terminal run: ionic emulate android

Its all...

Asgard answered 20/2, 2016 at 19:30 Comment(0)
A
0

For me I copied my fonts folder from the assets to the res folder and caused the problem because Android Studio didn't accept capitalized names. I switched to project view mode and deleted it then added it as font resource file by right clicking res folder.

Archival answered 6/9, 2017 at 15:49 Comment(0)
S
0

Most of the time you can have Android Studio automatically update the Gradle plugin.

If your Gradle plugin version is behind, Instant Run will mostly likely not work. Therefore if you go to the Instant Run settings (Preferences > Build, Execution, Deployment > Instant Run), you'll see an Update project button at the top right (image below). Clicking this will update both the Gradle wrapper and build tools. Update Project

Saad answered 28/2, 2018 at 13:35 Comment(4)
Not true in all configurationsUnavailing
Hence the twice mention of 'most of the time'Saad
lol the method may be available or not, it does not affect the status of your code or application. If it option is there use it and i'll upgrade your gradle, if it isn't there you wont be able to use it and you can try another method. Are you literate? If you misunderstand tiny paragraphs most of the time, I am worried for you :)Saad
There is no "Instant Run" section now in preferences (AS 4.1.3). This answer is obsolete.Ditchwater
A
0

Select android\gradle\wrapper and open gradle-wrapper.properties

change: distributionUrl=https://services.gradle.org/distributions/gradle-older-version-to-new-version.zip

eg: distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip and rebuild your project

Argumentation answered 4/1, 2020 at 20:20 Comment(0)
S
0

Other answers mentioned how to update AGP (Android Gradle Plugin).

For updating Gradle itself, if you have set the IDE settings to use Gradle from the wrapper file or the wrapper task (as opposed to using a Gradle installed on your system, if any)...

Setting the Gradle used by the IDE

...you can specify the following code in your top-level build.gradle[.kts] script:

tasks.wrapper {
    gradleVersion = "7.3.3"
    // Downloads the full version of the Gradle (with sources and documentation)
    distributionType = Wrapper.DistributionType.ALL
}

Now, instead of editing gradle-wrapper.properties file, run the wrapper task and Sync the IDE:

OS Command
Linux ./gradlew wrapper
Windows Command Prompt gradlew wrapper
Schaffner answered 23/1, 2022 at 15:21 Comment(0)
L
-12

If your run button is gray. This is how i fixed it.

Go to Run in menu, and then press this:

enter image description here

Then it will run your Emulator, and your run button will become green again and you can use it. That is how i fixed it.

Lan answered 17/8, 2017 at 18:3 Comment(1)
pretty irrelevant to the topic under discussion.Lanate

© 2022 - 2024 — McMap. All rights reserved.