Amelia@Amazon avatar image
Amelia@Amazon posted

How to use proguard within your Android apps with new Android Dev Tools


As Android developers look for ways to protect their property, and be able to avoid the 65,000 method limit issues that are normally associated with the Dalvik Runtime, ProGuard is a

great first line of defense for both of these. However, by default it is not enabled in Android Studio as of version 1.0 of their Gradle plugin, nor are the configuration files setup by default.


To configure ProGuard, you will need to configure the minification options within your project's build.gradle file. (please see example below)

As of Android Studio 1.1, ProGuard configuration files are no longer applied to the test APK. If ProGuard is enabled, it is only to generate the mapping file that will be used when running your ProGuard rules on the release APK.

For more information on how ProGuard works with the Android Gradle Plugin, please look at Google's documentation for their Gradle Plugin.

If you are still using a non-production version of Android studio, one thing to note is when you do migrate to version 1.0, the ProGuard enablement is handled differently. For more details on that, please refer to the Android documentation for migrating to Android Studio 1.0 and above:

For information on what options you should use in a ProGuard configuration for general cases with Android, refer to the ProGuard manual,

Also, of note, you may want to look into resource shrinking to help reduce the size of your APK at release as well, in the Android plugin for Gradle, this requires ProGuard to be enabled first, and google has that documented at:

Sample Code

 // build.gradle file 
android {
        buildTypes {
            release {
                minifyEnabled true // set to true or false to enable or disable Proguard
                proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

Keywords: Proguard, Security, Android Studio[/b]


10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.



brizzlebrazzle contributed to this article