Monday, April 14, 2014

Resign an APK File With New Certificate



Problem:

We have an apk file that is modified and signed by co-developer and want to publish it as an update of existing application in the Google Play.

Google Play rejects the new update as it signed using a different certificate.

Solution: 

Resign the file using the old certificate.

If you work on mac this problem is solved easily using this few line of shell script as following.

zip -d new-apk.apk META-INF/\*
jarsigner -verbose -storetype pkcs12 -keystore old-cert.pfx -storepass old-cert-password new-apk.apk old-cert-alias
jarsigner -verify new-apk.apk
/AndroidSDKPath/tools/zipalign -v 4 new-apk.apk new-apk-aligned.apk


And presto! A modified apk signed with old certificate.

What it does is strip META-INF directory from the apk file, sign and verify the apk, and the last is zipalign the apk.

No comments:

Post a Comment