簡體   English   中英

Proguard在Google Play服務庫中返回錯誤

[英]Proguard returned error with Google Play Services library

我將Google Play服務庫添加到了我的應用程序中。 一切正常,但我的apk的大小在4(!)倍從350KB增加到1.6MB。 要從Google Play服務庫中刪除未使用的類,我決定使用ProGuard。 但是現在我無法運行項目或將其導出到apk,因為ProGuard返回錯誤。 當我不使用GPS lib時我沒有出口問題,但我不能用這個庫創建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;
}

這是我的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不同的類,但現在沒有任何幫助...

請幫我!

將android-support-v4.jar添加到您的項目中

如果您使用Eclipse ADT:您應該引用復制到開發工作區的庫Google Play服務的副本 - 您不應該直接從Android SDK目錄引用該庫。

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

在生成簽名版本時,我一直面臨類似的問題和其他一些Prograud。 經過大量的搜索,最終我能夠解決我的問題。 我相信人們有比下面更好的解決方案。

  1. 保留最新的SDK和支持的庫。
  2. 在“/ sdk / tools / progaurd /”中創建一個文件夾“libs”。
  3. 復制.jar文件,例如您的應用程序在“/ sdk / tools / progaurd / libs /”文件夾中需要的“android-support-v13.jar”,“google-play-services.jar”。
  4. 在您的應用程序“libs”文件夾中復制.jar。 同時刪除“android-support-v4.jar”,因為它不是必需的,這里v13已經支持v4
  5. 將.jar文件添加到構建路徑。 同時從構建路徑中刪除“android-support-v4.jar”,因為它不是必需的,這里v13已經支持v4。
  6. 在應用程序project.properties文件中添加以下行。 請將目標保持為“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 
  1. 我的Progaurd文件“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; } 

最好的問候,Vik

即使我有谷歌播放服務作為一個庫我仍然必須手動添加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.** { *; }

最后一行使它只有我的代碼被混淆。 它更清潔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM