Reputation: 411
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
Upvotes: 30
Views: 66790
Reputation: 621
I've just built in newly installed VS code and everything worked, did not ask anything, there were no errors. magic!
Upvotes: 0
Reputation: 11
Separately, I opened android module in Android Studio, then gradle started to build, then I opened the Flutter project again. it is ok
Upvotes: 0
Reputation: 1736
I faced the exact same issue.... Spent couple of hours figuring it out! Here are things I did to get the thing working
.gradle
folder. In my case, I'm on MacOs... So I executed sudo rm -r ~./gradle
version
./gradlew clean
in the android directory of your projectflutter clean
then flutter pub get
Upvotes: 3
Reputation: 6936
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
Upvotes: 1
Reputation: 31
Please update gradle version
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
in gradle-wrapper.properties
Upvotes: 1
Reputation: 381
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
Upvotes: 0
Reputation: 200
In other, for me to solve this issue,
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.
Upvotes: 4
Reputation: 3571
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.
Upvotes: 0
Reputation: 21
Try to uninstall java, restart android studio and run the application again. Grandle handled everything by itself.
Upvotes: 0
Reputation: 827
You need to update version of Gradle:
distributionUrl=https://services.gradle.org/distributions/gradle-7.1.1-all.zip
Upvotes: 16
Reputation: 630
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
Upvotes: 12
Reputation: 161
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
Upvotes: 1
Reputation: 20048
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.
Upvotes: 7
Reputation: 391
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
Upvotes: 4
Reputation: 411
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
Upvotes: 8