I’ve been working on an android app with Xamarin lately and I wanted to deploy it to App Center automatically so I can install it on my mobile to test it as I hate manual deployment.
I knew that App Center had a connector to azure devops repositories so you can build and deploy when a new commit arrives but I wanted to use Azure pipelines because there might be the need to deploy other things than the app. So after reading A LOT of documentation here and there here’s how I made it work.
This tutorial assumes that you already have a Xamarin for android project created.
Create a keystore file with Android Studio
If you don’t have Android Studio yet, you can download it here : https://developer.android.com/studio/
Once in Android Studio, you need to create your keystore file by creating a new empty project, then go to Build in the menu and click on Generate Signed Bundle / APK
In the subsequent window, select the APK options
You need now to create the keystore by clicking on the “Create New” button under the keystore path
Then fill the next window.
Key store path : the path where your file will be saved
Password : Minimum 6 characters
Alias : this is the name of the key you will use to sign your app
Password : can be different that the keystore password
Validity : I left it at 25 years, you can change it if you want.
The rest of the window is self-explanatory, I have no idea if this influences in any way the behaviour of the key or the keystore but I’m guessing no.
You need to keep track of the informations you put in this window as we will need them later.
You can now close Android Studio as we won’t be needing it again.
Get App Center Api key
In order to deploy from Azure Devops to App Center you need an Api key from App Center.
You need go open App Center, go to account settings in the menu under your avatar on the upper right corner. In the following screen, scroll down until the User Api Key section, open it and click on the New API token button. Enter the name of your key then select Full Access.
When you click the Add new API token, you will receive your API key. Mind that it appears only once so make sure you save the key somewhere as you will need it afterwards.
Copy the keystore file in Azure Devops
In Azure devops there is a place where you can store securely any files you may need for your pipelines, it is called Secure Files. You can access it in your Azure Devops environment under Pipelines > Library.
You need to upload your keystore file here in order to access it in your pipeline
You can also authorize all your pipelines to access the file. But if you don’t, Azure Devops will ask you for permission when you will run your pipeline for the first time
Create the App Center connection
In order to deploy your build to App Center, a connection between Azure Devops and App Center needs to be established. To do so, open the project settings, and click on Service Connection.
Click on New Service Connection, choose the Visual Studio App Center, then Next
This is where you use the Api key you got from App Center earlier.
I decided to use YAML here instead of building my pipeline with the provided GUI because I wanted to see how functional it is and I must say I’m quite happy with it. You include it in your repository and then you have your pipeline source controlled which is very nice. When you have the Azure Pipeline extension installed in your Visual Studio Code, it gets easier.
This is my YAML file which is functional
pool: vmImage: 'VS2017-Win2016' variables: buildConfiguration: 'Debug' outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)' steps: - task: NuGetToolInstaller@0 - task: NuGetCommand@2 inputs: restoreSolution: '**/*.sln' - task: XamarinAndroid@1 inputs: projectFile: '**/*.csproj' outputDirectory: '$(outputDirectory)' configuration: '$(buildConfiguration)' - task: AndroidSigning@3 inputs: apksign: true apksignerKeystoreFile: 'Name of your file in Secure Files' apksignerKeystorePassword: '$(password)' apksignerKeystoreAlias: 'Name of the key specified in Android Studio' apksignerKeyPassword: '$(keypassword)' zipalign: false apkFiles: '$(outputDirectory)/*.apk' - task: PublishBuildArtifacts@1 inputs: pathtoPublish: '$(outputDirectory)' - task: AppCenterDistribute@3 inputs: serverEndpoint: 'Name of your App Center connection' appSlug: 'AppCenterAccountName/AppName' appFile: '$(outputDirectory)/*.apk' symbolsOption: 'Android' releaseNotesOption: 'input' releaseNotesInput: 'Some message to give your users' destinationType: 'groups'
It was quite an ordeal to find all the informations to finally be able to automatically deploy to App Center from Azure Devops with a sign APK. If you are having any trouble with this present guide, don’t hesitate to contact me in the comment section or on twitter @Sisudev, I will gladly help you.