条纹 Android ExceptionInInitializerError

Stripe for Android ExceptionInInitializerError

使用 Stripe 库和示例 located here。当我尝试在我们的应用程序的发布版本中创建令牌时,我得到以下堆栈跟踪:

    java.lang.RuntimeException: An error occured while executing doInBackground()
    at com.stripe.android.compat.AsyncTask.done(AsyncTask.java:250)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
    at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ExceptionInInitializerError
    at com.stripe.net.APIResource.<clinit>(APIResource.java:37)
    at com.stripe.android.Stripe.doInBackground(Stripe.java:28)
    at com.stripe.android.Stripe.doInBackground(Stripe.java:23)
    at com.stripe.android.compat.AsyncTask.call(AsyncTask.java:236)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    ... 3 more
Caused by: java.lang.RuntimeException: Missing type parameter.
    at com.google.a.c.a.getSuperclassTypeParameter(TypeToken.java:84)
    at com.google.a.c.a.<init>(TypeToken.java:62)
    at com.stripe.model.FeeRefundCollectionDeserializer.<init>(FeeRefundCollectionDeserializer.java:17)
    at com.stripe.model.FeeRefundCollectionDeserializer.<clinit>(FeeRefundCollectionDeserializer.java:17)
    ... 8 more

使用调试版本似乎工作正常。我正在使用混淆器并添加了文档中提到的排除项:

-keep class com.stripe.** { *; }

我正在使用的卡是测试卡,当我 运行 调试 apk 时,它优雅地告诉我这是一张与实时密钥一起使用的测试卡。当我在实时 apk 中尝试相同操作时,它会导致崩溃。

现在完全不使用任何混淆器进行测试...

编辑:

好的,我已经完全关闭了 proguard,这似乎让问题消失了。所以现在我将尝试用我极其有限的 proguard 知识四处挖掘,试图弄清楚这里发生了什么:)

这是我的完整混淆器-rules.pro 文件:

-dontwarn com.facebook.**
-dontwarn org.joda.time.**
-dontwarn org.codehaus.**
-dontwarn java.nio.**
-dontnote **ILicensingService
-keep class com.crashlytics.** { *; }
-keep class com.crashlytics.android.**
-keep class com.stripe.** { *; }
-keepattributes SourceFile,LineNumberTable,*Annotation*

经过相当多的搜索后,我了解到 proguard 似乎正在剥离 Stripe 库中与 Gson 相关的 类,即使它不应该这样做。

As posted here, Google 似乎推荐一些额外的 gson proguard 设置:

-dontwarn com.facebook.**
-dontwarn org.joda.time.**
-dontwarn org.codehaus.**
-dontwarn java.nio.**
-dontnote **ILicensingService
-keep class com.crashlytics.** { *; }
-keep class com.crashlytics.android.**
-keep class com.stripe.** { *; }
##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }

##---------------End: proguard configuration for Gson  ----------
-keepattributes SourceFile,LineNumberTable

将这些设置添加到混淆器似乎已经修复了我的应用程序的发布版本。