8
1

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.

Xamarin(その2)Advent Calendar 2016

Day 2

Visual Studio Team ServicesでXamarin.Androidをビルドする時に気を付ける事

Last updated at Posted at 2016-12-02

はじめに

この記事は「Xamarin(その2) Advent Calendar 2016 - Qiita」の2日目です。
(遅れてごめんなさい~)

(ホントは、Visual Studio Team ServicesでXamarinをもっと楽に使うをAdvent Calendarに挙げたかったです。)

本記事で解決する事

Xamarin.AndroidのプロジェクトをVisual Studio Team Servicesでビルドする

なぜ、これをネタに挙げたのか

選択肢のdefaultがビルドできない設定であり、ハマったから...

再現手順

Visual Studio Team ServicesでBuild definitionを作る際に、JDK Versionを変えず、初期値defaultのままで保存し、ビルドを実行するvsts_build_csproj.png

結果

プロジェクトのビルドに失敗する

ログ

失敗してますね

2016-12-02T16:04:07.1936537Z ##[section]Starting: Build Xamarin.Android Project Phoneword.csproj
...
2016-12-02T16:04:12.9420485Z   MonoAndroid Tools: C:\Program Files (x86)\MSBuild\Xamarin\Android\
2016-12-02T16:04:12.9430481Z   MonoAndroid Binaries: C:\Program Files (x86)\MSBuild\Xamarin\Android\
2016-12-02T16:04:12.9430481Z   Android Platform API level: 24
2016-12-02T16:04:12.9430481Z   TargetFrameworkVersion: v6.0
2016-12-02T16:04:12.9430481Z   Android NDK: \
2016-12-02T16:04:12.9430481Z   Android SDK: C:\java\androidsdk\android-sdk\
2016-12-02T16:04:12.9430481Z   Android SDK Build Tools: C:\java\androidsdk\android-sdk\build-tools\24.0.2\
2016-12-02T16:04:12.9430481Z   Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_45\
...
2016-12-02T16:04:31.1021909Z   C:\Program Files (x86)\Java\jdk1.6.0_45\\bin\javac.exe -J-Dfile.encoding=UTF8 -d obj\Release\android\bin\classes -classpath "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0\mono.android.jar" -bootclasspath C:\java\androidsdk\android-sdk\platforms\android-24\android.jar -encoding UTF-8 "@C:\Users\buildguest\AppData\Local\Temp\tmp7721.tmp" 
2016-12-02T16:04:32.8878609Z   obj\Release\android\src\md509b4767b40af69f246eff6e802137e4e\MainActivity.java:5: cannot access android.app.Activity
2016-12-02T16:04:32.8898615Z   bad class file: android\app\Activity.class(android\app:Activity.class)
2016-12-02T16:04:32.8898615Z   class file has wrong version 52.0, should be 50.0
2016-12-02T16:04:32.8898615Z   Please remove or make sure it appears in the correct subdirectory of the classpath.
2016-12-02T16:04:32.8898615Z   	extends android.app.Activity
2016-12-02T16:04:32.8898615Z   	                   ^
2016-12-02T16:04:32.9118630Z ##[error]obj\Release\android\src\md509b4767b40af69f246eff6e802137e4e\MainActivity.java(5,21): Error :  cannot access android.app.Activity
bad class file: android\app\Activity.class(android\app:Activity.class)
class file has wrong version 52.0, should be 50.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
	extends android.app.Activity
...
2016-12-02T16:04:32.9198620Z 
2016-12-02T16:04:32.9198620Z     0 Warning(s)
2016-12-02T16:04:32.9198620Z     1 Error(s)
2016-12-02T16:04:32.9198620Z 
2016-12-02T16:04:32.9198620Z Time Elapsed 00:00:21.55
2016-12-02T16:04:33.1828604Z ##[error]Process 'msbuild.exe' exited with code '1'.
2016-12-02T16:04:33.2048614Z ##[section]Finishing: Build Xamarin.Android Project Phoneword.csproj

原因

Android SDK Build-tools packageのVersion 24を利用する場合、JDK 1.8を利用する事が期待された動作である。
しかし、ログにJava SDK: C:\Program Files (x86)\Java\jdk1.6.0_45\と出力されているように、defaultではJDK 1.6を利用している為に、Xamarin.Androidプロジェクトのビルドに失敗した。

解決策

Build definitionJDK VersionJDK 8を指定する
vsts_build_csproj2.png

ログ

成功してますね

2016-12-02T16:30:22.5040169Z ##[section]Starting: Build Xamarin.Android Project Phoneword.csproj
...
2016-12-02T16:30:28.1133680Z   MonoAndroid Tools: C:\Program Files (x86)\MSBuild\Xamarin\Android\
2016-12-02T16:30:28.1133680Z   MonoAndroid Binaries: C:\Program Files (x86)\MSBuild\Xamarin\Android\
2016-12-02T16:30:28.1133680Z   Android Platform API level: 24
2016-12-02T16:30:28.1133680Z   TargetFrameworkVersion: v6.0
2016-12-02T16:30:28.1133680Z   Android NDK: \
2016-12-02T16:30:28.1133680Z   Android SDK: C:\java\androidsdk\android-sdk\
2016-12-02T16:30:28.1133680Z   Android SDK Build Tools: C:\java\androidsdk\android-sdk\build-tools\24.0.2\
2016-12-02T16:30:28.1133680Z   Java SDK: C:\Program Files\Java\jdk1.8.0_102\
...
2016-12-02T16:30:49.9946759Z Done Building Project "C:\a\1\s\Phoneword.csproj" (PackageForAndroid target(s)).
2016-12-02T16:30:49.9976767Z 
2016-12-02T16:30:50.0006764Z Build succeeded.
2016-12-02T16:30:50.0006764Z     0 Warning(s)
2016-12-02T16:30:50.0016763Z     0 Error(s)
2016-12-02T16:30:50.0016763Z 
2016-12-02T16:30:50.0016763Z Time Elapsed 00:00:23.45
2016-12-02T16:30:50.0876774Z ##[section]Finishing: Build Xamarin.Android Project Phoneword.csproj

まとめ

  1. 「defaultを選択した時に、何が設定されるか」を正しく理解しましょう
  2. AndroidプロジェクトのAPIレベルを確認しましょう

そして、Visual Studio Team Services(VSTS)を使って、開発に注力しましょう

8
1
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
8
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?