Using proguard with Android Studio


My build.gradle has . . .

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

Every proguard-android.txt file I can find (like the one at C:\Users\Gary\AppData\Local\Android\sdk\tools\proguard) has the following in it:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /tools/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
# For more details, see

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;

This seems to be nonsense because there is no file in AS projects that I can find. The only thing that I can see being changed in my .apk is local names and nothing else. Where do I put my proguard parms? thanks, Dean

You should put the proguard-rules.txt under app/ (i.e. the same level as app/build.gradle). The text at the top of the default proguard files is a comment (see that the first character in each line is #). You can add your custom rules below the comment, or delete the comment all together.

As stated in the commented text in the top of default proguard files, you can find more documentation here.

As stated in your build.gradle, project specific keep options will be taken from your own proguard file and in this case it is proguard-rules.txt.

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

You can add that file in you /app folder if it is not yet there. For example you can use the proguard-rules.txt to add keep options for Otto.

# Add any project specific keep options here:

-keepattributes *Annotation*
-keepclassmembers class ** {
    @com.squareup.otto.Subscribe public *;
    @com.squareup.otto.Produce public *;

This video can help you solving your question :)
By: admin