I am investigating an issue that is only present with minifyEnabled is set to true in Gradle.
I am using log statements to debug but the issue is apparently pretty deep. Is there anything I can do to have minifyEnabled set to true, but still be able to use the Android Studio debugger?
I know the answer is probably 'no', but I wanted to ask anyway.
In short: is it possible to run the Android Studio debugger with minifyEnabled
set to true
?
minifyEnabled true. // Enables resource shrinking, which is performed by the. // Android Gradle plugin. shrinkResources true. // Includes the default ProGuard rules files that are packaged with.
R8 is an app shrinking tool that is used to reduce the size of your application. This tool present in Android Studio works with the rules of Proguard. R8 will convert your app's code into optimized Dalvik code.
Enabling ProGuard (Gradle Builds) The minifyEnabled property is part of the buildTypes release block that controls the settings applied to release builds. Set the minifyEnabled property to true to enable ProGuard, as shown in this example. The getDefaultProguardFile('proguard-android.
– android developer. Jun 12, 2015 at 10:47. 1. minifyEnabled enables proguard which removes unused classes/code and shrinkResources removes unused resources (pngs, xmls, mostly introduced by libraries which you don't fully utilize).
It is already possible to debug minified applications.
First, edit your proguard-rules.pro
and add lines:
-dontobfuscate
-keepattributes SourceFile,LineNumberTable
Also, make sure to comment out this line:
# -renamesourcefileattribute SourceFile
Then, edit your application build.gradle
file and define your debug build type in the following way:
debug {
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
All of these changes are necessary(if you skip keepattributes
and renamesourcefileattribute
, then debugging will work, but logging will still point to wrong place in the code)
Then, run the application with debugger.
The logging will now point you exactly to the proper place in the code. Also, if there are any breakpoints set, these will be executed properly. Android Studio will allow you to investigate variables, check for conditions and evaluate the code.
Remember to remove the changes in the proguard-rules.pro
file before you build the release. You can also define debug and release settings in separate proguard files.
No ..but you should avoid using it on debug build. it will slow down your application .it is usefull when you release the APK for testing purposes but before that, Make you aware of using MinifyEnabled. follow this link. it is used for enable the code shrinking.(Unused codes will be shrinked).
See official documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With