31

I just downloaded Flutter and tried to learn the emulator with the first default code which Google offered. But it does not run at all!

I have the dart and flutter plugins installed. I also changed the order of jcenter() and google() too

like this:

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        jcenter()
        google()
    }

   
dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        jcenter()
        google()

    }
}

And the error is:

Launching lib/main.dart on Android SDK built for x86 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/[myname]/.gradle/caches/5.6.2/scripts-remapped/settings_7iv4l88jiyzeatj2wku74hwcv/7yvt6la2007dno98lt3rzbguf/settings8410a2d21ed2f87c8a0398566330ee52).
> Could not open settings generic class cache for settings file '/Users/[myname]/AndroidStudioProjects/test_app/android/settings.gradle' (/Users/[myname]/.gradle/caches/5.6.2/scripts/7yvt6la2007dno98lt3rzbguf/settings/settings8410a2d21ed2f87c8a0398566330ee52).
   > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 57

* 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 568ms
Finished with error: Gradle task assembleDebug failed with exit code 1

16 Answers 16

16

You need to update version of Gradle:

  1. go to https://gradle.org/install/ and get info about last version (for now it is 7.1.1)
  2. open gradle/wrapper/gradle-wrapper.properties and change version to last

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

Sign up to request clarification or add additional context in comments.

Comments

12

If you are in Windows 10, set the JAVA_HOME environment variable to the JRE for Android Studio. For example:

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

Comments

8

I got it! My current java version was 12 and I downgraded it to Java 8. Then everything works fine.

I'll leave it, hoping it can help somebody struggling in the future will

2 Comments

If you don't want to use Java 8 for everything else on your system you can set the JDK to be used by gradle in gradle.properties. See stackoverflow.com/a/21212790/2382389
It worked perfectly once I uninstalled the higher version of Java.
7

I had the same issue with a slightly different error message:

... Could not open settings remapped class cache for 3n8ygcxrc7nelqcw5tzib8bo6....


I was able to resolve this issue by opening the android folder in my project with Android Studio and syncing Gradle. Here's how:

Let's say that my current Flutter project is in the directory C:\Users\Mendel\Documents\Flutter Projects\test. In this directory, there's an android folder, open this android folder in Android Studio instead of your current Flutter project, (goto File -> Open) and let Gradle Sync run (it will run automatically, the process will take some time). Once done, re-open your Flutter project.

Comments

4

I don't know reason for this error. But I was updated gradle version to the latest in gradle-wrapper.properties file. Then sync. It worked for me.

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

Comments

4

In other, for me to solve this issue,

  1. I had to open my project in finder and then
  2. Dragged the android folder onto Android Studio. It will start from afresh to resync my project with all neccessary conflicting gradle versions and jdk's .

Note while the syncing was going on, I made sure to accept every upgrade recommendation brought up on the dialog until the process was completed.

When this was done, I went back to my project, ran it again and it worked smoothly.

Open project in finder

Drag android folder into android studio to begin resync

1 Comment

How to do this on Visual Studio Code?
3

Working solution 2023

I faced the exact same issue.... Spent couple of hours figuring it out! Here are things I did to get the thing working

  1. Delete .gradle folder. In my case, I'm on MacOs... So I executed sudo rm -r ~./gradle
  2. Upgrade your Java version
  3. Execute ./gradlew clean in the android directory of your project
  4. Run pub flutter clean then flutter pub get
  5. Launch the build, and it should be fine ✨

Comments

2

Delete the .gradle file and then run ./gradlew clean

Comments

1

I had the same issue: For fixing install openJdk8 version https://adoptopenjdk.net/upstream.html?variant=openjdk11&jvmVariant=openjdk8 Also, change the path to OpenJDK place

Comments

1

Please update gradle version

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip

in gradle-wrapper.properties

Comments

1

For my case , I'm using M1 chipped Mac OS. First upgrade your gradle distribution -

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip

in gradle-wrapper.properties.

Then you might face an issue like that -

accessible: module java.base does not "opens java.io" to unnamed module @42760a00

if you face this please add a like in gradle.property.

org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED

enter image description here

Ref 1 and Ref 2

Comments

0

Try to uninstall java, restart android studio and run the application again. Grandle handled everything by itself.

Comments

0

Since Android Studio comes bundled with JDK, it may be a solution to downgrade (or upgrade?) your Android Studio version.

For example, if you are still using Flutter 1.x, I recommend using Android Studio up to 4.2.x. This requires no additional installations or configuration changes, whereas later versions cause all sorts of weird issues.

Comments

0

i have the same issue i have java 17 installed in my system

after searching this on internet i found that if you downgrade your java from whatever to java 8 or java 11 then it's going to work.

i downgrade to java 11 and its works

Comments

0

Separately, I opened android module in Android Studio, then gradle started to build, then I opened the Flutter project again. it is ok

Comments

0

I've just built in newly installed VS code and everything worked, did not ask anything, there were no errors. magic!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.