|||

Building and Deploying apps using VSTS and HockeyApp - Part 2 : Android

This post talks about building and deploying Android apps using Visual Studio team services. This is part 2 of series of posts. To see how to build iOS apps using VSTS, please see part 1 of this series.

Build Variables

Variable Name Variable Value
system.debug false
BuildConfiguration release
BuildPlatform any cpu

Develop Branch

dev build steps

Step 1: Nuget restore

Field Name Field Value
Path to Solution Locate the Android only solution that has the Android project and the shared code.
Path to Nuget Locate path of any custom nuget config files. See part 1 for more details
Installation Type restore

Step 2: Build Android

Field Name Field Value
Project Path to Droid.csproj file
Output Directory $(build.binariesdirectory)/$(BuildConfiguration)
Configuration $(BuildConfiguration)

Note: $(build.binariesdirectory) is a system variable. For a list of all system variables see this link

Beta Branch

beta build steps

Step 1: Nuget restore

Same as develop branch

Step 2: Version AndroidManifest.xml

Field Name Field Value
Source Path Path to properties folder in the Droid folder
File Pattern AndroidManifest.xml
Build Regex Pattern \d+

Advanced Tab

Field Name Field Value
Build Regex Group Index 0
Regex Replace Pattern versionCode="\d+
Prefix for Replacements versionCode="
Fail If No Target Match Found true

Step 3: Apply Google Maps Release Key

With google maps there are 2 keys for GMaps

  • debug maps key
  • release maps key

The debug key is used during the application development. I typically share my debug.keystore with other team members so the maps work for everyone. I also put the debug and release keystore files in a folder AndroidKeys’ and check that along with the solution. The developers can copy the debug.keystore from the solution and put that in a directory on their development machine.

Note: The location for debug.keystore on my machine is C:\Users\Raghu\AppData\Local\Xamarin\Mono for Android

To create a release keystore file follow this link on Xamarin’s website.

After both keys are created, we need to get a google maps api key. This can be achieved by following information here. When we build and debug the android app using Visual studio, it uses the debug.keystore file to sign the app, but when we build for production we sign the app with a release.keystore (that is our company’s private key).

The AndroidManifest.xml file contains the debug google api key.

<meta-data android:name="com.google.android.geo.API_KEY" android:value="My Debug Key" />

This build step changes this debug key to the one related to the release.keystore file, with the following configuration.

Field Name Field Value
Tool perl
Arguments -pi -e 's/Old debug Key/New Release Key-s/g' AndroidManifest.xml

Advanced Tab

Field Name Field Value
Working Folder Android Project properties folder
Fail on standard error true

Step 4: Print AndroidManifest.xml

This step is optional to make sure the contents of the AndroidManifest.xml are updated correctly from the last build step

Field Name Field Value
Tool cat
Arguments Path to AndroidManifest.xml

Step 5: Build Android

Field Name Field Value
Project Path to droid.csproj file
Output Directory $(build.binariesdirectory)/$(BuildConfiguration)
Build Configuration $(BuildConfiguration)

JDK Options Tab

Field Name Field Value
Select JDK to use for the build JDK Version
JDK Version default
JDK Architecture x86

Step 6: Signing and Zipalign apk

Field Name Field Value
APK Files [Path to Droid Project Folder]/**/*.apk

Jarsigner Options

Field Name Field Value
Sign the APK true
Keystore File $(Agent.BuildDirectory)\s\Path to KeyStore files\release.keystore
Keystore Password password or a secure build variable
Alias The alias we created at the time of creating the release.keystore file
Key Password Same as Keystore Password but once again
Jarsigner Arguments -verbose -sigalg MD5withRSA -digestalg SHA1

Zipalign Options

Field Name Field Value
Zipalign true

Step 7: Deploy Android to HockeyApp

Field Name Field Value
HockeyApp Connection Choose from the Dropdown
App ID The Guid app id of the hockey app where the apk needs to land
Binary File Path [Path to Droid Folder]/**/*droid.apk
Publish true

Master Branch

master build

With the master branch all builds steps are identical to the beta branch with the exception of the following three.

Step 6: Copy Files to Staging directory

Field Name Field Value
Source Folder [Path To Droid project folder]/obj/release/android/bin
Contents *droid.apk
Target Folder $(build.artifactstagingdirectory)

Advanced Tab

Field Name Field Value
Clean Target Folder true

Step 7: Publish Artifacts

Field Name Field Value
Path To Publish $(build.artifactstagingdirectory)
Artifact Name MyApp-PlayStore-Build
Artifact Type Server

Step 8: Deploy to HockeyApp

Same configuration as the beta Deploy to hockey step except a different App ID for a new hockey bucket.

Up next Building and Deploying apps using VSTS and HockeyApp - Part 1 : iOS Building and Deploying apps using VSTS and HockeyApp - Part 3 : Windows Phone
Latest posts Refactor react code to use state store instead of multiple useState hooks Notes on Python Threat Modelling - Using Microsoft STRIDE Model WCAG - Notes Flutter CI/CD with Azure Devops & Firebase - iOS - Part 1 Flutter CI/CD with Azure Devops & Firebase - Android - Part 2 How to samples with AWS CDK A hashicorp packer project to provision an AWS AMI with node, pm2 & mongodb Some notes on Zeebe (A scalable process orchestrator) Docker-Compose in AWS ECS with EFS volume mounts Domain Driven Design Core Principles Apple Push Notifications With Amazon SNS AWS VPC Notes Building and Deploying apps using VSTS and HockeyApp - Part 3 : Windows Phone Building and Deploying apps using VSTS and HockeyApp - Part 2 : Android Building and Deploying apps using VSTS and HockeyApp - Part 1 : iOS How I diagnosed High CPU usage using Windbg WCF service NETBIOS name resolution woes The troublesome Git-Svn Marriage GTD (Getting things done) — A simplified view Javascript Refresher Sharing common connection strings between projects A simple image carousel prototype using Asp.net webforms and SignalR Simple logging with NLog Application logger SVN Externals — Share common assembly code between solutions Simple async in .net 2.0 & Winforms Clean sources Plus Console 2 — A tabbed console window