How to debug the Android App in release mode using Android studio

Solution 1:

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'
    }
} 

Solution 2:

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.

Solution 3:

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

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

Solution 4:

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'

Solution 5:

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).