Skip to content

Commit

Permalink
[xabuild] Add MSBuild wrapper script to build Xamarin.Android projects
Browse files Browse the repository at this point in the history
(IDEs?! We don't need no stinkin' IDEs! [0, 1])

`tools/scripts/xabuild` is an `xbuild` ("MSBuild") -using script to
support building Xamarin.Android projects from the command-line,
without modifying or replacing the "system" Xamarin.Android install.
Also handy if there are multiple development branches available.

`tools/scripts/xabuild` takes the same command-line arguments as
xbuild(1) and MSBuild, allowing projects to be built and application
packages to be created:

  ${xamarin-android-checkout-path}/tools/scripts/xabuild /t:SignAndroidPackage
  adb install bin/Debug/*-Signed.apk

Xamarin.Android.Build.Tasks.dll is updated to look for an alternate,
*available*, path to `libmonosgen-2.0.so`, and to remove the
%(Reference.Private) metadata so that all required assemblies are
installed into $(OutputPath). (Previous versions of Xamarin.Android
would encode the ABI into the filename, but this encoding should no
longer be necessary.)

android-toolchain is altered to provide `_GetAndroidNdkDirectory` and
`_GetAndroidNdkDirectory` targets, so that the xabuild script can
properly determine the path to the $(AndroidToolchainDirectory)
location.

[0]: In the spirit of: https://www.youtube.com/watch?v=VqomZQMZQCQ
[1]: Seriously, we often like to keep the "system" Xamarin.Android
    untouched and unchanged, so that we can more easily build filed
    bugs/etc., so the easiest way to build a Xamarin.Android project
    from a development branch is from an `xbuild` wrapper script and
    building from the command line [2].
[2]: https://developer.xamarin.com/guides/android/under_the_hood/build_process/#Build_Targets
  • Loading branch information
jonpryor committed Apr 25, 2016
1 parent 995f9aa commit e20863e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
3 changes: 1 addition & 2 deletions build-tools/android-toolchain/android-toolchain.mdproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ItemType>GenericProject</ItemType>
<ProjectGuid>{8FF78EB6-6FC8-46A7-8A15-EBBA9045C5FA}</ProjectGuid>
</PropertyGroup>
<Import Project="..\..\Configuration.props" />
<Import Project="android-toolchain.targets" />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>$(AndroidToolchainDirectory)</OutputPath>
</PropertyGroup>
Expand All @@ -23,7 +23,6 @@
_CreateNdkToolchains;
</BuildDependsOn>
</PropertyGroup>
<Import Project="android-toolchain.targets" />
<ItemGroup>
<ProjectReference Include="..\..\src\Xamarin.Android.Tools.BootstrapTasks\Xamarin.Android.Tools.BootstrapTasks.csproj">
<Project>{E8492EFB-D14A-4F32-AA28-88848322ECEA}</Project>
Expand Down
13 changes: 13 additions & 0 deletions build-tools/android-toolchain/android-toolchain.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\Configuration.props" />
<Import Project="android-toolchain.projitems" />
<Target Name="_CopyBootstrapTasksAssembly"
Outputs="$(OutputPath)\Xamarin.Android.Tools.BootstrapTasks.dll">
Expand Down Expand Up @@ -85,4 +86,16 @@
AlwaysCreate="True"
/>
</Target>
<Target Name="_GetAndroidSdkDirectory">
<Message
Text="$(AndroidToolchainDirectory)\sdk"
Importance="High"
/>
</Target>
<Target Name="_GetAndroidNdkDirectory">
<Message
Text="$(AndroidToolchainDirectory)\ndk"
Importance="High"
/>
</Target>
</Project>
2 changes: 1 addition & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void AddRuntimeLibraries (ZipFile apk, string supportedAbis)
apk.AddEntry (string.Format ("lib/{0}/libmonodroid.so", abi), File.OpenRead (path));
if (!use_shared_runtime) {
// include the sgen
library = string.Format ("libmonosgen-2.0.{0}.so", abi);
library = "libmonosgen-2.0.so";
path = Path.Combine (root, "lib", abi, library);
apk.AddEntry (string.Format ("lib/{0}/libmonosgen-2.0.so", abi), File.OpenRead (path));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@
</Reference>
<Reference Include="Ionic.Zip">
<HintPath>..\..\packages\Unofficial.Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="FSharp.Compiler.CodeDom">
<HintPath>..\..\packages\FSharp.Compiler.CodeDom.1.0.0.1\lib\net40\FSharp.Compiler.CodeDom.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
25 changes: 25 additions & 0 deletions tools/scripts/xabuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash -e
topdir="$(cd `dirname "$0"`/../.. && pwd)"

if [ -z "$CONFIGURATION" ] ; then
CONFIGURATION=Debug
fi

export TARGETS_DIR="$topdir/bin/$CONFIGURATION/lib/xbuild"
export MSBuildExtensionsPath="$TARGETS_DIR"
export MONO_ANDROID_PATH="$topdir/bin/$CONFIGURATION"
export XBUILD_FRAMEWORK_FOLDERS_PATH="$topdir/bin/$CONFIGURATION/lib/xbuild-frameworks"
ANDROID_NDK_PATH=$(cd $topdir/build-tools/android-toolchain && xbuild /nologo /v:minimal /t:_GetAndroidNdkDirectory android-toolchain.targets)
ANDROID_SDK_PATH=$(cd $topdir/build-tools/android-toolchain && xbuild /nologo /v:minimal /t:_GetAndroidSdkDirectory android-toolchain.targets)

ANDROID_NDK_PATH=$(echo $ANDROID_NDK_PATH | sed 's/^\w*//g')
ANDROID_SDK_PATH=$(echo $ANDROID_SDK_PATH | sed 's/^\w*//g')

export ANDROID_NDK_PATH
export ANDROID_SDK_PATH

exec xbuild $MSBUILD_OPTIONS \
/p:AndroidNdkDirectory="$ANDROID_NDK_PATH" \
/p:AndroidSdkDirectory="$ANDROID_SDK_PATH" \
/p:MonoDroidInstallDirectory="$MONO_ANDROID_PATH" \
"$@"

0 comments on commit e20863e

Please sign in to comment.