使用ProGuard和snowplow库[0]时,我们的Android应用会收到java.lang.NoClassDefFoundError
,并显示以下错误消息:
--------- beginning of crash
E/AndroidRuntime(10137): FATAL EXCEPTION: Thread-573
E/AndroidRuntime(10137): Process: com.appier.tracker.android.demo, PID: 10137
E/AndroidRuntime(10137): java.lang.NoClassDefFoundError: <clinit> failed for class com.snowplowanalytics.snowplow.tracker.android.Util; see exception in other thread
E/AndroidRuntime(10137): at com.snowplowanalytics.snowplow.tracker.android.Subject$1.run(Unknown Source)
E/AndroidRuntime(10137): at java.lang.Thread.run(Thread.java:818)
E/AndroidRuntime(11486): FATAL EXCEPTION: Thread-753
E/AndroidRuntime(11486): Process: com.appier.tracker .android.demo, PID: 11486
E/AndroidRuntime(11486): java.lang.NoClassDefFoundEr ror: <clinit> failed for class com.snowplowanalytics.snowplow.tracker.android.Util; see exception in other thread
E/AndroidRuntime(11486): at com.snowplowanalytics.snowplow.tracker.android.Subject$1.run(Unknown Source)
E/AndroidRuntime(11486): at java.lang.Thread.run(Thread.java:818)
--------- beginning of system
但是,我们通过com.snowplowanalytics.**
中的以下设置将ProGuard设置为proguard-rules.pro
:
-dontwarn com.snowplowanalytics.**
-keep class com.snowplowanalytics.**{
*;
}
为确保ProGuard获得正确的配置,我们使用baksmali [1]来验证ProGuard是否保留Util
。以下是Util.smali
生成的baksmali
的负责人:
.class public Lcom/snowplowanalytics/snowplow/tracker/android/Util;
.super Lcom/snowplowanalytics/snowplow/tracker/core/Util;
# direct methods
.method public constructor <init>()V
.registers 1
invoke-direct {p0}, Lcom/snowplowanalytics/snowplow/tracker/core/Util;-><init>()V
return-void
.end method
.method public static getAdvertisingID(Landroid/content/Context;)Ljava/lang/String;
.registers 2
invoke-static {p0}, Lcom/snowplowanalytics/snowplow/tracker/android/Util;->getPlayAdId(Landroid/content/Context;)Ljava/ lang/String;
move-result-object v0
return-object v0
.end method
.method private static getAdvertisingInfoObject(Landroid/content/Context;)Ljava/lang/Object;
.registers 7
....
由于Util
仍然包含其所有符号名称,因此ProGuard确实会读取配置并保留com.snowplowanalytics.**
。但是,Android仍无法找到该类并抛出java.lang.NoClassDefFoundError
。我们不确定我们错过了什么,所以请告诉我们如何让snowplow库和ProGuard一起工作,没有任何问题,谢谢。
[0] https://github.com/snowplow/snowplow-android-tracker/releases/tag/0.2.0