Skip to content

Instantly share code, notes, and snippets.

@nstarke
Last active April 28, 2024 16:29
Show Gist options
  • Save nstarke/615ca3603fdded8aee47fab6f4917826 to your computer and use it in GitHub Desktop.
Save nstarke/615ca3603fdded8aee47fab6f4917826 to your computer and use it in GitHub Desktop.
How to make a Release Android App debuggable

How to make a Release Android App debuggable

Let's say you want to access the application shared preferences in /data/data/com.mypackage.
You could try to run adb shell and then run-as com.mypackage ( or adb shell run-as com.mypackge ls /data/data/com.mypackage/shared_prefs), but on a production release app downloaded from an app store you're most likely to see:

run-as: Package 'com.mypackage' is not debuggable

While ADB's adb backup command will pull many of the files from the application's data directory, the files can be inconsistent with what is actually on the device. If you want to see what is actually on the device, you need to make the application debuggable.

For this task, we'll need apktool ( http://ibotpeaches.github.io/Apktool/ ). Once you have it setup, you'll need to find the path to the APK to pull it off the device. Run:

$ adb shell pm list packages -f -3

Find the package in the list (it should look something like /data/app/com.mypackage.apk=com.mypackage), and pull it off the device:

$ adb pull /data/app/com.mypackage.apk

Next, we need to disassemble the apk using apktool:

$ apktool d -o output-dir com.mypackage.apk

In output-dir, find AndroidManifest.xml and open it up in the text editor of your choice. In the application xml node, add the following xml attribute:

android:debuggable="true"

Now we need to reassemble the application. We do this by running:

$ apktool b -o com.mypackge.apk output-dir

Finally, we need to resign the APK so that the device will accept it:

$ keytool -genkey -v -keystore resign.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore resign.keystore com.mypackage.apk alias_name

That's it! You should now be able to transfer the new com.mypackage.apk back to the device and run it. Now you should be able to run adb shell run-as ls /data/data/com.mypackage/ without getting the debuggable error.

@olalonde
Copy link

olalonde commented Mar 3, 2023

When installing I get:

adb: failed to install com.mypackage.apk: Failure [-124: Failed parse during installPackageLI: Targeting R+ (version 30 and above) requires the resources.arsc of installed APKs to be stored uncompressed and aligned on a 4-byte boundary]

Edit:

Works by using this command instead of jarsigner:

apksigner sign --ks resign.keystore --ks-pass pass:somepassword myapp.apk

@Arinerron
Copy link

What if the jar file is one that you cannot uninstall? Is there an easy way to just change the package path so it doesn't error?

@amahdy
Copy link

amahdy commented Jul 16, 2023

After spending the night on this, I've compiled all errors, findings, and workarounds here: https://gist.github.com/amahdy/87041554f62e384bee5766a958fd4f9a

Unfortunately I still did not achieve what I was aiming for (which is linking the new apk with the old data), the only solution would be root but I'm still avoiding it for now.

@kdrkdrkdr
Copy link

This script can make app debuggable!

apk_name=com.example
apk_location=$(adb shell pm list packages -f -3 | grep $apk_name | sed 's/.*:\(.*\).apk.*/\1/').apk
adb pull $apk_location original.apk
keytool -genkey -v -keystore resign.keystore -storepass androiddbg -alias androiddbg -dname "CN=Android Debug,O=Android,C=US"
python make_debuggable.py apk original.apk patched.apk resign.keystore androiddbg
adb uninstall $apk_name
adb install patched.apk

Push file example!

tmp="/data/local/tmp"
adb push /home/Desktop/a.txt $tmp
adb shell run-as com.example cp $tmp $dst

Pull file example!

app="com.example"
adb -d shell "run-as $app cat /data/user/0/$app/file.txt" > file.txt

@RomanDorofeyev
Copy link

apksigner sign --ks resign.keystore --ks-pass pass:somepassword myapp.apk

Thanks, that helps!

@Shmuel930
Copy link

Did everything, the app is signed and I can install it.
But it crashes at the moment I start it.
Any idea why?

@julKali
Copy link

julKali commented Dec 20, 2023

Did everything, the app is signed and I can install it. But it crashes at the moment I start it. Any idea why?

@Shmuel930 I cobbled up a script that often works better, have you tried using it? Unlike apktool it doesn't decompile (and recompile) the whole Manifest, so it tends to be more robust against obfuscation and anti-debugging measures.

https://github.com/julkali/makedebuggable

@Shmuel930
Copy link

Did everything, the app is signed and I can install it. But it crashes at the moment I start it. Any idea why?

@Shmuel930 I cobbled up a script that often works better, have you tried using it? Unlike apktool it doesn't decompile (and recompile) the whole Manifest, so it tends to be more robust against obfuscation and anti-debugging measures.

https://github.com/julkali/makedebuggable

Hey, yea I've used it as well, same results

@Strengthless
Copy link

Got the INSTALL_PARSE_FAILED_RESOURCES_ARSC_COMPRESSED error upon installation.

It seems that jarsigner no longer works for SDK 30+.

Switched to using apksigner, and things worked perfectly.

apksigner sign -v --ks resign.keystore com.mypackage.apk

@julKali
Copy link

julKali commented Mar 14, 2024

Did everything, the app is signed and I can install it. But it crashes at the moment I start it. Any idea why?

@Shmuel930 I cobbled up a script that often works better, have you tried using it? Unlike apktool it doesn't decompile (and recompile) the whole Manifest, so it tends to be more robust against obfuscation and anti-debugging measures.
https://github.com/julkali/makedebuggable

Hey, yea I've used it as well, same results

If you haven't solved it yet, would you mind opening an issue on my repo, (or apktool's and linking it here), I would be interested in finding the problem.

@mickael28
Copy link

@nstarke @julKali , I followed the apktool script and manage to create a debuggable APK of Need For Speed (trying to copy the save date in a new Android 12), the problem I have though is that when launching the app on the phone, it just doesn't work.

It gives and error and just say: try later or quit.

Do you know why that could be?

@ttsiodras
Copy link

Just wanted to thank you - this worked perfectly for me to set an app on my Quest 1 as debuggable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment