Sunday, September 29, 2013

How to fix "Install Parse Failed - Inconsistent Certificates" when installing .APK file

If you install an Android application (.apk file) to your phone from one machine, and then try to install it again later when it's built on another machine with a different apk signature (e.g. from a CI build) then you will get the following message on the phone:  (In this example I've tried to install the app from an email attachment directly on the phone.)



"Application not installed. An existing package by the same name with a conflicting signature is already installed."



Similarly if you try to install the app on another development machine using ADB (or from the IDE) you get the following "install parse failed inconsistent certificates" error message:

$ adb install TestProj-debug-unaligned.apk 
1539 KB/s (45347 bytes in 0.028s)
 pkg: /data/local/tmp/TestProj-debug-unaligned.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]
$ adb install -r TestProj-debug-unaligned.apk 
2659 KB/s (45347 bytes in 0.016s)
 pkg: /data/local/tmp/TestProj-debug-unaligned.apk
Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]

You also get the exact same message as above if you try to run the application from within Android Studio of course:

Waiting for device.
Target device: CB5A1QHGNF
Uploading file
  local path: /Users/lombard/src/TestProjProject/TestProj/build/apk/TestProj-debug-unaligned.apk
  remote path: /data/local/tmp/com.example.testproj
Installing com.example.testproj
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.testproj"
pkg: /data/local/tmp/com.example.testproj
Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]

You've got two options:
  1. Copy the first machine's debug.keystore file to the second machine. See: How to deal with INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES without uninstallation on StackOverflow.
  2. Completely uninstall the application first and then install again. You may have to do this if you don't have the debug.keystore file for some reason. Perhaps your Jenkins CI build has a different release keystore.
I've had to go for the second option.

I was hoping I'd be able to keep the application's data, so I first tried uninstall with the -k option to keep the data files, however that results in an "update incompatible" error:

$ adb shell pm uninstall -k com.example.testproj
$ adb install -r TestProj-debug-unaligned.apk
1532 KB/s (45347 bytes in 0.028s)
 pkg: /data/local/tmp/TestProj-debug-unaligned.apk
Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE]

The only solution seems to be to uninstall the application completely:

$ adb uninstall com.example.testproj
Success

Now the app will install from Android Studio.

Ideally I want to find a way to force an app to reinstall without needing to completely uninstall it first.
Post a Comment