Proguard 在 Android 工具的 25.1.6 版本中失败

Proguard failing with 25.1.6 release of Android tools

我今天下载了 Android 工具的 25.1.6 版本,我注意到 proguard 因以下错误而崩溃:

Error:Execution failed for task ':app:transformClassesWithNewClassShrinkerForDebug'.
> /usr/local/opt/android-sdk/tools/proguard/proguard-android.txt line 43:15 extraneous input '[]' expecting ')'

我确定我没有更改 proguard-android.txt 文件中的任何内容。第 43 行对我来说如下:

void set*(%[]);

我注意到这里的文件...

https://android.googlesource.com/platform/sdk/+/android-6.0.1_r43/files/proguard-android.txt

... 与我机器上的不同吗?该文件是我应该拥有的文件的最新版本吗?

嗯,Android SDK 管理器未更新 Android SDK 本地副本中的 tools/proguard 文件夹。我刚刚从这里重新下载了 Android SDK...

http://developer.android.com/sdk/index.html

... 并将该分发版中的 tools/proguard 文件夹替换为我本地 Android SDK 副本中的 tools/proguard,错误消失了。

如果 tools/proguard 文件夹是通过 Android SDK 管理器更新的,那就太好了。

似乎我们中的一些人正在发生这种情况。我只下载了这个答案中附带的文件夹并将其复制到 android-sdk/tools 文件夹覆盖那里的内容,现在它可以正常工作了。

https://code.google.com/p/android/issues/detail?id=210012

只知道几个选项:

对我有帮助的是将相应的 proguard-android.txt 文件替换为 this 页面

中的文件

为了以防页面消失,请在此处保存其内容:

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
    public static <fields>;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

在调试模式下,我将 minifyEnabled 设置为 false