Monday, November 5, 2018

Update and re-sign apk file for android testing

Sometimes you gets an apk file from other developers, and need to update certain web resource files (AndroidManifest.xml, javascript, text, or image files), and then resign it to run some testing on your android device. The following steps can be used to do so.

1. download APKTool based on
https://ibotpeaches.github.io/Apktool/install/

2. Run the below command from terminal to extract origin.apk
apktool d /Users/i826633/Documents/Bugs/496624/origin.apk

3. update the web resource files in the extracted folder

4. run the below command to build the update
apktool b /Users/i826633/Documents/Bugs/496624/origin
this will generate a new apk file in /Users/i826633/Documents/Bugs/496624/origin/dist folder

5. for simplifying, rename generated apk file to updated.apk and copy it out to the same folder as original apk file

6. from terminal run the below command from the folder containing your updated apk file. You may need to update the path based on android studio version
/Users/i826633/Library/Android/sdk/build-tools/28.0.2/zipalign -v -p 4 updated.apk aligned.apk 

7 copy your android sign jks file to the same folder, and then resign the aligned apk with the below command. If you do not yet have a signing jks file, you can use the debug signing file created by android studio. It is under C:\Users\username\.android\debug.keystore, and the password is 'android'
/Users/i826633/Library/Android/sdk/build-tools/28.0.2/apksigner sign --ks debug.keystore--out signed.apk aligned.apk

8. run the below command to verify the signed apk is valid. If anything is wrong, it will report an error
/Users/i826633/Library/Android/sdk/build-tools/28.0.2/apksigner verify signed.apk

9. install the apk to device and run it on your device
adb install signed.apk


As a side note, to reload the webview content in android cordova webview, run the below code from Chrome inspector's javascript debugger
window.location.reload()

No comments:

Post a Comment