10

I'm using Android Studio v.1.0 My build file :

  buildTypes {

    debug {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }

    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

but when I try to make a release build, I get an error : Error:Execution failed for task ':app:proguardRelease'.

java.io.FileNotFoundException: F:....\app\proguard-rules.pro (File not found)

I think, that proguard-android.txt is a part of Android SDK, am I right ?

And why Android Studio can't find it ?

I also tried proguard-android.pro - the same result

ozbek
  • 20,955
  • 5
  • 61
  • 84
Rikki Tikki Tavi
  • 3,089
  • 5
  • 43
  • 81

6 Answers6

10

If you don't need any specific ProGuard configuration:

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt')
    }
}

(The warning might happened)

Or specify "rules" and put it here:

.../app/proguard-rules.pro

For example I use "Butter Knife" and my proguard-rules.pro looks like:

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

Or, possibly you can leave build.gradle file as it is (if you don't like warnings )), And just put an empty proguard-rules.pro to that location.

Andrew
  • 36,676
  • 11
  • 141
  • 113
4
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

Following line in build.gradle file of your app module indicates the script of proguard needs to apply to your release build. It has two files:

  1. proguard-android.txt: is the default android proguard file, can be found in D:\SDK\tools\proguard directory of SDK.
  2. 'proguard-rules.pro': It contains your application specific proguard script. You need to create this file in the root folder of your application. All your application specific proguard should be inside this file.
Sagar Trehan
  • 2,401
  • 2
  • 24
  • 32
3

I've created my own proguard-android.pro file and that works properly for me :

-dontwarn org.apache.commons.**
-dontwarn com.google.**
-dontwarn com.j256.ormlite**
-dontwarn org.apache.http**

-keepattributes SourceFile,LineNumberTable
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }

-keepattributes Signature
# GSON Library
# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

# Google Map
-keep class com.google.android.gms.maps.** { *; }
-keep interface com.google.android.gms.maps.** { *; }
Rikki Tikki Tavi
  • 3,089
  • 5
  • 43
  • 81
1

please check your 'proguard-rules.pro' inside your root project folder. I your project exported from eclipse you must create 'proguard-rules.pro' inside root project folder.

user3068659
  • 443
  • 5
  • 14
0

A workaround is to download one of the following:

http://dl.google.com/android/android-sdk_r22.6.2-linux.tgz
http://dl.google.com/android/android-sdk_r22.6.2-windows.zip
http://dl.google.com/android/android-sdk_r22.6.2-macosx.zip

And copy over the following files:

tools/hprof-conv
tools/support/annotations.jar
tools/proguard
dat3450
  • 954
  • 3
  • 13
  • 27
cici
  • 1
  • 2
0

Hope this answer may be helpful in future

GoTobuild.gradle(Module:app)

Remove this part from buildTypes

debug {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
shyam
  • 1,084
  • 12
  • 20