Proguard在Google Play服务库中返回错误

时间:2014-06-20 21:38:10

标签: android google-play-services proguard

我将Google Play服务库添加到了我的应用程序中。一切正常,但我的apk的大小在4(!)倍从350KB增加到1.6MB。要从Google Play服务库中删除未使用的类,我决定使用ProGuard。但是现在我无法运行项目或将其导出到apk,因为ProGuard返回错误。当我不使用GPS lib时我没有出口问题,但我不能用这个库创建apk。 我读了很多关于这个问题的内容,但我发现的任何解决方案都没有帮助我。

这是我的proguard-project.txt(推荐here

-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.cng

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

#keep all classes that might be used in XML layouts
-keep public class * extends android.view.View
-keep public class * extends android.app.Fragment
-keep public class * extends android.support.v4.Fragment


#keep all public and protected methods that could be used by java reflection
-keepclassmembernames class * {
  public protected <methods>;
}

-keepclasseswithmembernames class * {
  native <methods>;
}

-keepclasseswithmembernames class * {
  public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
  public <init>(android.content.Context, android.util.AttributeSet, int);
}


-keepclassmembers enum * {
  public static **[] values();
  public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

-dontwarn **CompatHoneycomb
-dontwarn org.htmlcleaner.*
-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.common.GooglePlayServicesUtil {*;}
-keep class com.google.ads.** { *;}

这里是我在导出到apk后获得的错误:

[2014-06-20 23:11:38 - Dictionary] Proguard returned with error code 1. See console
[2014-06-20 23:11:38 - Dictionary]       You should check if you need to specify additional program jars.
[2014-06-20 23:11:38 - Dictionary] Unexpected error while performing partial evaluation:
[2014-06-20 23:11:38 - Dictionary]   Class       = [com/google/android/gms/common/GooglePlayServicesUtil]
[2014-06-20 23:11:38 - Dictionary]   Method      = [showErrorDialogFragment(ILandroid/app/Activity;ILandroid/content/DialogInterface$OnCancelListener;)Z]
[2014-06-20 23:11:38 - Dictionary]   Exception   = [java.lang.IllegalArgumentException] (Can't find any super classes of [com/google/android/gms/common/SupportErrorDialogFragment] (not even immediate super class [android/support/v4/app/DialogFragment]))
[2014-06-20 23:11:38 - Dictionary] java.lang.IllegalArgumentException: Can't find any super classes of [com/google/android/gms/common/SupportErrorDialogFragment] (not even immediate super class [android/support/v4/app/DialogFragment])
[2014-06-20 23:11:38 - Dictionary]  at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:299)
[2014-06-20 23:11:38 - Dictionary]  at proguard.evaluation.value.IdentifiedReferenceValue.generalize(IdentifiedReferenceValue.java:65)
[2014-06-20 23:11:38 - Dictionary]  at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:481)
[2014-06-20 23:11:38 - Dictionary]  at proguard.evaluation.Variables.generalize(Variables.java:136)
[2014-06-20 23:11:38 - Dictionary]  at proguard.evaluation.TracedVariables.generalize(TracedVariables.java:118)
[2014-06-20 23:11:38 - Dictionary]  at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:682)
[2014-06-20 23:11:38 - Dictionary]  at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:602)
[2014-06-20 23:11:38 - Dictionary]  at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.java:560)
[2014-06-20 23:11:38 - Dictionary]  at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute0(PartialEvaluator.java:264)
[2014-06-20 23:11:38 - Dictionary]  at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute(PartialEvaluator.java:181)
[2014-06-20 23:11:38 - Dictionary]  at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:101)
[2014-06-20 23:11:38 - Dictionary]  at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:79)
[2014-06-20 23:11:38 - Dictionary]  at proguard.classfile.attribute.visitor.AllAttributeVisitor.visitProgramMember(AllAttributeVisitor.java:95)
[2014-06-20 23:11:38 - Dictionary]  at proguard.classfile.util.SimplifiedVisitor.visitProgramMethod(SimplifiedVisitor.java:91)
[2014-06-20 23:11:38 - Dictionary]  at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
[2014-06-20 23:11:38 - Dictionary]  at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:504)
[2014-06-20 23:11:38 - Dictionary]  at proguard.classfile.visitor.AllMethodVisitor.visitProgramClass(AllMethodVisitor.java:47)
[2014-06-20 23:11:38 - Dictionary]  at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
[2014-06-20 23:11:38 - Dictionary]  at proguard.classfile.ClassPool.classesAccept(ClassPool.java:116)
[2014-06-20 23:11:38 - Dictionary]  at proguard.optimize.Optimizer.execute(Optimizer.java:372)
[2014-06-20 23:11:38 - Dictionary]  at proguard.ProGuard.optimize(ProGuard.java:306)
[2014-06-20 23:11:38 - Dictionary]  at proguard.ProGuard.execute(ProGuard.java:115)
[2014-06-20 23:11:38 - Dictionary]  at proguard.ProGuard.main(ProGuard.java:492)

我的本​​地配置可能有问题...... 我尝试了-keep-dontwarn不同的课程,但现在没有任何帮助......

请帮助我!

4 个答案:

答案 0 :(得分:4)

将android-support-v4.jar添加到您的项目中

答案 1 :(得分:2)

如果您使用Eclipse ADT:您应该引用您复制到开发工作区的Google Play服务库的副本 - 您不应该直接从Android SDK目录引用该库。

https://developers.google.com/android/guides/setup

答案 2 :(得分:1)

在生成签名版本时,我一直面临类似的问题和其他一些Prograud。经过大量的搜索,最终我能够解决我的问题。我相信人们有比下面更好的解决方案。

  1. 保留最新的SDK和支持的库。
  2. 在“/ sdk / tools / progaurd /".
  3. 中创建”libs“文件夹
  4. 复制.jar文件,例如您的应用程序在“/ sdk / tools / progaurd / libs /”文件夹中需要的“android-support-v13.jar”,“google-play-services.jar”。
  5. 在您的应用程序“libs”文件夹中复制.jar。 同时删除“android-support-v4.jar”,因为它不是必需的,这里v13已经支持v4
  6. 将.jar文件添加到构建路径。 同时从构建路径中删除“android-support-v4.jar”,因为它不是必需的,这里v13已经支持v4。
  7. 在应用程序project.properties文件中添加以下行。请将目标保持为“android-22”。
  8. updateView()
    1. 我的Progaurd文件“proguard-android.txt”。请根据您的要求进行更改。
    2. proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt
      # Project target.
      target=android-22
      android.library.reference.1=../../dev/sdk/extras/google/google_play_services/libproject/google-play-services_lib
      

      最诚挚的问候, 维克

答案 3 :(得分:0)

即使我有谷歌播放服务作为一个库我仍然必须手动添加android-support-v4.jar到我的libs文件夹并右键单击并添加到eclipse中的构建路径。

我的proguard文件看起来像这样:

 -optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontwarn com.google.**
-dontpreverify
-dontwarn android.support.v4.**
-dontwarn org.apache.commons.codec.binary.Base64
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*





-keep class !mycode.** { *; }

最后一行使得只有我的代码被混淆了。它更清洁。