Android - proguard 和 google play 服务的应用程序导出错误

Posted

技术标签:

【中文标题】Android - proguard 和 google play 服务的应用程序导出错误【英文标题】:Android - app export errors with proguard and google play services 【发布时间】:2014-09-23 13:11:50 【问题描述】:

我已将最新的 Google Play 服务添加到项目中,现在 proguard 正在提供 我有很多警告:

[2014-07-31 17:21:50 - MyApp] Proguard returned with error code 1. See console
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.common.SupportErrorDialogFragment: can't find referenced method 'void setShowsDialog(boolean)' in class com.google.android.gms.common.SupportErrorDialogFragment
[2014-07-31 17:21:50 - MyApp] Warning: com.google.android.gms.common.api.d: can't find referenced method 'android.support.v4.app.FragmentActivity getActivity()' in class com.google.android.gms.common.api.d
[2014-07-31 17:21:50 - MyApp]       You should check if you need to specify additional program jars.
[2014-07-31 17:21:50 - MyApp] Warning: there were 9 unresolved references to classes or interfaces.
[2014-07-31 17:21:50 - MyApp]          You may need to specify additional library jars (using '-libraryjars').
[2014-07-31 17:21:50 - MyApp] Warning: there were 2 unresolved references to program class members.
[2014-07-31 17:21:50 - MyApp]          Your input classes appear to be inconsistent.
[2014-07-31 17:21:50 - MyApp]          You may need to recompile them and try again.
[2014-07-31 17:21:50 - MyApp]          Alternatively, you may have to specify the option 
[2014-07-31 17:21:50 - MyApp]          '-dontskipnonpubliclibraryclassmembers'.
[2014-07-31 17:21:50 - MyApp] java.io.IOException: Please correct the above warnings first.
[2014-07-31 17:21:50 - MyApp]   at proguard.Initializer.execute(Initializer.java:321)
[2014-07-31 17:21:50 - MyApp]   at proguard.ProGuard.initialize(ProGuard.java:211)
[2014-07-31 17:21:50 - MyApp]   at proguard.ProGuard.execute(ProGuard.java:86)
[2014-07-31 17:21:50 - MyApp]   at proguard.ProGuard.main(ProGuard.java:492)

我已经尝试添加

-dontwarn com.google.android.gms.*
-keep class android.support.v4.**  *; 

到 proguard 配置文件,但没有运气。我在我的应用程序中定位到 android 17 (4.2.2),并且最低 SDK 版本是 8(我认为是 2.2)。

任何解决此错误的帮助将不胜感激。

【问题讨论】:

【参考方案1】:

确保您已使用 Android 4.4.2 设置您的项目并且您已“包含 android-support-v13.jar”。我有同样的问题,但现在已经解决了。

【讨论】:

【参考方案2】:

你添加了吗:

-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;

在你的 Proguard 中? http://developer.android.com/google/play-services/setup.html

【讨论】:

是的,我已经添加并完成了添加google play服务的所有步骤。【参考方案3】:

似乎 google play 服务 jar 引用了 android-support-v13.jar 中的一些类。 因此在 proguard-project.txt 中添加以下行将解决问题:

-libraryjars <ANDROID_SDK_PATH>/extras/android/support/v13/android-support-v13.jar

您需要使用 Android SDK 管理器下载此 jar。

【讨论】:

以上是关于Android - proguard 和 google play 服务的应用程序导出错误的主要内容,如果未能解决你的问题,请参考以下文章

Android、Scala 和 Proguard

Android中的Proguard和反射

如何在 android 中使用 ProGuard 和 OrmLite

使用 ProGuard 和 Android 应用程序时资源重复

Android 上的 ProGuard 和 Gson (ClassCastException)

使用 LibGDX 和 ProGuard 导出 Android APK 时出错