Getting Android sdkmanager to run with Java 11

◇◆丶佛笑我妖孽 提交于 2019-12-03 17:02:05

问题


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?


回答1:


If anyone is looking for a Linux fix on Java 11. I built this on top of Wang's answer

cd Android/tools/bin
mkdir jaxb_lib
wget http://central.maven.org/maven2/javax/activation/activation/1.1.1/activation-1.1.1.jar -O jaxb_lib/activation.jar
wget http://central.maven.org/maven2/javax/xml/jaxb-impl/2.1/jaxb-impl-2.1.jar -O jaxb_lib/jaxb-impl.jar
wget http://central.maven.org/maven2/org/glassfish/jaxb/jaxb-xjc/2.3.2/jaxb-xjc-2.3.2.jar -O jaxb_lib/jaxb-xjc.jar
wget http://central.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 http://central.maven.org/maven2/org/glassfish/jaxb/jaxb-jxc/2.3.2/jaxb-jxc-2.3.2.jar -O jaxb_lib/jaxb-jxc.jar
wget http://central.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. Scroll down to the CLASSPATH variable, and add the new jars we just downloaded like this:

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



回答2:


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%
...



回答3:


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.

  • http://central.maven.org/maven2/javax/activation/activation/
  • http://central.maven.org/maven2/javax/xml/bind/jaxb-api/
  • https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-core
  • https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl
  • https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-xjc
  • http://central.maven.org/maven2/org/glassfish/jaxb/jaxb-jxc/

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



回答4:


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.



来源:https://stackoverflow.com/questions/53076422/getting-android-sdkmanager-to-run-with-java-11

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!