How do I debug an APK that is signed for release?
Asked Answered
C

7

148

I have a release APK which I have signed, uploaded to Google Play and installed on my Android device. I would like to debug this APK (by means of Android Studio or Eclipse) whilst it is running on my Android device. I have done this before and I remember it being with one of the Android development tools (perhaps Dalvik Debug Monitor). Sadly, I cannot remember how to do it and I have been unable to find any articles online. Does anybody know how I can do this?

Notes

  1. I have set android:debuggable="true" in the app's manifest file.
  2. I have enabled USB Debugging on my Android device.
Cranwell answered 31/1, 2012 at 15:11 Comment(4)
what are you currently trying? Do you not know how to use the Devices View in Eclipse?Replica
I now have the Devices view showing in Eclipse. I can see my device in the Devices list. I click on it but the "Debug the selected process" button is disabled despite the application running on the phone and the source project being present and opened in the workspace. Any ideas?!Cranwell
Are you clicking on the package name for your app?Replica
Yes. See comment in your answer. (Thanks for the help btw. Appreciate it.)Cranwell
R
89

Be sure that android:debuggable="true" is set in the application tag of your manifest file, and then:

  1. Plug your phone into your computer and enable USB debugging on the phone
  2. Open eclipse and a workspace containing the code for your app
  3. In Eclipse, go to Window->Show View->Devices
  4. Look at the Devices view which should now be visible, you should see your device listed
  5. If your device isn't listed, you'll have to track down the ADB drivers for your phone before continuing
  6. If you want to step through code, set a breakpoint somewhere in your app
  7. Open the app on your phone
  8. In the Devices view, expand the entry for your phone if it isn't already expanded, and look for your app's package name.
  9. Click on the package name, and in the top right of the Devices view you should see a green bug along with a number of other small buttons. Click the green bug.
  10. You should now be attached/debugging your app.
Replica answered 31/1, 2012 at 15:42 Comment(5)
I get up to step 8 but for some reason my app's package name doesn't show when I'm running the signed/release apk. (Strangely it does show when I run the app (debug apk) on my phone straight from Eclipse.) Confused...Cranwell
Got it! I had put the android:debuggable="true" attribute in the manifest tag instead of the application tag within manifest!! My bad :( Thanks Sam_D ever so much for your guidance. Wouldn't have done it without you, or at best would have taken a heck of a long time!Cranwell
When I add the debuggable keyword in build.gradle and want to publish in play store it shows this error You uploaded a debuggable APK. For security reasons you need to disable debugging before it can be published in Google Play. Macias
This answer is way outdated. Instead of androidManifest.xml you should update build.gradle. See other answers.Alabaster
@Macias Were you able to find a solution for this?Franny
M
173

I know this is old question, but future references. In Android Studio with Gradle:

buildTypes {
    release {
        debuggable true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

The line debuggable true was the trick for me.

Before Gradle 1.0 it was runProguard instead of minifyEnabled. Look at here.

Morganstein answered 28/11, 2014 at 3:43 Comment(3)
Note that as of gradle 1.0 it's minifyEnabled instead of runProguard - see tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0Eunuchoidism
As a note to this current answer, I myself would avoid sending a debuggable release to the Google Play store, and it may not let you as in hasnain_ahmad's case in previous outdated answer. Just doing it temporarily to test a release-downloaded-from-store issue, like inapp purchase code tracking, would be less risky. You could also try working with the beta track (I don't know if this may give the same error as hasnian got) or transferring the release build apk to your phone from your computer to avoid the security issues (dealing with the bundle is messier).Varistor
That doesn' t look to work anymore (when debuggable is set to true, the release is not signed). https://mcmap.net/q/36023/-uploading-android-app-bundle-to-google-play-console-key-signing-errorVirgina
R
89

Be sure that android:debuggable="true" is set in the application tag of your manifest file, and then:

  1. Plug your phone into your computer and enable USB debugging on the phone
  2. Open eclipse and a workspace containing the code for your app
  3. In Eclipse, go to Window->Show View->Devices
  4. Look at the Devices view which should now be visible, you should see your device listed
  5. If your device isn't listed, you'll have to track down the ADB drivers for your phone before continuing
  6. If you want to step through code, set a breakpoint somewhere in your app
  7. Open the app on your phone
  8. In the Devices view, expand the entry for your phone if it isn't already expanded, and look for your app's package name.
  9. Click on the package name, and in the top right of the Devices view you should see a green bug along with a number of other small buttons. Click the green bug.
  10. You should now be attached/debugging your app.
Replica answered 31/1, 2012 at 15:42 Comment(5)
I get up to step 8 but for some reason my app's package name doesn't show when I'm running the signed/release apk. (Strangely it does show when I run the app (debug apk) on my phone straight from Eclipse.) Confused...Cranwell
Got it! I had put the android:debuggable="true" attribute in the manifest tag instead of the application tag within manifest!! My bad :( Thanks Sam_D ever so much for your guidance. Wouldn't have done it without you, or at best would have taken a heck of a long time!Cranwell
When I add the debuggable keyword in build.gradle and want to publish in play store it shows this error You uploaded a debuggable APK. For security reasons you need to disable debugging before it can be published in Google Play. Macias
This answer is way outdated. Instead of androidManifest.xml you should update build.gradle. See other answers.Alabaster
@Macias Were you able to find a solution for this?Franny
S
44

Besides Manuel's way, you can still use the Manifest.

In Android Studio stable, you have to add the following 2 lines to application in the AndroidManifest file:

    android:debuggable="true"
    tools:ignore="HardcodedDebugMode"

The first one will enable debugging of signed APK, and the second one will prevent compile-time error.

After this, you can attach to the process via "Attach debugger to Android process" button.

Shred answered 27/1, 2015 at 20:37 Comment(4)
@jaibatrik it has to be your apk and you have to attach the debugger from the sources. if you are doing both and it still does not work, share more info and I may try to helpShred
I got "[Fatal Error] :7:203: The prefix "tools" for attribute "tools:ignore" associated with an element type "application" is not bound." Is tools:ignore="HardcodedDebugMode" a legit config here?Chiaroscuro
I had to add lintOptions { abortOnError false } into my app/build.grade instead of using tools:ignore like so: android { lintOptions: { abortOnError false } }Zoogloea
i got The prefix "tools" for attribute "tools:ignore" associated with an element type "application" is not bound. !Deflective
E
13

I tried with the following and it's worked:

release {
            debuggable true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
Exceedingly answered 12/9, 2017 at 7:10 Comment(3)
This answer has already been given in this thread by Manuel Lopera... three years ago! See here: https://mcmap.net/q/157723/-how-do-i-debug-an-apk-that-is-signed-for-releaseCranwell
@AdilHussain But I tried that answer it's not worked for me. See there is a difference in my answer at ` minifyEnabled false` and it is runProguard true in his case. Please see the changesExceedingly
Not a big deal but his answer does contain an update to this effect. Anyway. Not a big deal. Thanks for the answer.Cranwell
M
13

In case of you decided the debug your apk which is already in market but not assigned to be debuggable and you do not want to publish it again. So follow the below steps;

  1. Decompile the Apk with ApkTool(eg. apktool d <APK_PATH>)
  2. Open the AndroidManifest.xml from decompiled files
  3. Set android:debuggable="true" in application tag
  4. Compile the modified source with ApkTool (eg. apktool b <MODIFIED_PATH>)
  5. Debuggable apk ready(which unsigned means cannot publish store). You can debug as you wish.
Mullite answered 5/8, 2019 at 6:20 Comment(0)
R
11

Add the following to your app build.gradle and select the specified release build variant and run

signingConfigs {
        config {
            keyAlias 'keyalias'
            keyPassword 'keypwd'
            storeFile file('<<KEYSTORE-PATH>>.keystore')
            storePassword 'pwd'
        }
    }
    buildTypes {
      release {
          debuggable true
          signingConfig signingConfigs.config
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
Reckford answered 16/11, 2018 at 6:57 Comment(0)
N
2

enter image description here

Add debuggable true in release in buildTypes and turn on 'release' in botton left Build Variants on Android studio Source: https://mobikul.com/release-variant-of-app-enable-logcat-running-release-build-application/ It work me! Can you try it

Nucleoplasm answered 9/6, 2022 at 7:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.