Proguard返回了Google Play Services库的错误



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

这是我的proguard-project.txt(推荐在这里)

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

这是我的程序。

-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不同的类,但现在没有任何帮助…

请帮帮我!

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

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

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

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

    保留最新的SDK和支持的库。
  1. 在"/sdk/tools/proguard/"中创建一个名为"libs"的文件夹。
  2. 将应用程序需要的。jar文件,例如"android-support-v13.jar","google-play-services.jar"拷贝到"/sdk/tools/proguard/libs/"文件夹中。
  3. 将.jar拷贝到应用程序的"libs"文件夹中。也删除"android-support-v4.jar",因为它不是必需的,这里v13已经支持v4
  4. 将.jar文件添加到构建路径。同时从构建路径中删除"android-support-v4.jar",因为它不是必需的,这里的v13已经支持v4了。
  5. 在应用程序项目中添加以下行。属性文件。请将目标设置为"android-22"。
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
我的程序保护文件"proguard-android.txt"。请根据您的要求更改。
-optimizationpasses 2
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-dontshrink
-verbose
-dontwarn org.apache.**
-dontwarn org.slf4j.**
-dontwarn org.json.*
-dontwarn org.mortbay.**
-dontwarn org.apache.log4j.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.apache.commons.codec.binary.**
-dontwarn javax.xml.**
-dontwarn javax.management.**
-dontwarn java.lang.management.**
-libraryjars libs/android-support-v13.jar
-libraryjars libs/google-play-services.jar

-dontwarn android.support.v13.**    
-keep class android.support.v13.** { *; }  
-keep interface android.support.v13.app.** { *; }  
-keep public class * extends android.support.v13.**   
-keep public class * extends android.app.Fragment
-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.** { *; }

-dontwarn com.google.code.**
-dontwarn oauth.signpost.**
-dontwarn twitter4j.**
-dontwarn com.google.ads.**
-dontwarn org.acra.**

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''
-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 public class com.google.code.linkedinapi.**
-keep public class android.content.** { *; }

-keep class javax.**  { *; }
-keep class org.**  { *; }
-keep class twitter4j.**  { *; }
-keep class java.lang.management.**  { *; }
-keep class com.google.code.**  { *; }
-keep class oauth.signpost.**  { *; }

-keep class org.acra.** { *; }

-keepclassmembers public class com.google.code.linkedinapi.client.impl.LinkedInApiXppClient {
     public <init>(java.lang.String, java.lang.String);
}

-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 class **.R$* {
  public static <fields>;
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keep public class * {
    public protected *;
}
-keep class * implements android.os.Parcelable {
  public static final ** CREATOR;
}

最诚挚的问候,维克

即使我有Google play services作为库,我仍然需要手动将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.** { *; }

的最后一行使它只有我的代码被混淆。它更干净。

相关内容

  • 没有找到相关文章

最新更新