【问题标题】:Google Play Services v23 Proguard configurationGoogle Play Services v23 Proguard 配置
【发布时间】:2015-06-25 06:20:54
【问题描述】:

升级到 Google Play 服务 v23 后,尝试在 Eclipse 中导出已签名的应用程序时看到此消息:

Proguard returned with error code 1. See console
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced class android.content.pm.PackageInstaller
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced class android.content.pm.PackageInstaller$SessionInfo
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced class android.content.pm.PackageInstaller
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced class android.content.pm.PackageInstaller$SessionInfo
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced method 'android.content.pm.PackageInstaller getPackageInstaller()' in class android.content.pm.PackageManager
Warning: com.google.android.gms.internal.zzif: can't find referenced method 'void setMixedContentMode(int)' in class android.webkit.WebSettings
      You should check if you need to specify additional program jars.
Warning: there were 4 unresolved references to classes or interfaces.
         You may need to specify additional library jars (using '-libraryjars').
Warning: there were 2 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile them and try again.
         Alternatively, you may have to specify the option 
         '-dontskipnonpubliclibraryclassmembers'.
java.io.IOException: Please correct the above warnings first.
    at proguard.Initializer.execute(Initializer.java:321)
    at proguard.ProGuard.initialize(ProGuard.java:211)
    at proguard.ProGuard.execute(ProGuard.java:86)
    at proguard.ProGuard.main(ProGuard.java:492)

我添加了这个,在documentation中指定

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

并尝试添加

-keep class android.content.pm.PackageInstaller.**

proguard-project.txt,但这没有帮助。

我错过了什么?

【问题讨论】:

  • -keep class android.content.pm.**怎么样
  • 在 Google 官方文档中有一个关于使用 Eclipse+ADT 构建的部分,所以它也应该在那里工作。

标签: android google-play-services proguard


【解决方案1】:

嘿,我遇到了完全相同的错误,我通过添加来修复它:

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**

到我的 proguard.cfg

【讨论】:

  • 这个解决方案对我有帮助,但stackoverflow.com/questions/18646899/… 中的第二个建议使 apk 文件大小更小。
  • 我已经尝试过相同的方法,但现在构建正在运行并正在运行。 Android Studio 没有生成 apk。有人可以帮忙吗?
  • 文档说不需要为此手动添加proguard规则
【解决方案2】:

我有同样的问题,但使用的是 Android Studio。基于 Lary Ciminera 的解决方案,我添加了

-dontwarn com.google.android.gms.**

到 proguard-project.txt。

【讨论】:

    【解决方案3】:

    我通过将它添加到 proguard-project.txt 来修复它:

    -keep class android.content.pm.PackageInstaller
    -keep class android.content.pm.PackageInstaller$SessionInfo
    -keep class android.content.pm.PackageManager
    
    -dontwarn android.content.pm.PackageInstaller
    -dontwarn android.content.pm.PackageInstaller$SessionInfo
    -dontwarn android.content.pm.PackageManager
    
    -keep class android.webkit.WebSettings
    -dontwarn android.webkit.WebSettings
    

    【讨论】:

      【解决方案4】:

      将您的目标 SDK 版本至少升级到 21 应该可以解决此问题。在 API 版本 21 中添加了 PackageInstaller 和相关的类:https://developer.android.com/reference/android/content/pm/PackageInstaller.html

      【讨论】:

      • 这不会阻止该应用在 Android 低于 5.0 的设备上使用吗?因为这大约占所有设备的 3%。
      • @LaryCiminera 不,目标与 minSdkVersion 不同; targetSdk 可能会触发兼容性模式。您应该将 targetSdk 设置为您拥有该应用程序的最新版本。
      猜你喜欢
      • 2014-05-18
      • 2016-11-21
      • 2015-02-24
      • 2017-07-10
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多