问题
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)
How to fix this and achieve ProGuard protection to my App ?
回答1:
Try to change into -
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
回答2:
I had the same trouble as shown 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?"
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.
回答3:
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.
回答4:
Try:
proguardFiles.add(file('proguard-android.txt'))
proguardFiles.add(file('proguard-rules.txt'))
This structure works in the gradle-experimental plugin.
回答5:
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"
}
回答6:
try this,
{
minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles 'proguard-rules.pro'
}
回答7:
In my case:
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
replace runProguard false with minifyEnabled false works.
来源:https://stackoverflow.com/questions/29527524/android-studio-proguard-cannot-resolve-symbol-getdefaultproguardfile