38

I need help. I can't upgrade gradle version of my react-native project.

I try a lot of things, downloaded last version of Android Studio & SDK Tools etc.

I changed this file \android\gradle\wrapper\gradle-wrapper.properties, I tried to upgrade using npm install -g react-native-git-upgrade but still I can't upgrade it.

When I react-native eject It's exports "distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip"

Waiting for answers.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Siberhecy
  • 561
  • 1
  • 5
  • 16

8 Answers8

55

In android/build.gradle you have to edit this line

classpath 'com.android.tools.build:gradle:x.y.z'

Change x.y.z with the version you want. Edit it with Android Studio then click Sync now

Daniel Gabor
  • 1,405
  • 11
  • 13
10

In {yourProject}\android\gradle\wrapper\gradle-wrapper.properties, update:

distributionUrl=https\://services.gradle.org/distributions/gradle-{your version}.zip

Find your version of gradle with

gradle --version

You may need to install gradle wrapper if you haven't already.

justinhook
  • 111
  • 1
  • 7
  • From where come the {version} used on the distributionUrl parameter (https\://services.gradle.org/distributions/gradle-{version}.zip)? Normaly I create my project and I need update to a newer version changing this parameter manualy. – regisls Apr 19 '21 at 17:01
8

you can go to https://services.gradle.org/distributions/ and check that latest -all.zip version of gradle and update the same in your gradle-wrapper.properties file. When you run your react-native app the next time, your gradle will first get upgraded and then run.

Dinesh Verma
  • 585
  • 5
  • 8
5

There are two things

  1. Android Gradle Plugin

    You can see the version of it in android/build.gradle file and update it using Daniel's answer here

  2. Gradle version

    You can see this in android\gradle\wrapper\gradle-wrapper.properties file and update it using the answer mentioned here

To know the difference between them refer following links:

https://developer.android.com/studio/releases/gradle-plugin

difference between android gradle plugin and gradle

Toshal Agrawal
  • 173
  • 2
  • 7
  • 1
    You can simply edit both it in the menu in Android Studio at `File > Project Structure > Project` – Mika Aug 03 '22 at 11:45
1

From Gradle's site:

https://gradle.org/install/#with-the-gradle-wrapper

Upgrade with the Gradle Wrapper If your existing Gradle-based build uses the Gradle Wrapper, you can easily upgrade by running the wrapper task, specifying the desired Gradle version:

$ ./gradlew wrapper --gradle-version=6.6.1 --distribution-type=bin Note that it is not necessary for Gradle to be installed to use the Gradle wrapper. The next invocation of gradlew or gradlew.bat will download and cache the specified version of Gradle.

$ ./gradlew tasks Downloading https://services.gradle.org/distributions/gradle-6.6.1-bin.zip ...

Run these commands in your project's android folder

1

I had opened my project in Terminal and ran open -a /Applications/Android\ Studio.app to open Android Studio but so that it can access node to download my gradle version which it did automatically.

Learned from this original post: React Native on Android: Cannot run program "node": error=2, No such file or directory

Ian
  • 1,746
  • 1
  • 15
  • 28
1

Open Android Studio and navigate to File → Project Structure

enter image description here

Then click on the Project option.

enter image description here

then choose the latest version of Gradle. After that click on Ok.

Xhirazi
  • 735
  • 4
  • 15
0

For react native Go to File -> Project Structure -> Change gradle version to 6.1.1 plugin version to 4.0.0 Try different combinations Use this link - https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle

Nikhil Jain
  • 244
  • 3
  • 7