Maheshwar Ligade
techwasti
Published in
2 min readFeb 5, 2017

--

Enabling proguard for Android.

For more stories.

How to de-obfuscate stack Trace is here?

Enabling proguard in an android studio is a really easy task but I really encounter question seamlessly and I am getting this question frequently on StackOverflow, this motivates me to write this simple article.

How to Enabling ProGuard obfuscation in Android Studio?

Question is here on stackoverflow. I have already provided my answer here but now I want to explore a little bit what is proguard? and How to enable it?

What is this proguard…..?

Ref — Wikipedia.

ProGuard is an open source command-line tool that shrinks, optimizes and obfuscates Java code. It is able to optimize bytecode as well as detect and remove unused instructions. ProGuard is open source software.

Proguard was developed by Eric P.F. Lafortune.

As per the definition proguard will help you to not only obfuscation but also it optimizes, shrinks and remove unused instructions as well.

I asked many developers, why you want to apply proguard to your project, and I come across to only one answer, we used only for security purpose. Proguard is not only providing security to your code but also it provides many more features. Let us understand what is proguard and how to use it?

Features of Proguard.

  1. ProGuard also optimizes the bytecode, removes unused code instructions, and obfuscates the remaining classes, fields, and methods with short names.
  2. The obfuscated code makes your APK difficult to reverse engineer, which is especially valuable when your app uses security-sensitive features, such as licensing verification.

We will look more here How to enable it in the android studio instead of exploring how proguard works?

To enable ProGuard in Android Studio.

Below is the sample of how to enable default ProGuard in Android Studio.

  1. Go to the build.gradlefile of the app
  2. enables the proguard minifyEnabledtrue
  3. enable shrinkResources true to reduce the APK size by shrinking resources.
  4. proguardFiles getDefaultProguardFile('proguard-android.txt') to enable the default one. If you want to use your own proguard file then use the below rules.
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

The link contains ProGuard settings for Android and other library settings also:

This is simple to try to say about enabling proguard in an android studio.

I have been following this path, love to hear from you.

Youtube Channel :- https://www.youtube.com/channel/UCiTaHm1AYqMS4F4L9zyO7qA

Let's connect on Stackoverflow, LinkedIn, Facebook& Twitter.

--

--

Maheshwar Ligade
techwasti

Learner, Full Stack Developer, blogger, amateur #ML,#DL,#AI dev in the quantum moment. I run https://techwasti.com/ to post all my articles.