iBotPeaches / Apktool

A tool for reverse engineering Android apk files
https://apktool.org/
Apache License 2.0
20.29k stars 3.59k forks source link

[BUG] Unable to add debuggable flag to APK #2758

Closed Maryannah closed 2 years ago

Maryannah commented 2 years ago

Information

I am trying to add the debuggable flag to an APK so that I can remotely debug it (it is a Cordova application). I tried all possible flag combinations as well as aapt binaries and I can't seem to be able to make it work.

Just decoding and encoding back the APK works fine, but the debuggable flag is not added.

I found similar issues online and tried them (notably, downgrading the apktool version), but none seem to work.

Please bear in mind that I am just a JS developper, this is way out of my league, so if you explain something to me, please do it like I'm 5 years old 😅

  1. Apktool Version (apktool -version) - 2.6.0
  2. Operating System (Mac, Linux, Windows) - Ubuntu WSL on Windows 11
  3. APK From? (Playstore, ROM, Other) - Playstore

Stacktrace/Logcat

I: Using Apktool 2.6.0
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes2 folder into classes2.dex...
I: Checking whether resources has changed...
I: Building resources...
W: res/drawable/$avd_hide_password__0.xml: Invalid file name: must contain only [a-z0-9_.]
W: res/drawable/$avd_hide_password__1.xml: Invalid file name: must contain only [a-z0-9_.]
W: res/drawable/$avd_hide_password__2.xml: Invalid file name: must contain only [a-z0-9_.]
W: res/drawable/$avd_show_password__0.xml: Invalid file name: must contain only [a-z0-9_.]
W: res/drawable/$avd_show_password__1.xml: Invalid file name: must contain only [a-z0-9_.]
W: res/drawable/$avd_show_password__2.xml: Invalid file name: must contain only [a-z0-9_.]
W: res/drawable-v24/$ic_launcher_foreground__0.xml: Invalid file name: must contain only [a-z0-9_.]
brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [android/static/sdktools/build-tools/32.0.0/aapt, p, --debug-mode, --min-sdk-version, 22, --target-sdk-version, 30, --version-code, 3002004, --version-name, 3.2.4, --no-version-vectors, -F, /tmp/APKTOOL5331482337174541048.tmp, -0, resources.arsc, -0, META-INF/androidx.activity_activity.version, -0, META-INF/androidx.annotation_annotation-experimental.version, -0, META-INF/androidx.appcompat_appcompat-resources.version, -0, META-INF/androidx.appcompat_appcompat.version, -0, META-INF/androidx.arch.core_core-runtime.version, -0, META-INF/androidx.asynclayoutinflater_asynclayoutinflater.version, -0, META-INF/androidx.cardview_cardview.version, -0, META-INF/androidx.coordinatorlayout_coordinatorlayout.version, -0, META-INF/androidx.core_core.version, -0, META-INF/androidx.cursoradapter_cursoradapter.version, -0, META-INF/androidx.customview_customview.version, -0, META-INF/androidx.documentfile_documentfile.version, -0, META-INF/androidx.drawerlayout_drawerlayout.version, -0, META-INF/androidx.fragment_fragment.version, -0, META-INF/androidx.interpolator_interpolator.version, -0, META-INF/androidx.legacy_legacy-support-core-ui.version, -0, META-INF/androidx.legacy_legacy-support-core-utils.version, -0, META-INF/androidx.legacy_legacy-support-v4.version, -0, META-INF/androidx.lifecycle_lifecycle-livedata-core.version, -0, META-INF/androidx.lifecycle_lifecycle-livedata.version, -0, META-INF/androidx.lifecycle_lifecycle-runtime.version, -0, META-INF/androidx.lifecycle_lifecycle-service.version, -0, META-INF/androidx.lifecycle_lifecycle-viewmodel.version, -0, META-INF/androidx.loader_loader.version, -0, META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version, -0, META-INF/androidx.media_media.version, -0, META-INF/androidx.print_print.version, -0, META-INF/androidx.recyclerview_recyclerview.version, -0, META-INF/androidx.room_room-runtime.version, -0, META-INF/androidx.savedstate_savedstate.version, -0, META-INF/androidx.slidingpanelayout_slidingpanelayout.version, -0, META-INF/androidx.sqlite_sqlite-framework.version, -0, META-INF/androidx.sqlite_sqlite.version, -0, META-INF/androidx.startup_startup-runtime.version, -0, META-INF/androidx.swiperefreshlayout_swiperefreshlayout.version, -0, META-INF/androidx.tracing_tracing.version, -0, META-INF/androidx.transition_transition.version, -0, META-INF/androidx.vectordrawable_vectordrawable-animated.version, -0, META-INF/androidx.vectordrawable_vectordrawable.version, -0, META-INF/androidx.versionedparcelable_versionedparcelable.version, -0, META-INF/androidx.viewpager2_viewpager2.version, -0, META-INF/androidx.viewpager_viewpager.version, -0, META-INF/androidx.work_work-runtime.version, -0, META-INF/com.google.android.material_material.version, -0, png, -0, arsc, -I, /home/max/.local/share/apktool/framework/1.apk, -S, /home/max/projects/dt-plus/builds/decoded/res, -M, /home/max/projects/dt-plus/builds/decoded/AndroidManifest.xml]

Steps to Reproduce

java -jar apktool.jar d game.apk -o decoded
java -jar apktool.jar b decoded -o encoded.apk -a path/to/aapt -d

APK

If this APK can be freely shared, please upload/attach a link to it. (Rename to .apk, github wouldn't let me send an APK file) game.zip

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything ?

Yes, and it works, the app can be installed after signing it

  1. If you are trying to install a modified apk, did you resign it?

Yes I did

  1. Are you using the latest apktool version?

Guess so, took the latest one in https://bitbucket.org/iBotPeaches/apktool/downloads/

pashamcr commented 2 years ago

use aapt2

Maryannah commented 2 years ago

use aapt2

Tried to, both by using the aapt2 bin

java -jar apktool.jar b decoded -o encoded.apk -a path/to/aapt2 -d

Using the flag for it

java -jar apktool.jar b decoded -o encoded.apk -a path/to/aapt -d --use-aapt2

Combining both

java -jar apktool.jar b decoded -o encoded.apk -a path/to/aapt2 -d --use-aapt2

And not providing the path to aapt to let apktool handle it

java -jar apktool.jar b decoded -o encoded.apk -d --use-aapt2
Maryannah commented 2 years ago

Well after many tries I don't know why but this time it worked.

I used zipalign like I did before, but instead of transferring my APK to my phone to install it, I used remote ADB to install it directly, and it seems to have worked.

So you can forget about it 😅

Thank you for the amazing tool nontheless !