Kevin Schultz

Mobile Engineering

Sharing Android Debug Keystore

| Comments

How often do you see the “Re-installation failed due to different application signatures” error when trying to install a development APK? By default the Android build chain uses a local debug signing keystore, so the same commit built on two different machines will be signed differently and can not re-install on top of each other. This is easily fixed by putting a shared debug keystore into your project repo. It’s a simple time saver if you sometimes use different computers, have a continuous integration server, or work with a team.

Unlike the release signing keystore, the debug keystore can be changed at any time. In fact they expire 1 year after creation, so if your project runs for a significant amount of time you will have to update it. Simply copy your local debug.keystore file into the repo. On Linux and Mac OS X this is located in ~/.android/. I personally create a new folder named external to keep it separate from the project source code and assets.

Once you have the keystore in your repo, override the default debug signing configuration to use shared file. The sample below are for Gradle, but this is also pretty straightforward in Ant and Maven.

Override Debug Signing Configuration
1
2
3
4
5
6
7
8
9
10
android {

    ...

    signingConfigs {
        debug {
           storeFile file("external/debug.keystore")
       }
   }
}

If you have custom build variants, you can use the debug signing configuration as shown below.

Custom Build Variants
1
2
3
4
5
6
7
8
9
10
android {

  ...

   productFlavors {
       demo {
           signingConfig signingConfigs.debug
       }
   }
}

This is generally one of the first things I do when setting up a project so I don’t have to ever bother with uninstalling and reinstalling an APK manually. For a bit more information on the debug.keystore file, and where it is located on Windows, see the Android Documentation.

Comments