Skip to content

Commit

Permalink
[xabuild] *Properly* package the .apk.
Browse files Browse the repository at this point in the history
Commit e20863e 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!
  • Loading branch information
jonpryor committed Apr 26, 2016
1 parent 4ff5c81 commit a9f69ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
12 changes: 11 additions & 1 deletion build-tools/mono-runtimes/mono-runtimes.targets
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
</Target>
<Target Name="_InstallBcl"
Inputs="$(_MonoPath)\mcs\class\lib\monodroid\mscorlib.dll"
Outputs="$(OutputPath)\lib\xbuild-frameworks\MonoAndroid\v1.0\mscorlib.dll">
Outputs="$(OutputPath)lib\xbuild-frameworks\MonoAndroid\v1.0\mscorlib.dll;$(OutputPath)lib\xbuild-frameworks\MonoAndroid\v1.0\RedistList\FrameworkList.xml">
<MakeDir Directories="$(OutputPath)\lib\xbuild-frameworks\MonoAndroid\v1.0" />
<MakeDir Directories="$(OutputPath)\lib\xbuild-frameworks\MonoAndroid\v1.0\RedistList" />
<MakeDir Directories="$(OutputPath)\lib\xbuild-frameworks\MonoAndroid\v1.0\Facades" />
<ItemGroup>
<_Assemblies Include="$(_MonoPath)\mcs\class\lib\monodroid\*.dll" />
Expand All @@ -91,6 +92,15 @@
<Touch
Files="$(OutputPath)\lib\xbuild-frameworks\MonoAndroid\v1.0\mscorlib.dll"
/>
<ItemGroup>
<FrameworkList Include="&lt;FileList Redist=&quot;MonoAndroid&quot; Name=&quot;Xamarin.Android Base Class Libraries&quot;&gt;" />
<FrameworkList Include="&lt;/FileList&gt;" />
</ItemGroup>
<WriteLinesToFile
File="$(OutputPath)lib\xbuild-frameworks\MonoAndroid\v1.0\RedistList\FrameworkList.xml"
Lines="@(FrameworkList)"
Overwrite="True"
/>
</Target>
<Target Name="_CleanRuntimes"
AfterTargets="Clean">
Expand Down
15 changes: 15 additions & 0 deletions src/Mono.Android/Mono.Android.targets
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@
Command="jar cf &quot;$(OutputPath)mono.android.jar&quot; -C &quot;$(IntermediateOutputPath)android-$(AndroidApiLevel).jcw\bin&quot; ."
/>
</Target>
<Target Name="_GenerateJavaCallableWrappers"
AfterTargets="CoreBuild"
Inputs="$(OutputPath)$(AssemblyName).dll"
Outputs="$(OutputPath)RedistList\FrameworkList.xml">
<MakeDir Directories="$(OutputPath)RedistList" />
<ItemGroup>
<FrameworkList Include="&lt;FileList Redist=&quot;MonoAndroid&quot; Name=&quot;Xamarin.Android $(AndroidFrameworkVersion) Support&quot; IncludeFramework=&quot;v1.0&quot;&gt;" />
<FrameworkList Include="&lt;/FileList&gt;" />
</ItemGroup>
<WriteLinesToFile
File="$(OutputPath)RedistList\FrameworkList.xml"
Lines="@(FrameworkList)"
Overwrite="True"
/>
</Target>
<Target Name="_CleanBinding"
AfterTargets="Clean">
<RemoveDir Directories="$(IntermediateOutputPath)android-$(AndroidApiLevel);$(IntermediateOutputPath)android-$(AndroidApiLevel).jcw" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,13 +800,6 @@ because xbuild doesn't support framework reference assemblies.
<CreateProperty Value="$(DefineConstants);$(AndroidDefineConstants)">
<Output TaskParameter="Value" PropertyName="DefineConstants" />
</CreateProperty>

<CreateProperty Value="smcs" Condition="'$(OS)' == 'Unix'">
<Output TaskParameter="Value" PropertyName="CscToolExe"/>
</CreateProperty>
<CreateProperty Value="$(_MonoAndroidBinDirectory)" Condition="'$(OS)' == 'Unix'">
<Output TaskParameter="Value" PropertyName="CscToolPath"/>
</CreateProperty>
</Target>

<!-- uploadflags.txt
Expand Down

0 comments on commit a9f69ad

Please sign in to comment.