Unable to find bundled Java version =>Mac Flutter Android Studio Arctic Fox 2020.3.1

created at 08-04-2021 views: 45

Terminal: flutter doctor -v

“Unable to find bundled Java version”

[!] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio Preview.app/Contents
    • Flutter plugin can be installed from:
        https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
        https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

Processing method:

cd /Applications/Android\ Studio.app/Contents/jre
ln -s ../jre jdk
ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk

Perfect result:

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
        https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
        https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

problem 2

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

Terminal input: flutter doctor --android-licenses, the following error appears

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)

at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)

at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)

at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)

at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)

Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema

at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)

at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)

at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)

... 5 more

Approach

1. Update sdkmanager in the tools/bin directory of the Android SDK

Terminal input: /Users/***/tools/bin/sdkmanager --update

2. Configure JAVA_HOME

The jdk under mac is installed under /Library/Java/JavaVirtualMachines by default. The real path is as follows:

WJdeMacBook-Pro:~ wj$ cd /Library/Java/JavaVirtualMachines
WJdeMacBook-Pro:JavaVirtualMachines wj$ ls -la
total 0
drwxr-xr-x  3 root  wheel   96  3 21 15:25 .
drwxr-xr-x  4 root  wheel  128  1  1  2020 ..
drwxr-xr-x  3 root  wheel   96  4  3  2019 jdk1.8.0_77.jdk

Refer to Apple's documentation and use the -V option after the command /usr/libexec/java_home to list all versions of JAVA_HOME, which is the following result:

WJdeMacBook-Pro:JavaVirtualMachines wj$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    1.8.77.03 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_77 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

Choose the jdk version you need and configure it in .bash_profile

Terminal input:

open .bash_profile

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home

export PATH=$JAVA_HOME/bin:$PATH

Copy and match the above 2 configuration paths in the .bash_profile file

After saving, in order to make the configuration effective immediately, you need to execute: source ~/.bash_profile command

Enter again at the terminal: flutter doctor

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses

Terminal input: flutter doctor --android-liceses

Occurs multiple times: Review licenses that have not been accepted (y/N)?

Always enter: y and then press enter

Perfect result:

WJdeMacBook-Pro:~ wj$ flutter doctor
***
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
***
created at:08-04-2021
edited at: 08-04-2021: