0

我的 build.gradle 有 . . .

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

我能找到的每个 proguard-android.txt 文件(如 C:\Users\Gary\AppData\Local\Android\sdk\tools\proguard 中的那个)都包含以下内容:

# 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
#   http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

这似乎是胡说八道,因为我可以找到的 AS 项目中没有 project.properties 文件。我唯一能看到在我的 .apk 中被更改的是本地名称,仅此而已。我应该把我的 proguard 参数放在哪里?谢谢,院长

4

2 回答 2

0

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.

于 2015-06-16T23:05:17.430 回答
0

如您的 build.gradle 中所述,项目特定的保留选项将从您自己的 proguard 文件中获取,在本例中为 proguard-rules.txt。

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

如果该文件尚不存在,您可以将该文件添加到您的 /app 文件夹中。例如,您可以使用 proguard-rules.txt 为 Otto 添加保留选项。

# Add any project specific keep options here:

-keepattributes *Annotation*
-keepclassmembers class ** {
    @com.squareup.otto.Subscribe public *;
    @com.squareup.otto.Produce public *;
}
于 2015-06-16T23:12:59.830 回答