Ivan Sandoval
Ivan Sandoval

Reputation: 121

Could not compile settings gradle React Native

The app worked for me from another machine, now that downloading the files from the repository on another computer gives me this problem

FAILURE: Build failed with an exception.

Upvotes: 12

Views: 62015

Answers (10)

tushar priyadarshi
tushar priyadarshi

Reputation: 11

delete the .gradle file in android folder(u can do it manually,close every terminal and then delete it manually).now go to android folder again(cd android) and type this .\gradlew clean or gradlew.bat clean) if this gradlew.bat clean does not work then--- go to android studio ,copy the sdk path.now go to android folder again make a local.properties file add sdk.dir=your sdk path(that u got from android studio but with double slash ).now open enviornment variable(type env in search ) go to enviornment variables ,under system variables add variable name:ANDROID_HOME ,value:paste your sdk path(u can get it from android studio) and restart your terminal. now open your terminal, go to project directory->android and try again with this command .\gradlew bat clean. now go back to ur project directory->cd .. and type this npx react-native run-android. it took me some 15mins to build. now check ur emulator .u will find your projectapp in emulator.u can open it manually .just click once on it.it will show welcome message

Upvotes: 0

Muhammad Areeb
Muhammad Areeb

Reputation: 306

i had the same error, my gradle plugin version (6.1.1) and java version (17) were not compatible. i downgraded to java 11 and it worked for me

Upvotes: 0

Nirnay Jain
Nirnay Jain

Reputation: 61

This is due to the JDK version installed on your system.

If you're using the latest version of Java Development Kit, you'll need to change the Gradle version of your project so it can recognize the JDK. You can do that by going to {project root folder}\android\gradle\wrapper\gradle-wrapper.properties and changing the distributionUrl value to upgrade the Gradle version.
You can check out latest releases of gradle and note the latest version of Gradle and edit in gradle-wrapper.properties and change the distributionUrl

Upvotes: 6

Batsa Isaac
Batsa Isaac

Reputation: 1

distributionUrl=https://services.gradle.org/distributions/gradle-7.4.1-bin.zip i changed the gradle vertion from 7.4.2 to 7.4.1 and it works

Upvotes: 0

Kegamo Akiri
Kegamo Akiri

Reputation: 11

Solved it by downgrading Java and upgrading Gradle version.

Upvotes: 1

Nightwolf1013
Nightwolf1013

Reputation: 1

I had the same problem, I came here looking for a solution. I selected JDK 11 instead of 16, but it didn't work, I remembered that I didn't point the way for the new JDK version in ~/.bashrc, now it finally worked.

Upvotes: 0

Ali Shirazee
Ali Shirazee

Reputation: 1118

This is an issue with how Gradle is automating the build and the current version of the JDK installed on your machine, follow these steps to fix it, the react native documentation states you need adoptopenjdk8, however you may have other conflicting JDK versions in the same directory.

Blog post: https://ashirazee.medium.com/react-native-android-failure-build-failed-with-an-exception-908934c3a32b

Step one:

open up your terminal and navigate to /Library/Java/JavaVirtualMachines by typing the following command:

cd /Library/Java/JavaVirtualMachines

after you have done that type ls to see what files are included and take note of the versions.

incase you have one or multiple JDK files present like such:

adoptopenjdk-8.jdk jdk-16.jdk  jdk-8.jdk

then go head and delete them with the following command line :

sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-16.jdk 
 
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-8.jdk

the only dependency you need is adoptopenjdk-8.jdk as mentioned in the react native docs

however delete that aswell and reinstall it after you have completed these steps:

sudo rm -rf /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk

after you have done so you can check if the files still exist by typing ls

if the files are deleted.

Step 2:

then run the following commands to insure all other links, plugins and files are deleted as-well from your Library:

run the following :

sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf ~/Library/Application\ Support/Oracle/Java

Step 3:

once you have done the following, reinstall the correct jdk as mentioned in the react native docs like so:

brew install --cask adoptopenjdk/openjdk/adoptopenjdk8

https://reactnative.dev/docs/_getting-started-macos-android

this may say adoptopenjdk-8.jdk is already installed, but go ahead and reinstall install it with:

brew reinstall adoptopenjdk8

enter image description here

At this point the error should be resolved and your build should work.

enter image description here

It is important to note that this is a build error, since react native uses Gradle to build automations, the conflicting of multiple jdk versions can cause your build to fail.

please refer to the following documentation:

https://docs.gradle.org/current/userguide/userguide.html

Upvotes: 12

Homen
Homen

Reputation: 1212

Open the android folder using Android Studio. Then all dependencies will start downloading(as shown in the picture). Let them complete. After completely downloaded and loaded you can run the project.

enter image description here

Upvotes: 2

user12371692
user12371692

Reputation: 41

I have solved issue by just opening project in Android studio react native version 0.60.5

Upvotes: 4

SHASHI SHEKHAR Barnwal
SHASHI SHEKHAR Barnwal

Reputation: 344

this issue seems to be with the java version, pls check for correct version. also even if two or more jdk are installed we can specify during runtime which jdk has to be used by specifying this gradlew.bat build -Dorg.gradle.java.home=---path-to-jdk---

Upvotes: 1

Related Questions