【问题标题】:Proguard failing with 25.1.6 release of Android toolsProguard 在 25.1.6 版本的 Android 工具中失败
【发布时间】:2016-05-13 14:33:43
【问题描述】:

我今天下载了 25.1.6 版本的 Android 工具,我注意到 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 proguard android-sdk-tools


    【解决方案1】:

    只知道几个选项:

    帮助我的事情是将相应的 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.**
    

    【讨论】:

    • 在哪里可以找到“对应的proguard-android.txt文件”?
    • 我在~/Android/Sdk/tools/proguard/proguard-android.txt 找到了我的。如果这对您不起作用,请尝试find /path/to/android/sdk | grep 'proguard-android.txt'
    【解决方案2】:

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

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

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

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 嗨@Eylen,请在此线程中查看我的答案。我发现的根本问题是tools/proguard 文件夹没有作为Android SDK Manager 窗口中Android 工具更新的一部分进行更新。您可能最好从新下载的 Android SDK 中获取tools/proguard 文件夹,而不是答案中的链接,因为后者可能不会更新,并且会随着时间的推移而过时。
      • 是的,你可能是对的。但我希望在以后的更新中文件夹会正确更新
      【解决方案4】:

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

      【讨论】:

      • 当你进行发布构建时你会遇到这个问题......除非你的&lt;Android SDK&gt;/tools/proguard文件夹中的文件是最新的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      • 1970-01-01
      • 2013-03-17
      相关资源
      最近更新 更多