How can I upgrade react-native gradle version
Asked Answered
L

10

43

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.

Lamanna answered 23/7, 2018 at 13:13 Comment(0)
B
60

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

Bastardy answered 23/7, 2018 at 15:0 Comment(7)
Thank you so much! Worked! react-native-google-mapsLamanna
How to understand which gradle version I need to update to?Funerary
@Vadim I have found this link helpful to understand which gradle version you need to update developer.android.com/studio/releases/…Theca
But that's the Gradle Tools version for Android, not Gradle itself.Kersten
Everytime I do this, it corrupts my entire project. Gradle is the worst, I mean the worst. days, weeks wasted on their horrible compatibility.Capsize
@Capsize I completely agree. :(Sacristy
i use to npx react-native@latest init a_new_project just to check which react-native version they are using with which gradle versionAphaeresis
I
13

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.

Identic answered 7/5, 2020 at 20:52 Comment(1)
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.Wallywalnut
B
10

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.

Berkeley answered 28/11, 2020 at 8:10 Comment(0)
T
6

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

Tutt answered 13/9, 2021 at 14:42 Comment(1)
You can simply edit both it in the menu in Android Studio at File > Project Structure > ProjectEucharis
C
4

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.

Contagion answered 25/11, 2022 at 15:3 Comment(0)
P
3

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

Poach answered 6/10, 2020 at 11:6 Comment(0)
H
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

Heaton answered 28/1, 2022 at 5:29 Comment(0)
C
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

Cambrai answered 6/7, 2021 at 3:38 Comment(0)
G
0

you can directly update gradle version which you want,

for example

  1. update gradle version to 8.0.2
  2. sync project

I hope it's work for you guys

Godbeare answered 11/3 at 11:33 Comment(0)
H
0

Check Gradle Releases: Visit the Gradle releases page (https://services.gradle.org/distributions/) to find a compatible version. Ideally, choose a stable release and avoid RC (release candidate) versions. Opt for versions ending in -all.zip.

Update gradle-wrapper.properties: Open the gradle-wrapper.properties file and edit the distributionUrl property. Replace the existing URL with the one you obtained from the Gradle releases page for your desired version (e.g., distributionUrl=https://services.gradle.org/distributions/gradle-7.5.1-bin/gradle-7.5.1-all.zip).

Update Gradle: Run the following command in your project's root directory (replace 7.5.1 with the actual version you chose):

 ./gradlew wrapper --gradle-version=7.5.1
Hilel answered 27/3 at 0:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.