Part 2 - Signing the Android Application Package

PDF for offline use

Let us know how you feel about this

Translation Quality


0/250

last updated: 2017-03

This guide explains how to sign the Android application package. If you are using an older version of Xamarin Studio (prior to version 5.9), see Xamarin Studio 5.8 and Earlier.

Signing the APK

In this section, we'll use Xamarin Studio's integrated publishing workflow to sign the APK. In Part 1, we used the Archive Manager to build the app and place it in an archive for signing and publishing. In this section, we'll learn how to create an Android signing identity, create a new signing certificate for Android applications, and publish the archived app ad hoc to disk. The resulting APK can be sideloaded into Android devices without going through an app store.

In Archive for Publishing, the Sign and Distribute... dialog presented us with two choices for distribution. Select Ad-Hoc and click Next:

Sign and Distribute dialog

Create a New Certificate

After clicking Ad-Hoc, Xamarin Studio opens the Android Signing Identity dialog as shown in the next screenshot. To publish the .APK, it must first be signed it with a signing key (also referred to as a certificate). If a certificate already exists, click the Import an Existing Key button to import it and then proceed to Sign the APK Otherwise, click the Create a New Key button to create a new certificate:

Android Signing Identity dialog

The Create New Certificate dialog is used to create a new signing certificate that can be used for signing Android applications. Click OK after entering in the necessary information:

Create New Certificate dialog

The resulting keystore resides in the following location:

~/Library/Developer/Xamarin/Keystore/alias/alias.keystore

For example, the above steps might create a new signing key in the following location:

~/Library/Developer/Xamarin/Keystore/chimp/chimp.keystore

For more information about the keystore, see Finding your Keystore's MD5 or SHA1 Signature.

Sign the APK

As seen here, a new certificate was added to the key store. To publish an app on Google Play, click Cancel and go to Part 3. Otherwise click Next to publish the app ad-hoc (for independent distribution) as shown in this example:

Sign and Distribute dialog

The Publish as Ad Hoc dialog provides a summary of the signed app before it is published. If this information is correct, click Publish.

Publish as Ad Hoc dialog

The Output APK file dialog will save the APK to the path specified. Click Save.

Output APK file dialog

Next, enter the password for the certificate (the password that was used in the Create New Certificate dialog) and click OK:

Enter certificate password

The APK is signed with the certificate and saved to the specified location. Click Reveal in Finder:

Publication Succeeded dialog

This opens the finder to the location of the signed APK file:

APK shown in Finder

The APK is ready to copy from the finder and send to its final destination. It's a good idea to install the APK on an Android device and try it out before distribution. See Part 6 for more information about publishing an ad-hoc APK.

This guide explains how to sign the Android application package using Xamarin Android 7.0 or later. If you are using Xamarin Android version 4.2.6 to 6.1, see Signing the Android Application Package (Visual Studio XA 4.2.6 to 6.1).

Signing the APK

This section describes the integrated publishing workflow to sign the APK provided by Visual Studio. In Part 1 the Archive Manager was used to build the app and place it in an archive for signing and publishing. This section explains how to create an Android signing identity, create a new signing certificate for Android applications, and publish the archived app ad hoc to disk. The resulting APK can be sideloaded into Android devices without going through an app store.

In Archive for Publishing, the Distribution Channel dialog presented two choices for distribution. Select Ad-Hoc:

Distribution Channel dialog

Create a New Certificate

After Ad-Hoc is selected, Visual Studio opens the Signing Identity page of the dialog as shown in the next screenshot. To publish the .APK, it must first be signed with a signing key (also referred to as a certificate).

An existing certificate can be used by clicking the Import button and then proceeding to Sign the APK. Otherwise, click the click the + button to create a new certificate:

Ad Hoc signing identity

The Create Android Key Store dialog is displayed; use this dialog to create a new signing certificate that can use for signing Android applications. Enter the required information (outlined in red) as shown in this dialog:

Create Android Key Store dialog

The following example illustrates the kind of information that must be provided. Click Create to create the new certificate:

Creating a new certificate

The resulting keystore resides in the following location:

C:\Users\USERNAME\AppData\Local\Xamarin\Mono for Android\alias\alias.keystore

For example, the above steps might create a new signing key in the following location:

C:\Users\USERNAME\AppData\Local\Xamarin\Mono for Android\chimp\chimp.keystore

For more information about the keystore, see Finding your Keystore's MD5 or SHA1 Signature.

Sign the APK

When Create is clicked, a new key store (containing a new certificate) will be saved and listed under Signing Identity as shown in the next screenshot. To publish an app on Google Play, click Cancel and go to Part 3. To publish ad-hoc, select the signing identity to use for signing and click Save As to publish the app for independent distribution. For example, the chimp signing identity (created earlier) is selected in this screenshot:

Signing Identity example

Next, the Archive Manager displays the publishing progress. When the publishing process completes, the Save As dialog opens to ask for a location where the generated .APK file is to be stored:

Save As dialog

Navigate to the desired location and click Save. If the key password is unknown, the Signing Password dialog will appear to prompt for the password for the selected certificate:

Signing Password dialog

After the signing process completes, click Open Folder:

Open Folder button

This causes Windows Explorer to open the folder containing the generated APK file. At this point, Visual Studio has compiled the Xamarin.Android application into an APK that is ready for distribution. The following screenshot displays an example of the ready-to-publish app, MyApp.MyApp.apk:

APK shown in Windows Explorer

Next Steps

After the application package has been signed for release, it must be published. The following sections describe several ways to publish an application.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.