无法使用Proguard缩小Flurry

20
这是我的Proguard配置文件(我从Android工具文件夹中复制了它,并添加了一些行)。
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
-allowaccessmodification
-dontpreverify
    
# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

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

-keepclassmembers class **.R$* {
    public static <fields>;
}

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

######################
# added by me
########################
# guava
-keepclasseswithmembers class com.google.common.base.internal.Finalizer{
    <methods>;
}

-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue

#
#Action Bar Sherlock
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }


#-dontobfuscate    
#-libraryjars libs/FlurryAgent.jar

我想在我的应用程序中使用Flurry,但是当我尝试使用FlurryAgen.jar混淆我的应用程序时,ProGuard会失败,并显示数十个此类错误:

Warning: com.flurry.android.ay: can't find referenced class com.google.ads.AdListener

当我尝试不混淆源代码时,proguard也会失败。

如何在使用proguard时使用flurry? 如何使proguard不混淆我的源代码?

更新 还提到了FlurryAgent.jar似乎已经被混淆 - http://korniltsev.ru/p/jBU0f1c.png。也许我们可以忽略缩小整个jar文件?

5个回答

46

最终我按照以下方式完成了它:

-keep class com.flurry.** { *; }
-dontwarn com.flurry.**

你是否已经能够验证Flurry在实践中仍然正确收集统计数据,考虑到-dontwarn com.flurry.**的影响?我处于同样的情况,尝试在使用Flurry的应用程序上使用Proguard,但是对于使用dontwarn时存在的问题还有点谨慎,因为我不太了解其中的原理。 - Bryce Thomas
8
跟进一下:为了增加你的回答的权威性,我刚刚重新下载了Flurry Android SDK,在文件FlurryAds-READMEv3.0.5.pdf中,最后有一个非常简短的部分,内容如下:*7. 使用ProGuard(可选) 如果您计划在发布应用程序之前在APK上运行ProGuard,则需要将以下内容添加到“proguard.cfg”文件中:-keep class com.flurry.** { ; } -dontwarn com.flurry.*因此,我想我会使用这种方法,尽管忽略这么多警告让我感到有些不舒服。 - Bryce Thomas

10

Korniltsev的回答对我有用,但新的flurry SDK(3.2.2)建议添加以下内容:

-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
-keepattributes *Annotation*,EnclosingMethod
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

可能存在一些需要换行的特殊情况,因此我最终采用了他们自己README中的方法。


1
此答案适用于Flurry 4.2.0版本。 - deko

5
我不确定Flurry具体如何与AdListener交互,但是谷歌的类名被混淆了。请尝试在proguard文件中添加以下代码:-keep public class com.google.ads.AdListener。如果Flurry使用其他com.google.ads类,您可能需要添加更多的类例外,但是此行代码应该可以解决您的警告问题。
更新:问题在于各种广告库的公共类方法名称被混淆了。因此,您可能需要包含其他proguard设置以包括这些方法。
-keep public class com.google.ads.** { public protected *; } 
-keep public class com.inmobi.androidsdk.** { public protected *; }
-keep public class com.millenialmedia.android.** { public protected *; }
-keep public class com.mobclix.android.sdk.** { public protected *; }
-keep public class com.jumptap.adtag.** { public protected *; }

我自己曾经使用过Flurry和proguard,在上传到你选择的应用市场之前一定要充分测试apk。


谢谢您的回复!我有很多警告(http://korniltsev.ru/p/jBU05Go.png),所以我认为忽略它们不是解决方案。另外,我提到FlurryAgent.jar似乎已经混淆了 - http://korniltsev.ru/p/jBU0f1c.png。也许我们可以忽略缩小整个jar文件? - Korniltsev Anatoly
是的,我在proguard中使用了Flurry而没有特定的例外,并且只要它在构建路径中就可以正常工作。有那么多的例外情况,您需要保留许多类的名称。也许类似于-keep public class com.google.ads.** { public protected *; }这样的东西会起作用? - SD_Guru
是的,我会继续忽略缩小FlurryAgent.jar :-) - SD_Guru
你知道如何忽略整个jar包吗? - Korniltsev Anatoly
目前你的Proguard配置对FlurryAgent.jar没有任何作用,所以你确实忽略了它。我怀疑问题在于Proguard正在更改上述类中Flurry尝试调用的方法调用。 - SD_Guru

3
Flurry(现在属于雅虎)官方推荐的Proguard文件可以在此处找到:

https://developer.yahoo.com/flurry/docs/publisher/code/android/

-­keep class com.flurry.** { *; }
-­dontwarn com.flurry.**
-­keepattributes *Annotation*,EnclosingMethod,Signature
-­keepclasseswithmembers class * {
  public <init>(android.content.Context, android.util.AttributeSet, int); 
}



# Google Play Services library
-­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;
}
#If you are using the Google Mobile Ads SDK, add the following:
# Preserve GMS ads classes
-­keep class com.google.android.gms.ads.** { *;
} 
-­dontwarn com.google.android.gms.ads.**


#If you are using the InMobi SDK, add the following:
# Preserve InMobi Ads classes 
-­keep class com.inmobi.** { *;
} 
-­dontwarn com.inmobi.**
#If you are using the Millennial Media SDK, add the following:
# Preserve Millennial Ads classes
-­keep class com.millennialmedia.** { *;
} 
-­dontwarn com.millennialmedia.**

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接