我基于这个指南设置了许可证检查器,特别是使用这个示例代码,它已经工作了一段时间了。
但最近我从Android P设备收到了崩溃报告,报告如下错误:
java.lang.NoClassDefFoundError:
at com.google.android.vending.licensing.ServerManagedPolicy.d (ServerManagedPolicy.java:22)
at com.google.android.vending.licensing.ServerManagedPolicy.a (ServerManagedPolicy.java:22)
at com.google.android.vending.licensing.LicenseValidator.a (LicenseValidator.java:2)
at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run (LicenseChecker.java:245)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:280)
at android.os.HandlerThread.run (HandlerThread.java:65)
Caused by: java.lang.ClassNotFoundException:
at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass (ClassLoader.java:379)
at java.lang.ClassLoader.loadClass (ClassLoader.java:312)
at com.google.android.vending.licensing.ServerManagedPolicy.d (ServerManagedPolicy.java:22)
at com.google.android.vending.licensing.ServerManagedPolicy.a (ServerManagedPolicy.java:22)
at com.google.android.vending.licensing.LicenseValidator.a (LicenseValidator.java:2)
at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run (LicenseChecker.java:245)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:280)
at android.os.HandlerThread.run (HandlerThread.java:65)
在Android P模拟器上的一些测试中,我无法重现上述相同的错误,但我发现 signedData
变量在 LicenseValidator.verify()
中被接收为 null
…请参见此处的代码here。我可以通过按照此帖子中的方法检查 null
来解决这个问题,但这只是避免问题而不是解决问题。而且,我甚至不确定它是否与我的控制台中用户报告的问题相同(也许它是特定于模拟器环境的)。
有人能对这些错误进行阐述,并提供解决方案吗?
带有更多信息的编辑:
- 我尝试过(没有成功)将以下内容添加到proguard规则中,以防止proguard删除不应删除的内容:
-keep class com.google.android.vending.licensing.** { *; }
- 我还尝试过(没有成功)在build.gradle中启用multidex:
multiDexEnabled true
- 当我直接向用户发送apk时,以与提交到Play Store相同的形式编译,没有崩溃……只有Play Store版本才会崩溃
这是来自控制台的反混淆崩溃日志(尽管我总是立即上传映射文件,但由于某种原因有时会说“此映射文件在崩溃后上传”,这真的不可能是真的,因为我立即执行操作):
java.lang.NoClassDefFoundError:
at com.google.android.vending.licensing.ServerManagedPolicy.decodeExtras (ServerManagedPolicy.java:22)
at com.google.android.vending.licensing.ServerManagedPolicy.processServerResponse (ServerManagedPolicy.java:22)
at com.google.android.vending.licensing.LicenseValidator.handleResponse (LicenseValidator.java:2)
at com.google.android.vending.licensing.LicenseValidator.verify (LicenseValidator.java:153)
at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run (LicenseChecker.java:45)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:193)
at android.os.HandlerThread.run (HandlerThread.java:65)
Caused by: java.lang.ClassNotFoundException:
at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass (ClassLoader.java:379)
at java.lang.ClassLoader.loadClass (ClassLoader.java:312)
at com.google.android.vending.licensing.ServerManagedPolicy.decodeExtras (ServerManagedPolicy.java:22)
at com.google.android.vending.licensing.ServerManagedPolicy.processServerResponse (ServerManagedPolicy.java:22)
at com.google.android.vending.licensing.LicenseValidator.handleResponse (LicenseValidator.java:2)
at com.google.android.vending.licensing.LicenseValidator.verify (LicenseValidator.java:153)
at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run (LicenseChecker.java:45)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:193)
at android.os.HandlerThread.run (HandlerThread.java:65)