Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android debugging with minifyEnabled true

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?

like image 295
Marc DiNino Avatar asked Aug 10 '15 18:08

Marc DiNino


People also ask

What is minifyEnabled 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.

What is R8 in Android?

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.

How do I enable ProGuard in debug mode?

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.

What is shrinkResources?

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


2 Answers

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.

like image 136
Krzysztof Sroga Avatar answered Oct 08 '22 03:10

Krzysztof Sroga


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.

like image 4
Noorul Avatar answered Oct 08 '22 03:10

Noorul