0

I am trying to launch my Flutter app on an Android device, I was able just until yesterday, but suddenly today I am getting this error when launching it:

Launching lib/main.dart on Moto G 5S in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Could not open settings remapped class cache for 7yvt6la2007dno98lt3rzbguf (/Users/modestovascofornas/.gradle/caches/6.3/scripts-remapped/settings_bwqg3axqhj874bje5e9od2vqv/7yvt6la2007dno98lt3rzbguf/settingsdeec0faa97453e2ce860d75e6bf1604b).
> Could not open settings generic class cache for settings file '/Users/modestovascofornas/desarrollo/DESARROLLO 2022 SSD-2/2022-G2-CAPENERGY-FLUTTER-PROFESIONAL/FLUTTER/flutter_capenergy/android/settings.gradle' (/Users/modestovascofornas/.gradle/caches/6.3/scripts/7yvt6la2007dno98lt3rzbguf/settings/settingsdeec0faa97453e2ce860d75e6bf1604b).
   > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61

* 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 24s
Exception: Gradle task assembleDebug failed with exit code 1

I have tried deleting .gradle folder, but not working

EDIT

This is my ~/.zshrc file

export PATH=/Users/modestovascofornas/flutter/bin:$PATH
export PATH=/Users/modestovascofornas/flutter/.pub-cache/bin:$PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
mvasco
  • 4,965
  • 7
  • 59
  • 120

3 Answers3

1

Set the JAVA_HOME environment variable to the JRE for Android Studio. For example:

C:\Program Files\Android\Android Studio\jre

Then invalidate and restart Android Studio before trying again.

Muhammad Hussain
  • 966
  • 4
  • 15
  • I am working on a Mac, and have set JAVA_HOME as usual. I have put my zshrc file in the question – mvasco Feb 07 '22 at 12:58
  • 1
    I think its a Java JDK problem, so I can refer you to this: https://stackoverflow.com/questions/67240279/could-not-open-settings-generic-class-cache-for-settings-file – Muhammad Hussain Feb 07 '22 at 13:01
1

You could try this:

Open the terminal in your IDE and issue the command:

flutter clean

Try to launch the app again.

Roslan Amir
  • 1,141
  • 8
  • 16
1

have you tried ./gradlew clean after you deleted .gradle ?

In Android Studio i've found it is always best to configure variables through the project structure dialog. Make sure you configured gradle, JDK & SDK for the project correctly there because the last error indicates a conflict with java/gradle version.

Try upgrading gradle via gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip

and be sure that you are running java version 11 or lower - whatever version is Android Studio default.

edit: After seeing your edit, i would almost guarantee that the issue is with jdk-17.0.2.jdk be sure to use the bundled JDK and configure the path through the project structure dialog.

nadam
  • 63
  • 5
  • You say I have to change the jdk to a 11 version? – mvasco Feb 07 '22 at 13:20
  • The app was running yesterday with the same jdk, the issue has been created today, after changing the app package name, but later I have put the older package name, and the issue is there – mvasco Feb 07 '22 at 13:22
  • 1
    sorry for the late reply. Yes, i would suggest changing the JDK to the Android Studio default JDK in the `Project Structure` dialog. [C:\Program Files\Android\Android Studio\jre] For me the bundled JDK is 11.0.11 - I have had this issue many times and was left scratching my head for several days. Are you still having this same issue? A few questions which would be helpful to guide you further. What version of Android Studio are you running? What version gradle are you running? What is the version of your Android Gradle Plugin? – nadam Feb 07 '22 at 22:38