This tutorial is going to look at how you can manually re-sign an Android APK for an application on your device. In another post we’ll look at using Robotium to run unit tests on Android applications for which you don’t have the original source code. There is a tool that does this for you, but if you experience problems with this, either check out this nugget, or read on…
Assuming you have the Android SDK installed, you will need an app (or see comment below) that can backup other apps on your device (like AndroZip) and an Archive application on your PC that allows you to delete items within a zip archive (such as 7-zip [PC] or BetterZip [Mac]). For this tutorial I am going to re-sign my demo app ‘Custom Buttons’ which you can grab from my downloads page.
- To start, backup your target app to SD card using AndroZip and transfer to your PC
- Change the file extension from .apk to .zip
- Open the archive with your chosen utility, delete the ‘META-INF’ folder and exit your utility programme, saving the changes if prompted. Don’t extract the zip, remove the folder then re-zip – this won’t work!
- Change the extension back to .apk
- Re-sign the .apk file with you debug certificate in terminal. Here I have
cd‘d to the directory containing my target apk file
jarsigner -verbose -keystore ~/.android/debug.keystore targetapp.apk androiddebugkey
- When prompted, the password to enter is
- Verify that the app has been signed properly:
jarsigner -verify targetapp.apk
cdinto your Android SDK tools folder and run zipalign, specifying the location of the input file and output file.
$ ./zipalign -v 4 ~/Desktop/targetapp.apk ~/Desktop/targetapp-aligned.apk
- Verify that the apk has been correctly aligned
$ ./zipalign -c -v 4 ~/Desktop/targetapp-aligned.apk
- Now you can uninstall the original application from your Android device and install this re-signed application to your device. There are many ways to do this, but from the command-line,
cdinto your platform-tools directory and, provided you only have the one device attached, enter:
$ ./adb install ~/Desktop/targetapp-aligned.apk