Getting Android sdkmanager to run with Java 11

I am facing a problem while running Android sdkmanager with Java 11 (Not studio, only SDK tools). I don't want to install JDK 8 or something similar. Is there a way to fix this for Android sdkmanager with JDK 11?

I have gone through this answer and it doesn't offer command line fix for java 11. Any other workaround possible?


Solution 1:

UPDATE: as explained in another answer, the sdkmanager from the new command line tool supports JDK 11+. The old sdkmanager has not received updates in years, so this workaround should not be necessary. Check @dmertins answer for links and more details.


If anyone is looking for a Linux fix on Java 11. I built this on top of previous answers

cd Android/tools
mkdir jaxb_lib
wget https://repo1.maven.org/maven2/javax/activation/activation/1.1.1/activation-1.1.1.jar -O jaxb_lib/activation.jar
wget https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-impl/2.3.3/jaxb-impl-2.3.3.jar -O jaxb_lib/jaxb-impl.jar
wget https://repo1.maven.org/maven2/com/sun/istack/istack-commons-runtime/3.0.11/istack-commons-runtime-3.0.11.jar -O jaxb_lib/istack-commons-runtime.jar
wget https://repo1.maven.org/maven2/org/glassfish/jaxb/jaxb-xjc/2.3.3/jaxb-xjc-2.3.3.jar -O jaxb_lib/jaxb-xjc.jar
wget https://repo1.maven.org/maven2/org/glassfish/jaxb/jaxb-core/2.3.0.1/jaxb-core-2.3.0.1.jar -O jaxb_lib/jaxb-core.jar
wget https://repo1.maven.org/maven2/org/glassfish/jaxb/jaxb-jxc/2.3.3/jaxb-jxc-2.3.3.jar -O jaxb_lib/jaxb-jxc.jar
wget https://repo1.maven.org/maven2/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar -O jaxb_lib/jaxb-api.jar

After the download finishes (make sure all files were downloaded OK), you have to edit sdkmanager and avdmanager scripts in the tools/bin directory. You can do this manually or automatically.

From Simon Ruggier answer (doesn't work on mac unless you use gnu-sed):

sed -ie 's%^CLASSPATH=.*%\0:$APP_HOME/jaxb_lib/*%' bin/sdkmanager bin/avdmanager

Or manually, scroll down to the CLASSPATH variable, and add the new jars we just downloaded like this:

CLASSPATH=$APP_HOME/jaxb_lib/activation.jar:$APP_HOME/jaxb_lib/jaxb-impl.jar:$APP_HOME/jaxb_lib/jaxb-xjc.jar:$APP_HOME/jaxb_lib/jaxb-core.jar:$APP_HOME/jaxb_lib/jaxb-jxc.jar:$APP_HOME/jaxb_lib/jaxb-api.jar:<etc etc...DO NOT REMOVE THE OTHER JARS!...>

Solution 2:

The sdkmanager that comes with the deprecated SDK Tools package doesn't support JDK 8 and is no longer receiving updates since september 2017. More information here and here.

The sdkmanager included in the new Command-Line Tools package supports JDK 11 and it can be downloaded from the Android Studio download page, in the Command line tools only section. There's no need to download any other files or to hack with the sdkmanager script, however you will need to update your PATH setting, e.g. on Linux: $ANDROID_HOME/cmdline-tools/latest/bin instead of $ANDROID_HOME/tools/bin

Although deprecated, the old Tools package is still being installed with Android Studio 4.1.1 by default. This post explains why.

Solution 3:

For those of you seeing this issue in Travis CI: I was seeing this error while attempting to accept the license agreement for build tools 30.0.2, targeting Android 30, with Java 11 for a travis CI build. Applying this answer (https://stackoverflow.com/a/65782803/6500352) I ended up with this working yml

os: linux
language: android
jdk: openjdk11

android:
 components:
   - tools
   - platform-tools
   - tools
   - extra-android-m2repository
env:
  global:
    - TARGET_VERSION=30
    - ANDROID_BUILD_TOOLS_VERSION=30.0.2
    - ANDROID_HOME=~/android-sdk

before_install:
  - touch $HOME/.android/repositories.cfg
  - wget "https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip" -O commandlinetools.zip
  - unzip commandlinetools.zip -d $ANDROID_HOME/
  - yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager "platforms;android-${TARGET_VERSION}" --sdk_root=$ANDROID_HOME
  - yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" --sdk_root=$ANDROID_HOME

before_script:
 - chmod +x gradlew
script:
- ./gradlew your_command_here

Solution 4:

Here's a more automated version of Emilio's answer (thanks!):

cd Android/tools
mkdir jaxb_lib
wget https://repo1.maven.org/maven2/javax/activation/activation/1.1.1/activation-1.1.1.jar -O jaxb_lib/activation.jar
wget https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-impl/2.3.3/jaxb-impl-2.3.3.jar -O jaxb_lib/jaxb-impl.jar
wget https://repo1.maven.org/maven2/com/sun/istack/istack-commons-runtime/3.0.11/istack-commons-runtime-3.0.11.jar -O jaxb_lib/istack-commons-runtime.jar
wget https://repo1.maven.org/maven2/org/glassfish/jaxb/jaxb-xjc/2.3.3/jaxb-xjc-2.3.3.jar -O jaxb_lib/jaxb-xjc.jar
wget https://repo1.maven.org/maven2/org/glassfish/jaxb/jaxb-core/2.3.0.1/jaxb-core-2.3.0.1.jar -O jaxb_lib/jaxb-core.jar
wget https://repo1.maven.org/maven2/org/glassfish/jaxb/jaxb-jxc/2.3.3/jaxb-jxc-2.3.3.jar -O jaxb_lib/jaxb-jxc.jar
wget https://repo1.maven.org/maven2/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar -O jaxb_lib/jaxb-api.jar
# Append jaxb_lib to the CLASSPATH in sdkmanager and avdmanager
sed -ie 's%^CLASSPATH=.*%\0:$APP_HOME/jaxb_lib/*%' bin/sdkmanager bin/avdmanager

The jar directory also doesn't belong under bin, so these instructions place it one level higher.

Solution 5:

Download jxab and jaf, put them all into classpath.

e.g.

sdkmanager.bat

...
set CLASSPATH=%CLASSPATH%;mylib\jaxb-ri\lib\jaxb-api.jar
set CLASSPATH=%CLASSPATH%;mylib\jaxb-ri\lib\jaxb-core.jar
set CLASSPATH=%CLASSPATH%;mylib\jaxb-ri\lib\jaxb-impl.jar
set CLASSPATH=%CLASSPATH%;mylib\jaxb-ri\lib\jaxb-jxc.jar
set CLASSPATH=%CLASSPATH%;mylib\jaxb-ri\lib\jaxb-xjc.jar
set CLASSPATH=%CLASSPATH%;mylib\jaf-1.1.1\activation.jar

@rem Execute sdkmanager
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %SDKMANAGER_OPTS%  -classpath "%CLASSPATH%" com.android.sdklib.tool.sdkmanager.SdkManagerCli %CMD_LINE_ARGS%
...