Apk - Edit and rebuild

Cheatsheet - Apk rebuild for debug purpose Link to heading

This tutorial describes the different steps to edit and rebuild an apk from the apk file.

Prerequisites Link to heading

This manipulation require to enable USB debugging in your android device (https://developer.android.com/studio/debug/dev-options) and have adb, apktool, jarsigner, keytool and zipalign installed on your computer. A rooted device is NOT needed.

Get the apk from adb : Link to heading

First, get the path to the apk in your filesystem :

$ adb shell pm path com.name.yourapp
package:/data/app/com.name.yourapp-K1Ep_ZmFrZWRhdGE6KQ==/base.apk

Use adb pull with the string of the previous step :

$adb pull /data/app/com.name.yourapp-K1Ep_ZmFrZWRhdGE6KQ==/base.apk

Decompile and edit Link to heading

Decompile :

$apktool d base.apk

A folder called base is created. Now you can edit files (smali,res,assets,…).

Rebuild : Link to heading

Rebuild the apk with apktool:

$apktool b base/

Create a keystore (do it just once):

$keytool -genkey -v -keystore debug.keystore -alias android -keyalg RSA -keysize 2048 -validity 20000

Go to the base/dist folder.

Sign the apk :

$jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ../../debug.keystore base.apk android

Align the zip :

$/opt/android-sdk/build-tools/29.0.2/zipalign -v 4 base.apk base_aligned.apk

Install on your device :

$adb install base_aligned.apk

Enjoy.