Monday, January 5, 2015

Enabling ProGuard obfuscation in Android Studio

In Android Studio, it is possible to use ProGuard to minify and obfuscate the Java source code from decompilation. The settings are different from the Eclipse ADT as Android Studio uses the Gradle build system. But still as straightforward provide you know where and what to change. At the minimum, you only need to enable ProGuard but sometimes it may be necessary to define classes that you do not want ProGuard to obfuscate - this can be done in a ProGuard rules file. The following steps illustrate these two tasks.

Enable ProGuard

  1.  In Android Studio, open up an Android project.
  2. Change to Project View.


  3. Edit the app's build.gradle file.

    Note: make sure the correct build.gradle file is edited. Typically, it is [Android project]/app/build.gradle.
  4. Change the following line:

    minifyEnable false

    to

    minifyEnable true
Set ProGuard Rules(optional)
  1. In Project View, select the proguard-rules.pro file.

    Note: Typically it is [Android project]/app/proguard-rules.pro.


  2. Add in the following lines to tell ProGuard not to obfuscate certain classes. 

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


Now when a release build is generated using Android Studio, the app will be obfuscated. 

1 comment:

Самаджон Усмонов said...
This comment has been removed by the author.
Related Posts with Thumbnails