From a9f69ad2371777dfd06f80d5e960efbab1462260 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Tue, 26 Apr 2016 09:28:37 -0400 Subject: [PATCH] [xabuild] *Properly* package the .apk. Commit e20863ea adds an `xabuild` script, which allows us to build Android .apk application packages. And lo, it was good! *Unfortunately*, while a .apk was *generated*, the app on-device would immediately crash with a bizarre error. Further investigation pointed to the actual problem: While xamarin-android was generating the .apk, the framework assemblies that were bundled into the app were coming from the local system Xamarin.Android install. (Oops.) Two things are required in order to cause the correct assemblies to be bundled into the app.apk: 1. MSBuild/xbuild require that the bin/$(Configuration)/lib/xbuild-frameworks/MonoAndroid/v* directories contain a `RedistList/FrameworkList.xml` file, otherwise the directory isn't recognized as a valid location for MSBuild frameworks. Since these files were missing, the built assemblies weren't considered for use when compiling the app. Update the build system to generate these files. 2. Xamarin.Android.Common.targets was overriding the $(CscToolExe) and $(CscToolPath) MSBuild properties when running on OS X to refer to an `smcs` script, which (i) doesn't exist in the xamarin-android repo, so (ii) the system-installed smcs script was used instead. The smcs script is no longer necessary, and hasn't actually been required for *years* (behold! laziness!), so just remove these property overrides. With these two changes, `xabuild` is not only able to generate an Android .apk file, but the resulting .apk will actually run on-device! Woo-hoo! --- build-tools/mono-runtimes/mono-runtimes.targets | 12 +++++++++++- src/Mono.Android/Mono.Android.targets | 15 +++++++++++++++ .../Xamarin.Android.Common.targets | 7 ------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/build-tools/mono-runtimes/mono-runtimes.targets b/build-tools/mono-runtimes/mono-runtimes.targets index 339a210007b..86d1c63e428 100644 --- a/build-tools/mono-runtimes/mono-runtimes.targets +++ b/build-tools/mono-runtimes/mono-runtimes.targets @@ -73,8 +73,9 @@ + Outputs="$(OutputPath)lib\xbuild-frameworks\MonoAndroid\v1.0\mscorlib.dll;$(OutputPath)lib\xbuild-frameworks\MonoAndroid\v1.0\RedistList\FrameworkList.xml"> + <_Assemblies Include="$(_MonoPath)\mcs\class\lib\monodroid\*.dll" /> @@ -91,6 +92,15 @@ + + + + + diff --git a/src/Mono.Android/Mono.Android.targets b/src/Mono.Android/Mono.Android.targets index 34afe42e7c9..8b457ec64a9 100644 --- a/src/Mono.Android/Mono.Android.targets +++ b/src/Mono.Android/Mono.Android.targets @@ -117,6 +117,21 @@ Command="jar cf "$(OutputPath)mono.android.jar" -C "$(IntermediateOutputPath)android-$(AndroidApiLevel).jcw\bin" ." /> + + + + + + + + diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 1652f21a257..2e75b389d9e 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -800,13 +800,6 @@ because xbuild doesn't support framework reference assemblies. - - - - - - -