2

Hello I am on mac and I changed the sdk version as many tutorials say. If I run java --version I get this:

openjdk version "11.0.19" 2023-04-18
OpenJDK Runtime Environment Homebrew (build 11.0.19+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.19+0, mixed mode)

The problem is when I run flutter doctor --verbose I get this on android studio:

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

The JDK versions are different. And when I try to run a flutter project I get this error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @52a71430

Additional information:

  • When I open my flutter project by the android folder in android studio I can configure project settings and select the jdk version.

  • This works only if I run the app inside the android folder in android studio. If I run it from the root it throws the same error.

  • The command output of /usr/libexec/java_home -V is this:

Matching Java Virtual Machines (1):
    11.0.19 (arm64) "Homebrew" - "OpenJDK 11.0.19" /opt/homebrew/Cellar/openjdk@11/11.0.19/libexec/openjdk.jdk/Contents/Home
/opt/homebrew/Cellar/openjdk@11/11.0.19/libexec/openjdk.jdk/Contents/Home
  • In my ~/.zshrc I have an export of export JAVA_HOME='/opt/homebrew/Cellar/openjdk@11/11.0.19/libexec/openjdk.jdk/Contents/Home'

Is there a way to solve this?

Joaquín Varela
  • 329
  • 5
  • 18

1 Answers1

0

i was able to change the version that flutter doctor -v shows doing the following, i deleted the android folder from my User location, deleted the android studio i had wich was the flamingo version and installed the Electric eel version from https://developer.android.com/studio/archive then i followed this instructions For the JetBrains Runtime "Android Studio Electric Eel" cd /Applications/Android\ Studio.app/Contents/jbr ln -s ../jbr jdk ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk Then go to the Finder and search for Android Studio:

Right click -> Show Package Contents Open the contents folder, then create new folder called jre Copy the contents of the JetBrainsRuntime folder and paste it into the jre folder from the answer Unable to find bundled Java version on Flutter and finally my flutter doctor -v shows java version 11 that allowed me to compile the flutter project, hope this helps!