35

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?

Manish
  • 1,735
  • 2
  • 17
  • 30
  • are you facing a similar issue as the linked question OR what is it that you're facing an issue with? Have you tried running with Java11 to start off with? – Naman Oct 31 '18 at 05:42
  • It may help if you would exactly name the problem and not say "a problem". Edit your question and add the error message and/or the stack trace. – Robert Oct 31 '18 at 19:17
  • 1
    I've got the same issue. The exception that is thrown is: Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema – irundaia Nov 03 '18 at 08:31

10 Answers10

58

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!...>
Emilio
  • 2,526
  • 22
  • 26
  • tried it on my friend mac it also works after installing wget – asem bused Jun 16 '19 at 04:10
  • MacOS user here -- this is the best answer I've found on the Internet as of 12 Sep 2019. – Jeremy White Sep 12 '19 at 19:40
  • macOS 10.14.6, Java: 13.0.1 2019-10-15,still error here ```./sdkmanager --version WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1 (file:/Users/limao/Library/Android/sdk/tools/bin/jaxb_lib/jaxb-impl.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) ...```, – crifan Nov 27 '19 at 06:33
  • 1
    I added a more convenient version of this answer as a separate answer. I'm not out for Internet points, so I was initially going to comment here as a suggestion, but there's a maximum comment length, and no support for code blocks in comments, so I had to put it in a separate answer for it to be useful. If this answer gets updated to incorporate the improvement, let me know and I'll delete mine. – Simon Ruggier Aug 15 '20 at 13:27
  • Thanks Simon. I added your suggestions. It´s a nice shortcut. – Emilio Aug 25 '20 at 09:54
  • On macOS Big Sur, `sed` messed up the classpath declaration. I had to use GNU sed with `brew install gnu-sed`. – hacker1024 Sep 22 '20 at 06:40
  • 1
    This should not be necessary if using the new "command line tools" package, which is JDK11+ compatible. See fresher answer below – Mike Hardy Mar 19 '21 at 19:26
  • Thanks Mike, I updated the answer to point to @dmertins's answer, which is way more updated than this old workaround. I also transformed it into a community wiki, so others can update it. – Emilio Mar 20 '21 at 22:03
43

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.

TnxSO
  • 13
  • 3
dmertins
  • 568
  • 5
  • 11
  • 4
    This is the correct answer in March 2021. Typically it's a PATH issue now, new command line tools (`$ANDROID_HOME/cmdline-tools/latest/bin`) are not in the PATH before the old tools (`$ANDROID_HOME/tools/bin`) but either referencing them directly or reorganize your paths, and you've got modern JDK11-compatible sdkmanager. – Mike Hardy Mar 19 '21 at 19:24
  • 3
    This advice seems to be out of date as of November 2021. There is no `latest` folder in the offical download for the Android SDK command line tools, only the Java-11-incompatible `sdkmanager`. – Benjamin Bray Nov 22 '21 at 08:19
7

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
Brad Moeller
  • 116
  • 1
  • 4
  • 2
    tools and platform-tools are not needed under android components since you're manually fetching them. build-tools is also downloaded on demand by Android Gradle plugin so platforms:android-30 is the only component you need. – hidro Aug 02 '21 at 08:38
  • This works for Travis CI and Java 11. Yes tools, platform-tools, and build-tools can be removed without causing problems. – Ryan W Nov 17 '21 at 03:51
4

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%
...
Wang Qian
  • 51
  • 4
  • 1
    where can i get jaxb, and jaf respectively ? from blind web search it shows up java ee, and some search result shows that jaf is somewhat bundled or something. – asem bused Mar 19 '19 at 03:07
  • 1
    search https://mvnrepository.com http://central.maven.org/maven2/javax/activation/activation/1.1.1/activation-1.1.1.jar http://central.maven.org/maven2/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar http://repository.ops4j.org/maven2/javax/xml/bind/jaxb-impl/2.0.2/jaxb-impl-2.0.2.jar http://repository.ops4j.org/maven2/javax/xml/bind/jaxb-xjc/2.0.2/jaxb-xjc-2.0.2.jar http://central.maven.org/maven2/org/glassfish/jaxb/jaxb-core/2.3.0.1/jaxb-core-2.3.0.1.jar http://central.maven.org/maven2/org/glassfish/jaxb/jaxb-jxc/2.3.2/jaxb-jxc-2.3.2.jar – Wang Qian Mar 20 '19 at 15:48
  • Finally. I made it work with java 18 – Juanpa Aug 05 '22 at 01:28
  • This helped me in 2022! :) – addd Nov 27 '22 at 19:42
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.

Simon Ruggier
  • 411
  • 3
  • 5
1

There is an issues according to previous answers, that you'd better to use more recent jaxb-impl jar such as 2.3.1 to avoid the reflection warning.

https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-impl/2.3.1/jaxb-impl-2.3.1.jar

Also if we put all jar files into ${APP_HOME}/lib and then append ${APP_HOME}/lib/* to CLASSPATH, the java will pick up all jar files.

MartenCatcher
  • 2,713
  • 8
  • 26
  • 39
Chen Gang
  • 11
  • 1
1

If you are on Apple Silicon or don't have wget installed:

cd Android/sdk/tools # or Android/tools
mkdir jaxb_lib
curl https://repo1.maven.org/maven2/javax/activation/activation/1.1.1/activation-1.1.1.jar -o jaxb_lib/activation.jar
curl 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
curl 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
curl 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
curl 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
curl 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
curl 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

# Add To CLASSPATH
sed -ie 's%^CLASSPATH=.*%\0:$APP_HOME/jaxb_lib/*%' bin/sdkmanager bin/avdmanager
# Add this manually on newline after CLASSPATH
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:$APP_HOME/jaxb_lib/istack-commons-runtime.jar:$CLASSPATH
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Krishna
  • 198
  • 2
  • 10
0

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156) at com.android.repository.api.SchemaModule.(SchemaModule.java:75) at com.android.sdklib.repository.AndroidSdkHandler.(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:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 5 more

Using Java 12, these are the steps I followed to bypass this warning. Thanks to Wang Qian.

Navigate to the path where the android sdk is installed such as the following.

%LOCALAPPDATA%\Android\Sdk\tools\bin

Edit sdkmanager.bat with a text editor such as notepad.

Find the following lines at approximately line 70.

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

Just above those lines, paste the following code.

set CLASSPATH=%CLASSPATH%;%APP_HOME%\mylib\jaxb-api.jar
set CLASSPATH=%CLASSPATH%;%APP_HOME%\mylib\jaxb-core.jar
set CLASSPATH=%CLASSPATH%;%APP_HOME%\mylib\jaxb-impl.jar
set CLASSPATH=%CLASSPATH%;%APP_HOME%\mylib\jaxb-jxc.jar
set CLASSPATH=%CLASSPATH%;%APP_HOME%\mylib\jaxb-xjc.jar
set CLASSPATH=%CLASSPATH%;%APP_HOME%\mylib\activation.jar

Create a new folder called mylib in the tools folder of your android sdk installation.

%LOCALAPPDATA%\Android\Sdk\tools\mylib

Download the latest version of the following 6 jar files and place them in the mylib folder.

Remove the versioning in the filenames to match the filenames set in the sdkmanager.bat file. You should now have the following files.

%LOCALAPPDATA%\Android\Sdk\tools\mylib\activation.jar
%LOCALAPPDATA%\Android\Sdk\tools\mylib\jaxb-api.jar
%LOCALAPPDATA%\Android\Sdk\tools\mylib\jaxb-core.jar
%LOCALAPPDATA%\Android\Sdk\tools\mylib\jaxb-impl.jar
%LOCALAPPDATA%\Android\Sdk\tools\mylib\jaxb-jxc.jar
%LOCALAPPDATA%\Android\Sdk\tools\mylib\jaxb-xjc.jar

All set! Now run your sdkmanager --update command

%LOCALAPPDATA%\Android\sdk\tools\bin\sdkmanager --update
hacker1024
  • 3,186
  • 1
  • 11
  • 31
Mugzzzy
  • 61
  • 1
  • 3
0

After trying Wang Qian's answer, I got Exception in thread "main" java.lang.NoSuchFieldError: REFLECTION. This might because the versions of jaxb-impl and jaxb-core are not matching. Make sure you download the same version of these two libraries, such as 2.3.0.1.

After that, I got another exception: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/istack/FinalArrayList. I found out this is because we are missing another library: istack-commons-runtime. Download it and put it into the classpath as well.


So the full list of library dependencies that need to add to classpath specifically should be:

  • jaxb-api
  • jaxb-core
  • jaxb-impl
  • jaxb-jxc
  • jaxb-xjc
  • activation
  • istack-commons-runtime

After this, you should be able to run sdkmanager but with a warning of illegal reflective access. You can ignore it without any problems. If you are interested in it, have a quick search. You'll find lots of questions on Stack Overflow regarding this warning.

Yihao Gao
  • 535
  • 7
  • 11
0

If you're on macOS using the android-sdk formula from Homebrew, it's discontinued and only supports Java 8. Quoting its formula page:

android-sdk requires Java 8. You can install it with: brew install --cask homebrew/cask-versions/temurin8

android-sdk has been officially discontinued upstream. It may stop working correctly (or at all) in recent versions of macOS.

For Java 11 and newer, you can install the android-commandlinetools formula.

brew install android-commandlinetools

Don't forget to set the ANDROID_HOME variable pointing to your "new" Android SDK directory:

export ANDROID_HOME=/usr/local/share/android-commandlinetools
jweyrich
  • 31,198
  • 5
  • 66
  • 97