Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with Java on Flutter for Mac

Error Message:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x71871a5e) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x71871a5e

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

I just installed the JDK, and this is what happens when I try to run on the Android side.

Can someone explain to me what this is and how to fix it?

Everything is the latest versions.

like image 376
NikkoNikkoNii Avatar asked Mar 31 '21 10:03

NikkoNikkoNii


People also ask

Which version of Java is compatible with flutter?

Requirements to create Flutter projectJava 11 JDK installed and set in system environment variables. Flutter and Dart extension installed. Connected Device with laptop for run and test flutter applications.

Does flutter work with Java 11?

flutter - Android Gradle plugin requires Java 11 to run.

How do I update Java in flutter?

Go to File > Project Structure. Select the SDK Location section in the list of the left. Deselect the Use embedded JDK (recommended) option. Enter the absolute path of your installed JDK in the text box.

How to build and run Flutter apps on Mac?

macOS supports developing Flutter apps in iOS, Android, and the web. Complete at least one of the platform setup steps now, to be able to build and run your first Flutter app. To develop Flutter apps for iOS, you need a Mac with Xcode installed. Install the latest stable version of Xcode (using web download or the Mac App Store ).

How do I use Android Studio with flutter?

Start Android Studio, and go through the ‘Android Studio Setup Wizard’. This installs the latest Android SDK, Android SDK Command-line Tools, and Android SDK Build-Tools, which are required by Flutter when developing for Android. Run flutter doctor to confirm that Flutter has located your installation of Android Studio.

Why is the JDK for flutter so annoying?

It's more than annoying because it diverts attention from flutter doctor output, where the real solution lies. And the link to get the JDK is not only the wrong link (to the Apple Safari home page!), it leads users to think that they need to do yet another standalone install.

How do I run flutter on Xcode without Sudo?

If you are using a Ruby Version manager, you may need to run without sudo. Open the default Xcode workspace in your project by running open ios/Runner.xcworkspace in a terminal window from your Flutter project directory. Select the device you intend to deploy to in the device drop-down menu next to the run button.


2 Answers

This is because your $JAVA_HOME is not set

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home" in .bash_profile

like image 175
Usama Altaf Avatar answered Oct 17 '22 13:10

Usama Altaf


For me, it turned out to be a java version compatibility issue with Gradle. I down graded from Java SE 16 to Java SE 11 and that fixed the issue.

like image 33
Mark Parris Avatar answered Oct 17 '22 15:10

Mark Parris