我尝试在ubuntu上运行android-studio,但它向我发送了上面标记的错误。这是到目前为止发生的所有事情: 实际上,我使用jdk 1.11作为默认版本。但是当我尝试运行sdkmanger时出现以下错误
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: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
我已经在网上寻找解决方案,并且找到了两种解决方法。第一个是减少我的Java版本。因为该错误实际上是由于java.xml从java1.9过时的事实引起的 第二个是保留在jdk1.11上并通过运行sdkmanager使用以下参数来解决错误 我已经完成了导出环境变量的操作,如:
export JAVA_OPTS="-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee"
首先,我决定使用第二个,但出现错误,找不到java.se.ee,而且我也找不到解决方法。
然后我尝试第一个,使用
减少Java版本update-alternatives --config java
update-alternatives --config javac
,到目前为止效果很好。 从这里找到的解决方案中,我修改了sdkmanager的脚本,从而使Java以-Xms500m -Xmx2g参数开头
我花了一些时间分析sdkmanager的启动情况,并得到了以下反馈:
library initialization failed - unable to allocate file descriptor table - out of memoryCommand terminated by signal 6
Command being timed: "java -Xms500m -Xmx2g -Dcom.android.sdklib.toolsdir=/var/Android/Sdk/tools -classpath
/var/Android/Sdk/tools/lib/dvlib-26.0.0-dev.jar:
/var/Android/Sdk/tools/lib/jimfs-1.1.jar:/var/Android/Sdk/tools/lib/jsr305-1.3.9.jar:
/var/Android/Sdk/tools/lib/repository-26.0.0-dev.jar:
/var/Android/Sdk/tools/lib/j2objc-annotations-1.1.jar:
/var/Android/Sdk/tools/lib/layoutlib-api-26.0.0-dev.jar:
/var/Android/Sdk/tools/lib/gson-2.3.jar:
/var/Android/Sdk/tools/lib/httpcore-4.2.5.jar:
/var/Android/Sdk/tools/lib/commons-logging-1.1.1.jar:
/var/Android/Sdk/tools/lib/commons-compress-1.12.jar:
/var/Android/Sdk/tools/lib/annotations-26.0.0-dev.jar:
/var/Android/Sdk/tools/lib/error_prone_annotations-2.0.18.jar:
/var/Android/Sdk/tools/lib/animal-sniffer-annotations-1.14.jar:
/var/Android/Sdk/tools/lib/httpclient-4.2.6.jar:
/var/Android/Sdk/tools/lib/commons-codec-1.6.jar:
/var/Android/Sdk/tools/lib/common-26.0.0-dev.jar:
/var/Android/Sdk/tools/lib/kxml2-2.3.0.jar:
/var/Android/Sdk/tools/lib/httpmime-4.1.jar:
/var/Android/Sdk/tools/lib/annotations-12.0.jar:
/var/Android/Sdk/tools/lib/sdklib-26.0.0-dev.jar:
/var/Android/Sdk/tools/lib/guava-22.0.jar
com.android.sdklib.tool.sdkmanager.SdkManagerCli"
User time (seconds): 0.19
System time (seconds): 0.04
Percent of CPU this job got: 76%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.31
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 31216
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 5
Minor (reclaiming a frame) page faults: 3483
Voluntary context switches: 235
Involuntary context switches: 74
Swaps: 0
File system inputs: 152
File system outputs: 64
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0