Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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

以上

参考

https://stackoverflow.com/questions/47150410/failed-to-run-sdkmanager-list-android-sdk-with-java-9

geishatokyo
「こんなの、はじめて。」世の中を驚き、喜ばせ、楽しませるサービスを作る、ハイテクエンターテインメントのベンチャー企業
https://www.geishatokyo.com/
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした