Publishing Android Apps to Microsoft App Center from Azure DevOps
Tags: tutorial, azure, devops, android
Published: 2021-02-16 11:41:27

---
title: Publishing Android Apps to Microsoft App Center from Azure DevOps
published: true
date: 2021-02-16 11:41:00 UTC
tags: #tutorial #azure #devops #android
canonical_url: https://sahansera.dev/publishing-android-apps-to-microsoft-appcenter/
cover_image: https://sahansera.dev/static/719b446733d6f6c94634fdc5ac50b15e/d170a/publishing-android-apps-to-microsoft-appcenter.jpg
---

In my previous article, we looked at how we can set up multi-stage builds for an Android app with Azure DevOps. In this article, we will be looking at distributing this app to App Center for internal testing.

> 💡 Note: that this a continuation of my previous blog article, [Multi-stage builds for Ionic Apps with Azure Pipeline Templates](https://sahansera.dev/multi-stage-builds-with-azure-pipelines-ionic/). I suggest you go through it if you haven’t already.

Let’s look at what we are going to be building today. As always, you can find the complete source code in [here](https://github.com/sahan91/AzurePipelinesTemplateForIonic/tree/main/infrastructure).

![publishing-android-apps-to-microsoft-appcenter-0-1.jpg](https://sahansera.dev/static/cf8523b7f8c99e1590a8c36b89f7da7a/4b190/publishing-android-apps-to-microsoft-appcenter-0-1.jpg "publishing-android-apps-to-microsoft-appcenter-0-1.jpg")

### What is Microsoft (Visual Studio) App Center?

Microsoft App Center is a platform where you can build, test, distribute and monitor your mobile apps. The beauty of this is that you can use it as a place to distribute your apps for a target user group for beta testing your app - similar to TestFlight but you can do it for multiple apps.

### Creating a new app in App Center

To get started, head over to [https://appcenter.ms/apps](https://appcenter.ms/apps). If you haven’t already got an app created in App Center, we first need to do that. You could either create it under an Organization or a User. In my case, I have created it under my user account. The details look like this.

![publishing-android-apps-to-microsoft-appcenter-0.png](https://sahansera.dev/static/a95b1151a762b81518dbb9366f37c6d4/f941f/publishing-android-apps-to-microsoft-appcenter-0.png "publishing-android-apps-to-microsoft-appcenter-0.png")

### Creating a Service Connection

Before pushing our signed APK to the App Center, we need to create a link between the Azure DevOps instance and the App Center tenant. For that, we will be creating a service connection so that the build agent has necessary credentials to make this link work and where to put the latest build.

There are two parts to getting a service connection.

First, we need to generate an API token which will be used by the [AppCenterDistribute](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/app-center-distribute?view=azure-devops) task. Let’s do the following steps in the App Center.

1. Click on Profile Icon (top-right corner)→ Account Settings → User API Tokens.
2. Click on New API token button.
3. Give it a memorable description
4. Select Full Access as for Access option.

> 💡 Tip: Make sure to copy the API token as we will need it for our next step.

![publishing-android-apps-to-microsoft-appcenter-1.png](https://sahansera.dev/static/9c9b0e0a7797131de2c091f86dcfff47/5a190/publishing-android-apps-to-microsoft-appcenter-1.png "publishing-android-apps-to-microsoft-appcenter-1.png")

Once that’s done, let create the service connection in Azure DevOps.

1. Navigate to your project’s settings → Scroll down until you find Service connections. At the time of writing, it could be found under `https://dev.azure.com/{your directory}/{your project name}/_settings/adminservices`
2. Click on Create service connection.
3. Type in “App Center” in the search box and select Visual Studio App Center from the list.
4. Full in the details of the service connection pop up, as shown below. Make sure to keep the Server URL as it is.

![publishing-android-apps-to-microsoft-appcenter-2.png](https://sahansera.dev/static/025d1bf8c932d953e40ce6ff04bc82e5/0b5b1/publishing-android-apps-to-microsoft-appcenter-2.png "publishing-android-apps-to-microsoft-appcenter-2.png")

Now we can use this service connection to deploy our app from Azure DevOps to the App Center.

### Configuring the deploy task

We will first look at configuring the deploy task for the Debug build. We will add a new “Deploy” stage and continue from there.

The latest additions to the [azure-piplines.yml](https://github.com/sahan91/AzurePipelinesTemplateForIonic/blob/main/infrastructure/azure-pipelines.yml) will look like follows.

```yaml
...
- stage: Deploy
    displayName: Deploy Debug and Release Apps to App Center
    dependsOn: Build
    jobs:
      - deployment: Deploy_Android_Debug
        variables:
          buildConfiguration: Debug
        displayName: Deploy Android - Debug App
        pool:
          vmImage: $(vmImageName)
        environment: Staging
        strategy:
          runOnce:
            deploy:
              steps:
                - template: ionic-android-debug-deploy.yml
                  parameters:
                    appCenterServiceConnection: 'App Center Integration for Sample App'
                    appSlug: '{username}/{appname in App Center}'
                    appFile: '$(Pipeline.Workspace)/$(projectName)/app-$(buildConfiguration).apk'
                    releaseNotes: 'Debug App'
```

I’m not going to do this for release build as it will be the same configuration but a different app slug.

> 💡 How do I find the app slug? Go to your app’s overview page in App Center and take note of the URL; the app slug would be {your org or user name}/{app name}

Let’s create a new file for the [ionic-android-release-deploy.yml](https://github.com/sahan91/AzurePipelinesTemplateForIonic/blob/main/infrastructure/ionic-android-debug-deploy.yml) for the App Center deployment.

```yaml
parameters:
  - name: appCenterServiceConnection
    displayName: 'Name of the service connection with App Center'
  - name: appSlug
    displayName: 'Path to application in AppCenter'
  - name: appFile
    displayName: 'Path of the apk to deploy'
  - name: releaseNotes
    displayName: 'Release notes'
  - name: deployMobileAssets
    displayName: "Deploy Mobile Assets"

steps:    
  - task: AppCenterDistribute@3
    inputs:
      serverEndpoint: '${{ parameters.appCenterServiceConnection }}'
      appSlug: '${{ parameters.appSlug }}'
      appFile: '${{parameters.appFile}}'
      symbolsOption: 'Android'
      destinationType: 'groups'
      releaseNotesOption: 'input'
      releaseNotesInput: '${{parameters.releaseNotes}}'
    displayName: 'Distribute to App Center'
```

The configuration for the release app will be the same in our case. So I am going to skip to keep things simple.

Once the pipeline runs, you should be able to see your brand new app release in the App Center 😎 Pat yourself on the back! Rest is easy.

![publishing-android-apps-to-microsoft-appcenter-3.png](https://sahansera.dev/static/921a3d6e1089f48dbc8e2859a7a33f12/5a190/publishing-android-apps-to-microsoft-appcenter-3.png "publishing-android-apps-to-microsoft-appcenter-3.png")

### Deploying our app for internal testing

App Center has the concept of adding [collaborators](https://docs.microsoft.com/en-us/appcenter/dashboard/creating-and-managing-apps#adding-collaborators-to-apps) to your app. This means that you can share your app with others by inviting them via email addresses. The official docs explains the concepts behind [creating teams](https://docs.microsoft.com/en-us/appcenter/dashboard/creating-and-managing-teams) for your app.

When you have a release under your app, you could then distribute it to your team members by going to the “Distribute” on the left sidebar.

You can either create a new release from an existing release artifact or decide to distribute the release you have already got there.

![publishing-android-apps-to-microsoft-appcenter-4.png](https://sahansera.dev/static/a27206e53db13e280f40de758be1d722/5a190/publishing-android-apps-to-microsoft-appcenter-4.png "publishing-android-apps-to-microsoft-appcenter-4.png")

![publishing-android-apps-to-microsoft-appcenter-5.png](https://sahansera.dev/static/073af347e2baa8d5fcaa1782c47b1ed0/5a190/publishing-android-apps-to-microsoft-appcenter-5.png "publishing-android-apps-to-microsoft-appcenter-5.png")

When adding user groups for testing, you can add the teams you have already created for your app or directly share it with their email address. Once you hit Submit, they will receive an email to directly download the APK to their phone, install and run the app.

### Conclusion

This article continued building upon our previous azure-pipelines.yml file and looked at how we can deploy our app to App Center for distribution. I hope this was helpful. Until next time 👋

### References

[https://docs.microsoft.com/en-us/appcenter/](https://docs.microsoft.com/en-us/appcenter/)

[https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema](https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema)