10

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.

  • Where: Settings file 'C:\Users\samue\Desktop\MCGPS\TeachAll\android\settings.gradle'

  • What went wrong: Could not compile settings file 'C:\Users\samue\Desktop\MCGPS\TeachAll\android\settings.gradle'.

    startup failed: General error during semantic analysis: Unsupported class file major version 57

Ivan Sandoval
  • 101
  • 1
  • 1
  • 3

8 Answers8

11

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

Ali Shirazee
  • 1,008
  • 10
  • 11
6

This is due to the jdk version intalled 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

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Nirnay Jain
  • 61
  • 2
  • 1
4

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

2

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

Homen
  • 1,222
  • 1
  • 12
  • 16
1

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---

1

Solved it by downgrading Java and upgrading Gradle version.

Rizwan
  • 103
  • 4
  • 24
0

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.

0

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

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34240892) – rhavelka Apr 21 '23 at 18:12
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 23 '23 at 05:32