facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.12k stars 24.32k forks source link

[Android] Gradle fails with `> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 62` #34822

Closed ChurikiTenna closed 1 year ago

ChurikiTenna commented 2 years ago

Description

warn Package react-native-navigation contains invalid configuration: "dependency.assets" is not allowed,"dependency.hooks" is not allowed. Please verify it's properly linked using "react-native config" command and contact the package maintainers about this.
info Starting JS server...
info Installing the app...

FAILURE: Build failed with an exception.

* What went wrong:
Could not open settings remapped class cache for 2b2v1krlox0a6mjvnk5eb71wr (/Users/tenna/.gradle/caches/6.3/scripts-remapped/settings_1rtjkco7nerckjkpaki5l1zp5/2b2v1krlox0a6mjvnk5eb71wr/settingsdeec0faa97453e2ce860d75e6bf1604b).
> Could not open settings generic class cache for settings file '/Users/tenna/Desktop/aitem/android/settings.gradle' (/Users/tenna/.gradle/caches/6.3/scripts/2b2v1krlox0a6mjvnk5eb71wr/settings/settingsdeec0faa97453e2ce860d75e6bf1604b).
   > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 62

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 649ms

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Could not open settings remapped class cache for 2b2v1krlox0a6mjvnk5eb71wr (/Users/tenna/.gradle/caches/6.3/scripts-remapped/settings_1rtjkco7nerckjkpaki5l1zp5/2b2v1krlox0a6mjvnk5eb71wr/settingsdeec0faa97453e2ce860d75e6bf1604b).
> Could not open settings generic class cache for settings file '/Users/tenna/Desktop/aitem/android/settings.gradle' (/Users/tenna/.gradle/caches/6.3/scripts/2b2v1krlox0a6mjvnk5eb71wr/settings/settingsdeec0faa97453e2ce860d75e6bf1604b).
   > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 62

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 649ms

    at makeError (/Users/tenna/Desktop/aitem/node_modules/execa/index.js:174:9)
    at /Users/tenna/Desktop/aitem/node_modules/execa/index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (/Users/tenna/Desktop/aitem/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
    at async Command.handleAction (/Users/tenna/Desktop/aitem/node_modules/@react-native-community/cli/build/index.js:142:9)
info Run CLI with --verbose flag for more details.

I have done everything this page said: https://reactnative.dev/docs/environment-setup. M1 Mac

Version

0.7

Output of npx react-native info

warn Package react-native-navigation contains invalid configuration: "dependency.assets" is not allowed,"dependency.hooks" is not allowed. Please verify it's properly linked using "react-native config" command and contact the package maintainers about this. info Fetching system and libraries information... System: OS: macOS 12.5 CPU: (8) arm64 Apple M1 Memory: 114.81 MB / 8.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.11.0 - ~/.nodebrew/current/bin/node Yarn: 3.2.3 - ~/.yarn/bin/yarn npm: 8.0.0 - ~/.nodebrew/current/bin/npm Watchman: 2022.09.26.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0 Android SDK: Not Found IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8609683 Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild Languages: Java: 18.0.2 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: ^18.2.0 => 18.2.0 react-native: ^0.70.1 => 0.70.1 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

I can give an access to the repository if that'll help.

Snack, code example, screenshot, or link to a repository

I can give an access to the repository if that'll help. I am struggling with errors that coming on and on for days... Please help..

cortinico commented 2 years ago

Java: 18.0.2 - /usr/bin/javac

What's your Gradle versions? You can find it inside the android/gradle/gradle-wrapper.properties file.

I believe you're on a old Gradle version which doesn't support Java 18. As an alternative, movign to JDK 11 should solve your issue.

Songlore commented 1 year ago

I'm having the same error: A problem occurred configuring root project 'LittleLemonNewsletterFinal'.

Could not open proj generic class cache for build file 'D:\LittleLemonNewsletterFinal\LittleLemonNewsletterFinal\android\build.gradle' (C:\Users\Owner.gradle\caches\7.5.1\scripts\akkbmo69g46wo5egmq4ch1csu). BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 63

cortinico commented 1 year ago

Closing as @ChurikiTenna is unresponsive. Feel free to re-open if the issue persists

giovannicaprio commented 1 year ago

Same issue here.

Edgar256 commented 1 year ago

same issue here

samtun commented 1 year ago

same issue here

sundarsharma2018 commented 1 year ago

same issue here

DragonStar373 commented 1 year ago

same issue here

abeeku commented 1 year ago

Try this https://stackoverflow.com/questions/74695402/bug-exception-in-phase-semantic-analysis-in-source-unit-buildscript-unsup/74695403

Changing the distribution url in gradle-wrapper.properties to 7.6

Hacimurad commented 1 year ago

i face same error and I solved my problem install idk 11; follow this AndroidStudio->file->ProjectStructure->click Gradle Settings->choose idk 11

https://user-images.githubusercontent.com/12226661/170825694-d28dc202-d23d-4ed4-a2d8-035d84ad7b58.png

superdencho commented 1 year ago

Try this https://stackoverflow.com/questions/74695402/bug-exception-in-phase-semantic-analysis-in-source-unit-buildscript-unsup/74695403

Changing the distribution url in gradle-wrapper.properties to 7.6

That works! Thank you!

moumen-engineer commented 1 year ago

but which distribution of gradle (7.6-all.zip or 7.6-bin.zip . . .

mattiarainieri commented 1 year ago

What about eas build?

ImadBouirmane commented 1 year ago

Try this https://stackoverflow.com/questions/74695402/bug-exception-in-phase-semantic-analysis-in-source-unit-buildscript-unsup/74695403

Changing the distribution url in gradle-wrapper.properties to 7.6

The right solution, thanks men

tanmoy27112000 commented 1 year ago

SOLUTION:

go to android/gradle/wrapper/gradle-wrapper.properties

Find the distributionUrl variable and change the end path to gradle-7.6-all.zip

ujangaripin24 commented 1 year ago

Try this https://stackoverflow.com/questions/74695402/bug-exception-in-phase-semantic-analysis-in-source-unit-buildscript-unsup/74695403

Changing the distribution url in gradle-wrapper.properties to 7.6

thx dude, it's work for linux mint 21.1!!

SushritPasupuleti commented 1 year ago

Try this https://stackoverflow.com/questions/74695402/bug-exception-in-phase-semantic-analysis-in-source-unit-buildscript-unsup/74695403

Changing the distribution url in gradle-wrapper.properties to 7.6

This doesn't seem to work anymore, as EAS just decides to use 7.5.1 no matter how many times gradle-wrapper.properties is changed.

alz86 commented 1 year ago

If someone else is still in problems with this, the solution, in my case was to align my version of Gradle with the Java one. There is a compatibility matrix that explains which version of Gradle works with which version of Java. By aligning them, it worked on my env.

YektaDev commented 1 year ago

Can confirm. I started having this bug every now and then only after I upgraded the JDK version and the solution for me since I'm not planning on downgrading the JDK, was to instead delete the .gradle and build directories when this happens. Though it's strange that the behavior isn't deterministic. My guess is there are multiple versions of JDK being used by IDE/Gradle/etc.

abdul-megadraws commented 10 months ago
Screenshot 2023-12-15 at 12 07 04 PM

Any solution for React Native Expo ? expo run:android

nikitaGrynch commented 10 months ago
Screenshot 2023-12-15 at 12 07 04 PM

Any solution for React Native Expo ? expo run:android

same issue

abdul-megadraws commented 10 months ago
Screenshot 2023-12-15 at 12 07 04 PM

Any solution for React Native Expo ? expo run:android

same issue

Not Yet! Will update here once fix my side.

ArnaudRm commented 9 months ago

For people using Expo trying to build your app locally the "old way" with expo run:android or npx react-native run-android commands :

I came to understand that if you are in a managed Expo app, and you want to build your app locally , expo advises to use the "new way" of building locally with eas build(as documented here) The major issue for me here is that creating the local build this way with eas build will count in your build usage on expo.dev.

Moreover, ios and android folders are generated if you are in a managed workflow , meaning you cannot change the gradle version as advised in this comment for example because this setting will be overriden the next time you perform a build via eas build command

So, here's how I managed to run local builds with expo run:android or react-native run-android

The problem was the gradle version set by Expo was not compatible with the java runtime version installed on my machine

@abdul-megadraws @nikitaGrynch

NaveenG46 commented 8 months ago

BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 65

what should i do ? also having this error too - "Your project's Gradle version is incompatible with the Java version that Flutter is using for Gradle. "

Help me to overcome this ...

Red3nzo commented 6 months ago

@NaveenG46 having same issue as you, funny no one has found a solution

AndreiSager commented 6 months ago

@NaveenG46 @Red3nzo I have the same problem. I am trying to use realm with expo on a bare workflow but none of the solutions I've found have worked.

I used the template given by expo. but I couldn't run it because I couldn't create a build.

> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 66
GStar718 commented 6 months ago

I'm sorry to hear that you're having trouble with using Realm in an Expo bare workflow. Here are some steps you might find helpful:

  1. Initialize the project: You can start a new project with the npx create-expo-app command. If you're using MongoDB Realm, you can use this command: expo init ReplaceWithNameOfYourAPP --template @realm/expo-template-ts.

  2. Rename App.js to App.tsx: If you're using TypeScript, you'll need to rename your App.js file to App.tsx.

  3. Create a tsconfig.json: You'll need a tsconfig.json file in your project root. You can create one with the touch tsconfig.json command.

  4. Run the project: After setting up, you can run your project with yarn start or npm run start.

**Run the expo diagnosticscommand "inside your project" might also help provide further details of your error:

GStar718 commented 6 months ago

i've found this to be useful.

  1. Check the Java version used by Flutter: You can do this by running flutter doctor --verbose.

  2. Update the Gradle version: You need to update the Gradle version specified in your android/gradle/wrapper/gradle-wrapper.properties file to be compatible with the Java version. For Java 17, you should use Gradle 7.3 or newer.

  3. Change the Java version: If updating Gradle doesn't work, you can change the Java version used by your project. You can do this by adding or changing org.gradle.java.home in your gradle.properties file to point to the appropriate Java version.

GStar718 commented 6 months ago

Always good to recheck your basic steps as well.

if your having trouble with using Realm in an Expo bare workflow. Here are some steps you might find helpful:

  1. Initialize the project: You can start a new project with the npx create-expo-app command³. If you're using MongoDB Realm, you can use this command: expo init ReplaceWithNameOfYourAPP --template @realm/expo-template-ts.

  2. Rename App.js to App.tsx: If you're using TypeScript, you'll need to rename your App.js file to App.tsx.

  3. Create a tsconfig.json: You'll need a tsconfig.json file in your project root. You can create one with the touch tsconfig.json command.

  4. Run the project: After setting up, you can run your project with yarn start or npm run start.

Remember, the bare workflow requires a good understanding of native development for both iOS and Android platforms. Developers should be familiar with Objective-C, Swift, Java, and Kotlin, in addition to JavaScript.

GStar718 commented 6 months ago

@NaveenG46 having same issue as you, funny no one has found a solution

scroll up from here

aaadhilll commented 6 months ago

BUG! exception in phase 'semantic analysis' in source unit '/Users/aswin/Desktop/dev/flutter/packages/flutter_tools/gradle/src/main/groovy/app_plugin_loader.groovy' Unsupported class file major version 64

aaadhilll commented 6 months ago

what to do???

AnuDesai-24 commented 6 months ago

BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 63