Continuos Integration from Microsoft for iOS and Android projects for free. Five years ago, even knowing that MS moves towards cross-platform support and open source, I wouldn’t believe in that. Now it’s the reality.
In this blog post I’ll show how to use Visual Studio Team Services (VSTS) and HockeyApp for setting up CI builds for Xamarin Android projects.
Configuring CI builds for Xamarin projects is an easy and straightforward process, after you’ve done it once, it takes less than 10 minutes to create build definitions for other projects. Let’s go through each step in detail.
Make sure that you’ve created a Team Project in VSTS and added your app to the HockeyApp.
Before we proceed to build definitions, there are a few configurations needs to be done.
0) Let’s start by opening the team project.
1) HockeyApp deployments are not available out of the box, but luckily for us, Microsoft created an extension. Click on the market icon in the upper right corner.
Search for a hockeyapp extension select the one from Microsoft.
2) We also need to create a HockeyApp connection to allow VSTS communicate with your HockeyApp account.
Open the API Tokens section on the Account Settings page and create a new Full Access token for your app (or for all apps if you have multiple apps).
Now go to the settings page in the VSTS (a small gear icon in the upper right corner) and select the Services tab. Click on the New Service Endpoint and select HockeyApp from the dropdown menu. Enter a connection name and paste the token.
Now we’re ready create a build definition.
1) Click on the BUILD link.
2) Add new build definition by clicking on the green plus button on the left panel and selecting Xamarin.Android
3) Specify repository, select a branch and make sure that CI checkbox is checked.
4) VSTS creates a default build definition, but we need to make a few changes. Since MS made Xamarin free, we don’t need to activate/deactivate Xamarin license anymore. So remove Activate Xamarin license, Deactivate Xamarin license steps. Also remove Publish Artifact step. Add HockeyApp step, and disable MSBuild and Xamarin Test Cloud steps (we’re not going to use unit tests or xamarin test cloud in this article, but you may want to enable them later). After all these changes the build definition will look like this:
CONFIGURE BUILD STEPS
Now let’s go through each step.
1) Nuget Installer only needs to know a path to your solution file. All other fields can be left blank/default.
2) Specify a path to the android project in Xamarin.Android step.
3) Android Signing
APK Files path is using the output directory from the Xamarin.Android step – $(build.binariesdirectory)/$(BuildConfiguration) and adds a mask to look after .apk files.
To sign the APK file, you need to specify a path to the keystore file. I use $(Build.Repository.LocalPath) variable to get a local path to the sources on the agent (more predefined variables here). Don’t forget to specify Keystore Password, Alias and Key Password.
We also want to use the zipalign tool.
At this point we have a signed .apk file. Let’s push it to the HockeyApp.
You already have a HockeyApp connection.
App ID can be found on the application page in HockeyApp
Binary file path again uses the Output Directory from Xamarin.Android step, appending it with the apk filename. I also find Release Notes (File) very useful, since it allows you to write release notes for each build in a text file within your project.
And that’s it!
Now hit the save button, give a name for the build definition and manually request a build by right clicking on the build definition and selecting Queue build. If everything is correct, in about 5-10 minutes you’ll get a an email with a link to the new version of the app. It’s amazing, isn’t it?