Optimize without obfuscate your debug build

Elye
Elye
Mar 9, 2017 · 2 min read

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.

The way!

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.

android {
buildTypes {
debug {
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile
('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile
('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

I hope you appreciate this post and it’s helpful for you.

You could check out my other interesting topics here.

Follow me on medium, Twitter or Facebook for little tips and learning on Android, Kotlin etc related topics. ~Elye~

Mobile App Development Publication

Sharing Mobile App Development and Learning

Elye

Written by

Elye

Passionate about learning, and sharing mobile development and others https://twitter.com/elye_project https://www.facebook.com/elye.proj

Mobile App Development Publication

Sharing iOS, Android and relevant Mobile App Development Technology and Learning

Elye

Written by

Elye

Passionate about learning, and sharing mobile development and others https://twitter.com/elye_project https://www.facebook.com/elye.proj

Mobile App Development Publication

Sharing iOS, Android and relevant Mobile App Development Technology and Learning

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store