47

For some reason I have to run my Android App in release mode.I have to run through the code when running the app just like we use in debug mode. My break points are not hitting when I run in release mode, I have added android:debuggable="true" in manifest. Still the breakpoint is not hitting. Any help.

Thanks in Advance

Bazi Paleri
  • 803
  • 1
  • 6
  • 15

7 Answers7

55

In your gradle file, you must add debuggable ability in your release flavor.

buildTypes {
    release {
        debuggable true
        minifyEnabled false
        signingConfig signingConfigs.release
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
    debug {
        debuggable true
        minifyEnabled false
        applicationIdSuffix '.debug'
    } 
}

signingConfig is release configuration it must be added in gradle file in android{} block, something like this:

signingConfigs {
    release {
        keyAlias 'YourAppKey'
        keyPassword 'somePassword'
        storeFile file('appkeyfile.jks')
        storePassword 'somePassword'
    }
} 
Sufian
  • 6,405
  • 16
  • 66
  • 120
once2go
  • 1,452
  • 1
  • 13
  • 21
  • I have added this in my build gradle. But I don't have a signingConfigs.release file. my signingConfig is signingConfigs.config. How can I generate one for release ?? – Bazi Paleri Nov 19 '15 at 11:41
  • 1
    I have added this all and Still my breakpoint is not hitting. Is there anything else that remove the breakpoint in the code?? – Bazi Paleri Nov 19 '15 at 12:04
  • what do you means remove? Write code line please at your breakpoint – once2go Nov 19 '15 at 12:06
  • 2
    You can add `release { signingConfig signingConfigs.debug }` to sign the release build with your debug certificate. – Mr-IDE Jun 01 '18 at 15:28
13

In my case, I have created the debug configuration same as previous release build and started debugging. It means you have to give sign build in debug version also in build gradle.

signingConfigs {
    config {
        keyAlias 'abc'
        keyPassword 'xyz'
        storeFile file('<<KEYSTORE-PATH>>.keystore')
        storePassword 'password'
    }
}
buildTypes {
  debug {
      debuggable true
      signingConfig signingConfigs.config
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

So It will have the same sign as release build and you can debug when it runs.

Bazi Paleri
  • 803
  • 1
  • 6
  • 15
2
 buildTypes {
    release {
    debuggable true
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

happy coding.Mark this answer up..if it helps.. :)

Harry Sharma
  • 2,190
  • 2
  • 15
  • 41
2

There's no "release mode". What you refer to is the build type which means steps taken during building (like minifying etc). Setting android:debuggable="true" will not automagically help, because when you "Run" the app instead of "Debug" you do not connect debugger to it so it will not stop for that particular reason.

So you can

set up your Debug build to be produced the same way Release is

But is quite unclear what is the reasoning behind your need and I got a feeling you are trying to go the wrong way (i.e. debug is usually not using ProGuard, while release build is and ProGuard changes the resulting binary so your breakpoints from source will not really work anyway).

Dan Alboteanu
  • 9,404
  • 1
  • 52
  • 40
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • 2
    I have a need to debug an issue that only affects release builds, which suggests that it is a bug created by shrinked/obfuscated/optimized code. The issue is not observed on debug variants – kip2 Nov 01 '19 at 08:25
1

I think Marcin's argument above makes sense (much as there are situations that require debugging release builds), so here is a slight variation of the accepted answers that worked for me:

android {
    ...
    buildTypes {
        release {
            shrinkResources false # this was key
            minifyEnabled false # seems that it can't be set to true if shrinkResources is false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }
}

Adapted from the official docs

NOTE:

When I set minifyEnabled true, the following crash occurred on app launch:

java.lang.RuntimeException: Unable to instantiate application co.mycompany.app.MyApp: java.lang.ClassNotFoundException: Didn't find class "co.mycompany.app.MyApp" on path: DexPathList...
kip2
  • 6,473
  • 4
  • 55
  • 72
  • With @once2go answer combined with yours, I could debug while deploying a `release` version of my app. – Ícaro Sep 18 '20 at 13:12
  • @kip2 Does this work if I want to upload the tab to Google console in the Internal test track. I keep getting "app is not signed" error. – msc87 Nov 23 '21 at 10:10
  • @msc87 I'm not too sure about the impact on app signing, but the answers on this question might give you an insight: https://stackoverflow.com/q/39628648/1145905 (it might be a bug with the resource shrinker that *both* the `minifyEnabled` and `shrinkResources` flags *need to have the same value*) – kip2 Nov 24 '21 at 10:31
1

Few pennys for the new comers.

If even After adding debuggable true in release block, your debug points are not hit.

Remove the following code from the release block.

    minifyEnabled true 
    shrinkResources true //remove resources
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Usman Zafer
  • 1,261
  • 1
  • 10
  • 15
  • 2
    If we remove those lines whats the point release as code will not obfuscate. there will be not diff b/w release and debug except signing. – Kathi Jun 07 '22 at 11:20
0

In 2022, or at least in MY case

I tried many solutions but didnt work finally solution was to create a new siginig key and use it with all build types &variants.

Steps

1 - Go to AndroidStudio top menu select Build>Generate Signed Bundle /APK > (choose APK )

*for the first time create a new key (you know how to create one? or read docs )

BUT NOTE while you are creating key choose build type debug then continue

2 - Again Go to AndroidStudio top menu select Build > Generate Signed Bundle /APK > (choose APK) BUT this time choose existing key ( the one we made in previouse step)

in previouse step we chose build type debug this time choose release and continue..

3 - Repeat steps 1 & 2, with AAB (release & debug)

this is basically making sure all build types are being signed using same configs.

NOTE

maybe you need to add below code to app build.gradle

android {

    ...

    signingConfigs { <-- Add this
        config {
            storeFile file('PATH_TO_KEY.jks')
            storePassword 'YOUR PASSWORD'
            keyAlias 'YOUR KEY ALIAS'
            keyPassword 'YOUR PASSWORD'
        }
    }

   ... 


   buildTypes {

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

            signingConfig signingConfigs.config <-- this
        }

        debug {
            signingConfig signingConfigs.config <-- this
        }
    }

}
abdullah
  • 157
  • 2
  • 8