2013-04-30

How to re-sign an android app(apk)?

In this article we are going to see how to un-sign a signed app. This is required when we will test an application apk file with robotium. For general ideal on robotium, I will provide separate post. First , let's have the apk file(application extension for a android app). Ex- game.apk

We can do this in two ways.

A. Manually :
Step 1:  Rename the APK as zip. Ex.game.zip

( To see the file extension in windows, Explorer > tools >folder option > view > un check )

Step 2: Delete META-INF folder
Step 3: Make the full folder into a ZIP file(re zip). Ex- game.zip

Step 4: Rename into apk extension. Ex- game.apk
Note(now there is no certificate now, so installation will be fail, if you try now) 
Step 5: open command prompt. and write the command
jarsigner -keystore [source keystore with path] -storepass android -keypass android [source apk with path] androiddebugkey
Example :  jarsigner -keystore C:\Users\shantonu/.android/debug.keystore -storepass android -keypass android D:\Android\android -sdk\platform-tools\game.apk androiddebugkey

Note : jarsigner  In windows PC, This command in here "C:\Program Files (x86)\Java\jdk1.6.0_06\bin" , so using command, you might need to brows to there.

Now you should be able to install apk.

Step 6: This is optional , it is necessary if apk is not installed properly. This will align the content inside the apk. To do this, From command prompt, navigate to \Android\android-sdk\tools, and type
zipalign 4   [source apk with path] [destination apk with path]
Example :
zipalign 4 D:\Android\android-sdk\platform-tools\game.apk D:\Android\android-sdk\platform-tools\AllignedApkName.apk

Now ,use that new apk and install to device.Your apk is re-signed with debugging key.

B. Using tool :
Step 1. Download the tool from this link
Step 2. Run this jar and drag the apk on to UI of the tool

Step 3: When it will prompt to save, save with new name


Step 4: press ok from confirmation message.


Now your apk is re-signed with debugging key.You may install in device.

Note : For windows pc, you need to add two system variable.
My computer > properties>Advance system settings >Environment variable
Then under system variables, press new

Variable Name : ANDROID_HOME
Variable Name : . Ex:- D:\Android\android-sdk\

Variable Name : JAVA_HOME
Variable Name : . Ex:- C:\Program Files (x86)\Java\jdk1.6.0_06\


Thanks...:)