ProGuard Tips
When implementing ProGuard for your Android App you might find these little tips helpful during implementation.
#1 Debug build
It’s common that debug build type doesn’t run ProGuard because it will slow down compilation and therefor development. But in order to fully test and debug any ProGuard problems, it’s handy to setup a separate build type dedicated to run ProGuard on a debug build.
buildTypes { debugMini { initWith debug minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' matchingFallbacks = ['debug'] } }
Now you could run test like monkey tests or UI tests to find possible problems on a build that’s close to your release build as possible.
#2 Debugging
ProGuard will by default remove many code attributes and hidden metadata that are not required for program execution. Some of those are actually useful to the developer — for example, you might want to retain source file names and line numbers for stack traces to make debugging easier:
-keepattributes SourceFile, LineNumberTable
If you are going to attach a debugger to step through method code in a ProGuarded build of your app, you should also keep the following attributes to retain some debug information about local variables:
-keepattributes LocalVariableTable, LocalVariableTypeTable
#3 Lookup
If you copy/paste a line of code and you are not sure what it does. It will save time to look it up instead of try and error all the time. Trust me I’ve been there, especially with ProGuard.
ProGuard manual:
https://www.guardsquare.com/en/products/proguard/manual/usage
Developer android:
https://developer.android.com/studio/build/shrink-code