ProGuard – Obfuscating, Shrinking & Optimizing Android Tool

When you are developing an Android app, some of the most common questions that you come across are:

How to safeguard an Android app?

How to minimize the final Android device executable apk file size?

How to make the app run faster?

The answer to the above questions is a tool called ‘ProGuard’. This tool is used worldwide as shrinker, optimizer, and obfuscator, which is usually neglected while releasing an app in the market. This blog post focuses on digging deeper about the usage of this tool while developing an android app.

So, what do these terms (Shrinkage, Optimization & Obfuscation) means?

Obfuscation – It a process of making an app code difficult to read & the app code becomes secure so that others will not be able to reverse engineer it to get the source code back from .apk

Shrinkage – It is process of making your app executable .apk file size to almost half of its original size.

Optimization – It is process which enhances the code to make the app run faster

Let’s deep dive into each technique.

Obfuscation

When we compile bytecodes, all the debugging information like classes, fields, methods, and attributes etc. are included. This makes it very easy to decompile and reverse engineer the code. To stop this from happening, ProGuard uses the technique called Obfuscator. Here, all the debugging information will be replaced by special characters making it very difficult to read and understand and at the same time the internal functionality remains the same.

Steps to Enable ProGuard in Your App

The following are the step to enable ProGuard in your app:

Step 1: In Android Studio, open up an Android project and change it to Project View.

Step 2: Edit the app’s [Android project]/app/build.gradle file by changing the value of minifyEnable to ‘true’.

Step 3: You can set rules to ProGuard which are optional. To do that, go to Project View, select the [Android project]/app/proguard-rules.pro file. Add in the following lines of code to tell ProGuard not to obfuscate certain classes.

-keepclassmembers class com.acadgild.xxxx {
public *; }

Shrinkage

The unused resources and libraries can be removed automatically at the built-time when packaging the .apk file. To automate this process, the resource shrinking should be enabled. This can be done as shown below:

Note: These flags cannot be included in your own configuration file. If included, the optimization will be turned off. You’ll need to either edit this file or duplicate the content and remove the include of this file from your project’s ProGuard.config path property.