Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
5
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

Organization

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

次のような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'

以上

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
5
Help us understand the problem. What are the problem?