Building Xamarin Android application using Team Foundation Build 2015

During 2015 Microsoft presented new, scriptable build system that's web-based and cross-platform. New build system is easy customizable and it's intended to replace old XAML based mechanism.

Every build definition is made of build tasks. In order to kick start build definition creation process, there are predefined templates available.


As you can see, one of templates is Xamarin.Android. Let's select it and proceed to next screen.

Repository Type: Here we can see that build mechanism enables different repository types (TFVC, Git, Subversion). Choose the one corresponding your source code repository.

Default Agent Queue: In order to do processor-intensive work of your build process you must have at least one build agent. New build mechanism have Hosted build agents ready to be used. This means that we don't have to set up and maintain machine that will carry on build process, but we can use hosted ones, as long as they satisfy demands of build definition.

Continuous integration: Whether build should be triggered after each checking or not.

Repository

First step in build process is getting code files from source control to build machine. So let's go to repository tab and chose what Server Path we want to map (and what we want to cloak).

Build Tasks

Xamarin.Android build template have following tasks:

Xamarin License Activate/Deactivate

Since Xamarin requires having active license in order to build Xamarin solutions we have to activate license in build definition. Simply provide your Xamarin Email and Password. Build definition can have variables and they can be secret, which is convenient when providing passwords.

At the end deactivate Xamarin license using the same technique.

Xamarin.Android

Choose csproj file you want to build and enter other build properties. You may want to select specific JDK Version (JDK 7 or JDK 8) if your project uses latest Xamarin.

MSBuild

If enabled, this build step is going to build all projects that has word "test" in its name.

Xamarin Text Cloud

Xamarin Test Cloud is Xamarin testing platform. Since we are not using it, let's remove this task.

Android Signing

Result of Xamarin.Android build is apk file. That apk file is still not ready to be installed on Android devices, as it has to be signed and aligned first. You can find more info about the process here.

In this build step you should define location of your keystore on your source control, alongside with alias, password and Jarsigner Arguments.

Copy and Publish Build Artifacts

The last build task is to publish artifacts of build process. For Xamarin Android build we are only interested in apk file.

Additional tasks

You may want to add additional tasks that are not part of Xamarin.Android build template. There are a lot of build tasks on your disposal.

Versioning

We added PowerShell task which will call ApplyVersionToAsseblies script. Job of this script is to update all dll and exe files with build version number.

We added one more PowerShell script called ApplyVersionToAndroidManifest.ps1. It's job is to update AndroidManifest, as we want to see build number within the application.

NuGet Installer

Since we are using NuGet we added this build step to provide all the necessary packages to build our application.

Completed Build Tasks

This is how build tasks list look after all changes:

Build version format

On General tab you can define your build version format. We decided for the following:

[code lang=csharp]$(Build.DefinitionName)_$(MajorVersion).$(MinorVersion).$(EnvironmentId)$(rev:.r)[/code]

MajorVersion, MinorVersion and EnvironmentId are build variables.

Queue build

Let's go and queue new build for using our new definition.


This is build summary page. You can track progress of the build and see logs in real-time. Also here you can see all other details, including issues and Associated work items. Build artifacts are available on Artifacts tab, ready to be downloaded manually or processed by Release Management.

Leave A Comment