Continuous integration and continuous deployments are a hot topic in the web world and are becoming a common practice there. In the mobile world however this is not the case “yet”.
Microsoft seems to have everything in place now for a full Mobile ALM suite. Building your cross platform apps with Xamarin (which they just acquired yesterday), storing your code and builds in VSTS (Visual Studio Team Services) and deploying your app to Hockeyapp. Usage and bug tracking can be done by either Xamarin insights, Hockeyapp or Microsoft Application insights (although the last one is deprecated). In the end I believe these 3 applications will merge into 1. So how do we set up these continuous deployments of our apps to hockeyapp? I’ll be describing this in a series of 3 blogposts (1 for each platform).
- Xamarin.Android (This post)
- Windows 10 UWP
- Xamarin.iOS
There are quite some differences in deploying the apps for the 3 platforms to Hockeyapp so that’s why I’ve decided to split them up into separate blog posts.
We’ll start with Android because this is the easiest and most straight forward. (who would have expected that?)
Context: the app we are going to deploy
I’ve created a simple solution in Visual Studio containing an average Xamarin project. 1 PCL, 1 Android app, 1 iOS app and 1 Windows 10 UWP app.
This solution is checked into my GIT repository stored in VSTS so lets move to there to start building the Android
Setting up the build in VSTS
in VSTS open your team project and go to the BUILD tab. in here we’re going to create a new build definition by clicking the green + sign.
Select the Xamarin.Android template which is already created by Microsoft for you.
Select the repository containing the solution and select the branch you want to deploy. you can even choose to build apps that are stored in different sources such as GitHub or remote Git repositories.
After everything is set click on Create
A build definition will be created and several build steps are generated for you. We’ll go over them one by one.
The first step is setting up your Xamarin license steps that will activate and deactivate your Xamarin license which is needed to execute the build of your Xamarin.Android project.
In this step you have to enter your email and password. Please note that the password field is a plain textbox and no password box. to fix this go to the “Variables” tab and create a variable with your password while you check the lock icon on the right. now you can store your password without other people being able to see it.
After you’ve created the Variable enter your email address and password variable into the 2 Xamarin License Steps (1 for activation and 1 for deactivation)
Please note that the deactivation step is set to always run (even if the build crashes half way)
Next we’ll be removing the Xamarin Test cloud build step in our build. Xamarin test cloud is a very nice tool to test your app on real devices but for this blogpost it’s a bit off topic. if you want to know more about how this works let me know and I’ll write another blog post about it.
I’ll also be deleting the MSBuild step that would build the unit test projects since my sample project did not have any unit tests.
Now the Xamarin license is set up we will start building the actual Android app. to do this we first need to build the PCL project. Add 2 extra build steps to our build definition by pressing the Add Build Step button
First Add a Nuget Installer step.
after that add a Visual Studio Build step.
Drag both steps to the top so the Nuget Installer is the first step and the Visual Studio Build step is the second.
The nuget installer step will be configured so it will install and update all nuget packages that are part of our solution. select your solution file in the “Path to Solution” field.
This is all we have to set up for the nuget packages. If you don’t have any nuget packages (is that possible these days?) you can remove this build step.
Next we’re going to set up the build of the PCL project. select the Visual Studio Build Step and select all the csproj file(s) that are part of your project.
Set the build platform to AnyCPU and make sure the configuration takes the $(BuildConfiguration) variable.
So now the PCL project builds lets move to the actual Android App build step.
Select your Android csproj file and make sure that the output directory is set to $(build.binariesdirectory)\$(BuildConfiguration) and the Configuration is set to $(BuildConfiguration)
Now all projects are being built and the only thing we need to do is publish the build artifacts so we can deploy them to Hockeyapp.
Set the Path to publish to $(build.binariesdirectory)\$(BuildConfiguration) and set the Artifact name to drop and the artifact type to Server.
Save your build and give it a test spin by clicking “Queue Build” you can also set the build to run automatically by adding a trigger in the Triggers tab.
if all is correct your build should now pass. on to the next step deploying a release to Hockeyapp!
Setting up Hockeyapp
I assume you’ve already created an account at Hockeyapp otherwise just sign up at www.hockeyapp.net (It’s free for 2 apps or less) once you’ve logged in go and create your first app by pressing the New App Button
Hockeyapp will ask you to upload a build. we’re not going to do that since we’re setting up automatic deployments. choose to add the app manually
Choose Android as your platform and select Alpha or Beta for release type. (whatever fits your app builds best). Give the app a title and fill in the Package Name and click save.
Now the app is created and it will show up on your dashboard. click on your app and copy your App ID. we’ll need it later.
To be able to deploy from VSTS we need to set up an API token we can use in VSTS. Click on your user icon in the top right and select API Tokens from the menu on the left.
Create a new API token and call it VSTS. Copy this API token. we’ll need it in VSTS
Move back to VSTS and open up the marketplace (top right next to your name) and click manage extensions. browse the marketplace and install the Hockeyapp extension
After installing the extension go back to your VSTS team project and navigate to the settings window. in the settings menu go to Services and add a new service Endpoint of type “Hockeyapp”
Give the endpoint a proper name and copy in the API token you’ve generated earlier. now save the service endpoint.
Now all the plumbing with Hockeyapp is done we can actually start deploying our app to hockeyapp
Deploying your automated build to Hockeyapp
Go back to your team project in VSTS and navigate to the Release tab
Choose an Empty deployment template and press OK.
First go to the Artifact tab and select the build we’ve created earlier as supplier of the artifacts we’re going to release to hockeyapp.
Go back to Environments, name your deployment template and add a new Task
This list should now contain a Hockeyapp step since we installed that as our extension
Configure the Hockeyapp step by selecting the Hockeyapp connection from the list. (the service connection you’ve created earlier should be listed here) Enter the APP ID you copied earlier and select the .apk file that was generated by the build.
The last step is setting the trigger to automatically start your hockeyapp deployment after each successful build. go to triggers, select Continuous deployment and make sure that the environment trigger is set to “Automated: after release creation.”
Save the deployment template and now you are ready to go. you can now manually create a new release using the deployment template or start a new build and you should see your app show up in Hockeyapp so your testers can download the app.
If you have any questions let me know via twitter @geertvdc or by commenting below.
Hopefully you’ll be back tomorrow for the next post explaining all the steps for Windows 10 UWP apps.
Geert van der Cruijsen
October 24, 2016 at 13:53
This was really very helpful post, I followed and successful in VSTS and hockeyapp integration and deployment. Thanks a lot.
December 16, 2016 at 12:53
That’s really helpful. Followed it successfully. Thanks!