If your Release build has less than 65K method, while your debug build now complaining exceed Dex limit, what to do?
Enable Multidex for your build? That’s one way, but not ‘the way’. Let me share with you a better way.
Optimize without obfuscate
We all know the reason debug build is over 65k dex limit is because of many unused methods are included, especially from external libraries, while Release build, we have Proguard to remove them cleanly.
The simple thought is, let’s proguard the debug build. Unfortunately, if you use Proguard on debug build, the code got obfuscated as well, causing debugging a challenge (e.g. you can’t trace the variable value in the debugger).
The good news is, Proguard has the setting
-dontobfuscate that you could set in your proguard-rules.pro file. Using that you will get your code optimized but not obfuscated.
This works perfectly. BUT … the problem though is, you still want to obfuscate your release build. So you’ll need to have two different set of proguard-rules.pro for your build, i.e one for release, the other for your debug. Well… clearly this is not ‘the way’ you prefer.
How nice if you can share one proguard-rules.pro file, with setting to turn on-off obfuscation for Release and Debug easily.
So the way is actually very simple, yet seemingly not many people aware. Turn on minifyEnabled but turn off proguard. It could be set in your debug buildType section of your
build.gradle file as shown below.
To get more hint and tips of optimization, refers to