I'm trying to run my Flutter app on my phone, connected via USB, in order to debug.

It stopped working from one day (May 13, if it matters) to the next. Quite frustrating is that I made no changes since it last worked. Since the last time I clicked the Android Studio "play" button on May 13, there were only code changes, which all ran fine via hot reload. Then the next day when pressing the play button, it suddenly complains about JAVA_HOME not being set.

After some troubleshooting, I now get the error message

* What went wrong:
Execution failed for task ':camera:compileDebugJavaWithJavac'.
> java.lang.IllegalAccessError:
class unnamed module @0x3d2880e7)
cannot access class$TypeSymbol (in module jdk.compiler)
because module jdk.compiler does not export
to unnamed module @0x3d2880e7

New lines inserted for readability. Also, the recent code changes do not concern camera usage in any way.
No problems when building for Chrome instead of Android.

Troubleshooting attempts

Android Studio version

With me not having changed any configuration manually, my first suspicion was something must have changed automatically. I have Android Studio installed via the JetBrains toolbox, which is set to automatically update my IDEs when a (stable) update is available. The last update (4.2.1) was indeed released this month, however rolling back to the previous version 4.2.0 did not fix the issue.

Pre-existing Java

Well... JAVA_HOME was set. Noteworthy is that it was set to the Android-Studio-embedded version of an older, non-JetBrains-Toolbox installed Android Studio. Even more noteworthy, it was set to
C:\Program Files\Android\Android Studio\jre, while the actual installation was under
C:\Program Files\Android\android-studio. Lowercase probably does not matter on WIN10, but the hyphen does... this was never supposed to work.

Making a copy of the folder under C:\Program Files\Android\Android Studio did not resolve the issue. Flutter doctor said it can find Java, but can not execute it. The play button in Android Studio produced another error now, but I don't know which anymore and I can't reproduce that anymore since I got rid of those old folders by now. Well, that was a dirty hack anyway.

That running echo %JAVA_HOME% in a windows CMD printed the path, while the terminal in Android Studio just printed %JAVA_HOME% added to all the hilarity. At that point I decided that this is too messed up and I'll just start over from the beginning.

New Java

So I uninstalled Android Studio, removed all Java installations could find, and removed JAVA_HOME from the environment.

  • After a reboot, I downloaded Android Studio again => no luck.
  • In Android Studio, went to File => Project Structure..., which lead to a different screen than where it now always leads me to, where I was able to select the SDK to use, but also edit the list of SDKs to choose from (JDKs and Android SDKs). Selected the "download JDK" option there => no luck
  • In the same screen, added OpenJDK jdk-16.0.1 downloaded manually to C:\tools\ => no luck
  • Adding JAVA_HOME again, set to C:\tools\jdk-16.0.1 => Android Studio terminal now finally prints this for echo %JAVA_HOME%, but building the project still no luck
  • Now currently, File => Project Structure... leads me to a window where I can select, separately, Android SDK location (set to C:\AndroidSDK\Android-sdk), Android NDK (nothing selected) and JDK. For the last option, I tried the embedded JDK as well as JAVA_HOME (still jdk-16.0.1 in C:\tools\) => no luck, both produce the IllegalAccessError I mentioned earlier.

I found some (years-) older posts mentioning that Android Studio doesn't work with newer JDK versions, but I get the same error with the embedded version.


What the heck is going on?
Why does it stop working form one day to the next without changes?
And what does it want form me to start working again?


Update 1

Thank you Milan Chauhan! After removing the folder .idea and android\.gradle, and then doing File -> Invalid cache and restart, building now produces another error:

Execution failed for task ':app:processDebugMainManifest'. 
> Unable to make field private final java.lang.String  
 accessible: module java.base does not "opens" to unnamed module @5689f0e

When I create a completely new flutter project and click the play button, I get the error

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > Could not open proj generic class cache for build file
      > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' 
    Unsupported class file major version 60

Solution 1: Milan Chauhan

  1. Delete .gradle folder and .idea folder from the project root folder

  2. In Android Studio, File -> Invalid cache and restart

Solution 2: Raphael Schmitz

I managed to fix it with these steps:

It seems that something here (Android Studio 4.2.1 / Dart 2.12.3 / Flutter 2.0.6) is indeed not compatible with JDK 16.

I still don't know what exactly happened here. Facts are

  • The Android Studio update came out very recently, and it's the only thing I'm aware of that would change on its own.
  • My own, manually added JAVA_HOME works with JDK 15, but not with JDK 16.
  • Choosing the embedded JDK, I get the same error as with manually added JDK 16.

My best guess based on that is that Android Studio did update automatically and that updated the embedded JDK to version 16.