How to debug apk signed for release?

120,080

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

I tried with the following and it's worked:

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

Solution 5

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'
        }
    }
Share:
120,080
Adil Hussain
Author by

Adil Hussain

Software Engineer with a focus on building Applications and SDKs for Mobile (Android, iOS).

Updated on March 18, 2021

Comments

  • Adil Hussain
    Adil Hussain over 3 years

    I have an apk which I've signed and uploaded to Android Market, and installed on my phone. I would like to debug this release apk (by means of Eclipse) whilst it is running on my phone. I have done this before (and remember it being with one of the Android development tools; perhaps Dalvik Debug Monitor) but unfortunately cannot remember how to do it and have been unable to find any articles online. Does anyone know how this can be done?

    Note: I have set android:debuggable="true" in the manifest and have enabled USB Debugging on my phone.

  • Adil Hussain
    Adil Hussain over 12 years
    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...
  • Adil Hussain
    Adil Hussain over 12 years
    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!
  • m02ph3u5
    m02ph3u5 over 8 years
    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-0
  • sandalone
    sandalone about 8 years
    @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 help
  • J D
    J D about 7 years
    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?
  • Adil Hussain
    Adil Hussain almost 7 years
    This answer has already been given in this thread by Manuel Lopera... three years ago! See here: stackoverflow.com/a/27181562/1071320
  • Shailendra Madda
    Shailendra Madda almost 7 years
    @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 changes
  • Adil Hussain
    Adil Hussain almost 7 years
    Not a big deal but his answer does contain an update to this effect. Anyway. Not a big deal. Thanks for the answer.
  • hasnain_ahmad
    hasnain_ahmad about 6 years
    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.
  • Antimonit
    Antimonit over 5 years
    This answer is way outdated. Instead of androidManifest.xml you should update build.gradle. See other answers.
  • Shashank Saxena
    Shashank Saxena almost 5 years
    @hasnain_ahmad Were you able to find a solution for this?
  • Androidcoder
    Androidcoder over 4 years
    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).
  • YoshiJaeger
    YoshiJaeger over 4 years
    I had to add lintOptions { abortOnError false } into my app/build.grade instead of using tools:ignore like so: android { lintOptions: { abortOnError false } }
  • Oliver D
    Oliver D over 4 years
    i got The prefix "tools" for attribute "tools:ignore" associated with an element type "application" is not bound. !