React Native Android : FAILURE: Build failed with an exception. MAC OS

trackmystories

TrackMyStories

Posted on April 19, 2021

React Native Android : FAILURE: Build failed with an exception. MAC OS

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.

Firstly: Recreate this error

In order to recreate this Error install a newer version of JAVA Development Kit for example JDK 16, or more than one JDK's on your mac.

https://www.oracle.com/java/technologies/javase-jdk16-downloads.html

If you run npx react-native run-android, You'll get the following build fail:

Alt Text

Your build may be failing because :

• More than one JDK's are installed.

• Incompatible JDK is installed.

• Or no JDK is installed.

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

So to fix this issue follow these steps:

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:

Alt Text

delete them with the following command line :

Alt Text

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

however delete that as-well and reinstall it after you have completed these steps.

After you have done so you can check if the files still exist by typing "ls" if the files are deleted.

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

Alt Text

Step Two:

Once all JDK's have been removed reinstall the correct JDK as mention in the react-native documentations.

Open up a new terminal

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

Alt Text

This may say adoptopenjdk-8.jdk is already installed:

Alt Text

regardless, go ahead and reinstall it with:

Alt Text

Once installation is complete, you should see the following:

Alt Text

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

To Conclude

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.

Alt Text

please refer to the following documentation to get a better understanding on Gradle compilation.

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

💖 💪 🙅 🚩
trackmystories
TrackMyStories

Posted on April 19, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related