Notes About Flutter and Android Studio Installation on Linux
Some ugly fix for Android SDK comparability issue with Java 11
I’ll be brief about the issue:
- Android SDK depends on an old standard library java.se.ee, but it was deprecated in Java 9 and 10 and was finally removed in Java 11.
- Modern Linux distribution comes with OpenJDK Java 11.
- Your Android / Flutter command tools (e.g. sdkmanager, flutter) would run on the default-installed version of Java, which do not have java.se.ee at all.
As a result, your command tools would sometimes run into error like this:
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
Google is well aware of the problem. So, Android Studio (the latest version now is 4.1.1) tarball is distributed with its own JRE/JDK folder in your <android_studio_path>/jre
folder. Your Android Studio is basically running on its own Java.
To fix your command line tools issue, you can either:
- Set a global JAVA_HOME variable to
<android_studio_path>/jre
, which is an ugly solution; or - Run all your android / flutter related command with the environment variable.
I like the second solution better, so I run sdkmanager or flutter like this:
env JAVA_HOME=<android_studio_path>/jre sdkmanager --licenses
env JAVA_HOME=<android_studio_path>/jre flutter doctor -v
What about things within Android Studio?
Still, some plugins in Android Studio (e.g. gradle) would run on the globally installed java. You need to somehow setup to run the Android Studio with the proper JAVA_HOME everytime.
I’m used to writing my own .desktop file for quick application access. Let’s say my android-studio is installed in /opt/android-studio
, my desktop file would look like this:
$HOME/.local/share/applications/android-studio.desktop
:
[Desktop Entry]
Version=1.0
Type=Application
Name=Android Studio
Exec=env JAVA_HOME=/opt/android-studio/jre bash -i "/opt/android-studio/bin/studio.sh" %f
Icon=/opt/android-studio/bin/studio.png
Categories=Development;IDE;
Terminal=false
StartupNotify=true
StartupWMClass=jetbrains-android-studio
Name[en_GB]=android-studio.desktop
So I can simply add the JAVA_HOME in the Exec command:
[Desktop Entry]
Version=1.0
Type=Application
Name=Android Studio
Exec=env bash -i "/opt/android-studio/bin/studio.sh" %f
Icon=/opt/android-studio/bin/studio.png
Categories=Development;IDE;
Terminal=false
StartupNotify=true
StartupWMClass=jetbrains-android-studio
Name[en_GB]=android-studio.desktop
And things are done :-)