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。也许我们可以忽略缩小整个罐子?

4

5 回答 5

46

最后我设法做到了这样:

-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
于 2012-08-31T10:22:34.037 回答
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。

于 2013-10-16T00:19:10.397 回答
5

我不确定 Flurry 是如何专门与 AdListener 交互的,但 Google 类的名称是被混淆的。

尝试将该行添加-keep public class com.google.ads.AdListener到 proguard 文件中。如果 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。

于 2012-08-30T14:30:58.697 回答
3

Flurry(现在由 Yahoo 拥有)官方推荐的 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.**
于 2015-03-02T17:28:52.173 回答
0

Flurry 不再需要您修改您的 proguard 配置,请参阅https://developer.yahoo.com/flurry/docs/integrateflurry/android/

注意:如果你添加了 Flurry 依赖的 AAR 格式,你不需要修改你的 AndroidManifest 文件或 ProGuard 配置。

于 2018-06-29T14:01:34.340 回答