28

IDE: Android Studio 1.1.0

Subject: ProGuard

Problem: ProGuard files or tools not recognized by Android Studio, getDefaultProguardFile can not be resolved and there's no proguard-android.txt and proguard-rules.txt files in the app, see the image below: (from build.gradle)

build.gradle screenshot

How to fix this and achieve ProGuard protection to my App ?

Fadi Obaji
  • 1,454
  • 4
  • 27
  • 57
  • Hi. It seems like the default filename generated by Android Studio is proguard-rules.pro. The one showing in your gradle file is proguard-rules.txt. It could just be the filename. – Christian Abella Apr 09 '15 at 00:44
  • Try rebuilding your project, then sync the project with the gradle files. – Mounir Elfassi Apr 09 '15 at 09:39
  • 1
    i did, still the same – Fadi Obaji Apr 09 '15 at 09:49
  • I'm using Android Studio 1.5.1. In my case works like a charm. Please could you post your *dependencies {...}*? – Susanna Martinelli Feb 18 '16 at 15:50
  • Cutting and pasting the code from and back to the same location eliminated the error warning for me. I had same issue/fix for 'signingConfigs'. It never prevented me from compiling, so maybe it was a false positive, at least in my case. – Androidcoder Jul 26 '16 at 15:14

7 Answers7

8

I had the same trouble as shown here:

enter image description here

The error message makes it seem as if the file is not being found, and therefore not read. However, I went to into sdk/tools/proguard folder to find the file, and at the top added a statement to test if the file was actually being read. I put at the top "Will this crash it?"

enter image description here

As you can see from the error, the file was indeed found during the build process and the statement I added crashed it. Thus, it appears the "can't resolve symbol" error is giving a false positive.

NameSpace
  • 10,009
  • 3
  • 39
  • 40
7

Try to change into -

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Amit K. Saha
  • 5,871
  • 2
  • 27
  • 35
4

I really had the same issue. So here is what made my project working:

release {
    minifyEnabled true
    proguardFile 'proguard-rules.pro'
}

Tested by this code:

 Log.d(TAG, "TEST!");
 Log.i(TAG, "INFO!");
 Log.e(TAG, "ERROR!");

In proguard.pro I placed this snippet (which removes all Log.d-Statements in the byte-code)

-assumenosideeffects class android.util.Log {
    public static int d(...);
}

And the cat says:

MainAct﹕ INFO!
MainAct﹕ ERROR!

-> exactly what I tried to achieve :)

PS: This assumes that you have the proguard.pro file in the module (aka 'app') folder.

Martin Pfeffer
  • 12,471
  • 9
  • 59
  • 68
  • Actually when i made a `signed apk` everything worked fine and i de-compiled the file to see if `proguard` worked and it did work, i don't know why `android studio` says `can not resolve symbol` – Fadi Obaji Apr 20 '15 at 12:52
  • Ohh, nice. In my situation (hiding the Logs), AS will only run the proguard config if I set the file as I wrote it above. – Martin Pfeffer Apr 20 '15 at 12:55
  • i think `proguard` removes all `logs` from your apps without telling it to do so, it's in the `proguard` description – Fadi Obaji Apr 20 '15 at 12:57
  • this shouldn't be the default-behavior.. (AFAIK)^^ – Martin Pfeffer Apr 20 '15 at 13:01
  • What about the other methods something like `options.compilerArgs` ? also i have `cannot resolve symbol options` – Ibrahim Disouki Nov 02 '15 at 06:59
1

Try:

proguardFiles.add(file('proguard-android.txt')) proguardFiles.add(file('proguard-rules.txt'))

This structure works in the gradle-experimental plugin.

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
0

I fixed the issue of Android Studio not recognising the method by using double quotes instead of the single. The below is what I ended up using:

    release{
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile("proguard-android.txt"),
                "proguard-rules.pro"
    }
Marvin
  • 44
  • 2
-1

try this,

{
  minifyEnabled false
  // proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
  proguardFiles 'proguard-rules.pro'
}
V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
Suman Dev
  • 1
  • 1
-7

In my case:

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

replace runProguard false with minifyEnabled false works.

Omama
  • 147
  • 1
  • 2
  • 9