Site icon DataFlair

Android Proguard Tool – How to Enable Proguard in Android?

FREE Online Courses: Elevate Skills, Zero Cost. Enroll Now!

In this Android tutorial, we’ll learn about the Android Proguard tool. Let us start this tutorial without any delay.

What is Android Proguard Tool?

Android Proguard Tool is a free Java class file shrinker, optimizer, and obfuscator. Its task is to detect and eradicate the unused code. This can be either the class, method, field, or even the attributes. It also optimizes the bytecodes and removes the instructions that are not to be used.

Android proguard does the following jobs:

Why do we use Proguard?

Now that you are well aware of what are Proguard tools and what these are used for, it would be easy for you to understand why it is needed.

As Android applications are easy to reverse engineer, we use Proguard tools to restrict this from happening. And other reasons are very well clear to you that are-

What are the Advantages of Proguard in Android?

All the reasons for which we use Proguard for are definitely the Pros of Proguard tools. Nonetheless, let us consider the following advantages of Proguard-

What are the Limitations of Android Proguard?

As we know, there’s the other side of everything; there’s the other side for this too. There are some disadvantages or rather drawbacks of Proguard as well. Come, let’s see them one by one-

How can I enable Proguard in Android Studio?

Now, We’ll see how to enable Proguard Android Studio. Proguard is basically integrated into the Android Build System. And it runs only when the build of your application is in the release mode. You can choose to use Android Proguard as it is not compulsory but is highly recommended. So, to enable or disable Proguard in your application you can use the minifyEnabled property present in build.gradle file.

To enable the Proguard in your application you can do the following-

1. Firstly, go to the build.gradle file of your application.
2. You will find the minifyEnabled property as a part of the buildTypes release block. It controls the settings applied to the release builds.
3. Now, all you have to do is, Set the minifyEnabled property to True. Thus the Proguard will be enabled in your application.
4. The method named getDefaultProguardFile(‘proguard-android.txt’) is for obtaining the default Proguard settings from Android SDK tools.

You can consider the following code and find it in build.gradle(:app) file:

apply plugin: 'com.android.application'

android {
   compileSdkVersion 29
   buildToolsVersion "29.0.3"
…	
   buildTypes {
       release {
           minifyEnabled true
           proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
       }
   }
}

5. At the root of the module, Android Studio adds the Proguard-rules.pro file that helps to add the custom Proguard rules.

Summary

In conclusion, this whole article was about Android Proguard tools. In this, we have everything about Proguard right from the tip to toe. Firstly, what we read in this article is what a Proguard tool is and why we use it. Then, we saw the Pros and Cons of the Proguard tool. And finally, we saw how we could implement the Proguard tool in our application in Android Studio.

We hope you found it useful. Thank You.

Exit mobile version