All Collections
Test
Xamarin.UITest and Signing Android Apps
Xamarin.UITest and Signing Android Apps

Using your Android Keystore to sign your Android App

Jihye E avatar
Written by Jihye E
Updated over a week ago

Background

When Xamarin.UITest executes tests with your Android APK it uses a test server that runs in process with your app to help facilitate the tests. Android will not allow that, unless the test server and your APK are signed with the same Android Keystore. Normally, Xamarin.UITest signs both your APK and the test server with the same debug Keystore and that works.

But, some apps will only work if signed with a specific Android Keystore. Apps that use Google Maps are one example. Also, running locally, if you are connecting to an already installed app you may need to specify the Keystore so that the test server can be signed with the one that matches that APK.

You can specify your Keystore directly or you can specify a Signing Info file that can be used instead. The purpose of the Signing Info file is to avoid exposing your Android Keystore and passwords. 

First we'll examine using your Keystore locally and then in App Center Test. Using you Keystore is the easiest way to start. Once you have that working you may want to go through the extra step of creating and using a Signing Info file. You never specify them both together.

Android Keystore

Local

When running locally with Xamarin.UITest to specify an Android Keystore, use the KeyStore method on your ConfigureApp.Android  statement:

Example:

ConfigureApp.Android.Keystore(path, spass, kpass, alias).StartApp();

public AndroidAppConfigurator KeyStore (String path, String storePassword, String keyPassword, String keyAlias)

Configures the keystore that the provided apk file is signed with. A keystore is not required, but will ensure that the apk file is pristine and unchanged. If a keystore is provided, it will be used to sign the auxiliary apks installed along with the app on the device. If a keystore is not provided, Xamarin.UITest will generate a keystore and resign the apk.

If you are connecting to an already installed APK see this Xamarin forum post.

App Center Test Cloud

Question from a user:
"Hello, I ran Android Xamarin.UITest on App Center Test Cloud. For some reason the device is not loading Google Maps. Can you tell me why the map is not loading?"

The problem in this case was that the APK was getting resigned in App Center Test Cloud with a different Android Keystore. To use the correct Keystore specify it in the CLI command when submitting your tests. 

Example addition to your CLI appcenter test run uitestcommand:

--store-password mystorepass --key-alias myalias --key-password mykeypass --store-path /Users/myname/test_keystore

All four of these command line options must be specified to use this approach.

--store-password <arg> Password to the keystore. Corresponds to the -storepass  argument in jarsigner.

--key-alias <arg>  Alias to the key in the keystore. Corresponds to the -alias  argument in jarsigner.

--key-password <arg> Password to the matching private key in the keystore. Corresponds to the -keypass  argument in jarsigner.

--store-path <arg>  Path to the keystore file.

Signing Info File

The other approach is to create and specify a signing info file. This has the same effect but does not use your Keystore and passwords in the command line. This does require creating a Signing Info.

First, find the test-cloud.exe in your NuGet packages folder for the version of Xamarin.UITest that you are using. It will be in the tools folder under a Xamarin.UITest folder. Then, use it to generate the Signing Info file. If you change the version of Xamarin.UITest you are using, you will need to generate a new Signing Info file.

Generating the Signing Info file

Windows:

test-cloud.exe gen-sign-info <apk-signed> <keystorefile> <keystorepass> <keyalias> <keypass> [--dir <directory] 

Mac:

mono test-cloud.exe gen-sign-info <apk-signed> <keystorefile> <keystorepass> <keyalias> <keypass> [--dir <directory] 

NOTE: Generating the signing information file using test-cloud.exe is only supported through UITest version 2.2.7.

Arguments:

<apk-signed>Path to the application under test, signed,

<keystorefile> Path to the keystore.

<keystorepass>  Password for keystore.

<keyalias>  Alias for key in keystore.

<keypass>  Password for private key.

Options:

--dir <directory> Destination directory for signing info file. (default: apk directory).

Local

When running locally with Xamarin.UITest to specify an Signing Info file, use the SigningInfoFile method on your ConfigureApp.Android  statement:

Example:

ConfigureApp.Android.SigningInfoFile(path).StartApp();
public AndroidAppConfigurator SigningInfoFile (String path)


Configures the signing info file that the test server will be "signed" with. A signing info file is not required, but can be used instead of a keystore for signing the test server. The signing info file can be freely shared without the risk of leaking keying material. The signing info file can be generated using the console tool.

App Center Test Cloud

To use the Signing Info file in your App Center Tests, specify it in the CLI command when submitting your tests. 

Example addition to your CLI appcenter test run uitestcommand:

--sign-info /Users/myname/test_signinfofile

There is just this one additional command line option to specify the Signing Info file:

--sign-info <arg> Use Signing Info file for signing the test server. 

Did this answer your question?