9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mac+Java9+UnityでAndroidビルドする時のエラーの対処法

Last updated at Posted at 2018-03-13

次のようなNoClassDefのエラーが出て、Androidビルドができなくなった時の対処法です

CommandInvokationFailure: Unable to list target platforms. Please make sure the android sdk path is correct. See the Console for more details. 
/Users/takezoux2/Library/Android/sdk/tools/bin/avdmanager list target -c
stderr[
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
	... 5 more
]
stdout[
]
exit code: 1

原因

ビルドの途中でsdkmanagerやavdmanagerのコマンド実行をする際にデフォルトのJavaが使われることになるが、Java9の場合JigSawにより、Java8までデフォルトで含まれていたクラスが含まれなくなったため発生しています。

対処方法

1. (これはやってると思いますが)UnityのSDKの設定をjava1.8にする

Unity>Preferences>ExternalToolのJavaSDKの項目でJDK1.8系を指定して下さい。

2. avdmanagerやsdkmanagerを修正し、XML系のモジュールを追加

~/Library/Android/sdk/tools/bin/avdmanager
~/Library/Android/sdk/tools/bin/sdkmanager

をそれぞれテキストエディターで開き、該当箇所を下のようにそれぞれ修正して下さい。

avdmanager
# Add default JVM options here. You can also use JAVA_OPTS and AVDMANAGER_OPTS to pass JVM options to this script.
#DEFAULT_JVM_OPTS='"-Dcom.android.sdkmanager.toolsdir=$APP_HOME"'
DEFAULT_JVM_OPTS='"-Dcom.android.sdkmanager.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
sdkmanager
# Add default JVM options here. You can also use JAVA_OPTS and SDKMANAGER_OPTS to pass JVM options to this script.
# DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME"'
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

以上

参考

9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?