如何避免java.lang.NoClassDefFoundError:pre / L上的android / os / PersistableBundle? [英] How to avoid java.lang.NoClassDefFoundError: android/os/PersistableBundle on pre-L?

查看:150
本文介绍了如何避免java.lang.NoClassDefFoundError:pre / L上的android / os / PersistableBundle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 TinyBus 库在我的应用中发送活动。 MinSDK是15,编译SDK是23.

I use the TinyBus library to dispatch events in my app. MinSDK is 15, compile SDK is 23.

在21之前的设备上,我面临的问题似乎影响了许多使用反射的应用程序。一旦我尝试在我的基础 Activity 类(继承自 AppCompatActivity )中的总线上注册,我得到以下崩溃日志:

On pre-21 devices, I'm facing the issue which seems to affect many apps that use reflection. As soon as I try to register on the bus in my base Activity class (which inherits from the AppCompatActivity), I get the following crash log:

E/AndroidRuntime: java.lang.NoClassDefFoundError: android/os/PersistableBundle
E/AndroidRuntime:     at java.lang.Class.getDeclaredMethods(Native Method)
E/AndroidRuntime:     at java.lang.Class.getPublicMethodsRecursive(Class.java:955)
E/AndroidRuntime:     at java.lang.Class.getMethods(Class.java:938)
E/AndroidRuntime:     at de.halfbit.tinybus.impl.ObjectsMeta.<init>(ObjectsMeta.java:58)
E/AndroidRuntime:     at de.halfbit.tinybus.TinyBus.processQueue(TinyBus.java:346)
E/AndroidRuntime:     at de.halfbit.tinybus.TinyBus.register(TinyBus.java:178)
E/AndroidRuntime:     at com.package.name.activities.InitializedActivity.onStart(InitializedActivity.java:62)
E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1166)
E/AndroidRuntime:     at android.app.Activity.performStart(Activity.java:5264)
E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2047)
E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2099)
E/AndroidRuntime:     at android.app.ActivityThread.access$600(ActivityThread.java:138)
E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:4929)
E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)

我知道这个错误是由dalvik无法初始化它在<无法找到的类中引起的code> dex 文件。有很多关于这个问题的信息和问题(因为它也影响了Otto和其他人),但到目前为止我只看到一个修复:删除 PersistableBundle的使用从应用程序。但是, 我在代码中的任何地方都没有引用 PersistableBundle ,但系统显然会这样做。

I know that this error is caused by dalvik failing to initialize a class it can't find in the dex file. There is a lot of info and questions related to this issue (since it also affects Otto and others), but so far I have only seen one fix: remove the usage of PersistableBundle from the app. However, I do not reference PersistableBundle anywhere in my code, but the system apparently does.

该问题还有其他已知问题吗?

Is there any other known fix to the problem?

推荐答案

嗯,问题是现在解决了。在完成我的所有代码(我应该在很久以前完成)后,我发现我实际上有引用 PersistableBundle 。那些位于我让IDE生成的方法,如 onPostCreate(PersistableBundle包),并没有注意。用 Bundle 替换所有 PersistableBundle 修复了问题。

Well, the issue is resolved now. After going through all of my code (which I should have done ages ago) I found out that I actually had references to the PersistableBundle. Those were located in methods I let the IDE generate like onPostCreate(PersistableBundle bundle) and wasn't paying attention to. Replacing all PersistableBundle with Bundle fixed the problem.

对于有类似问题的人,我只建议在使用较新的API时仔细查看生成的内容。

To folks having similar issue I can only suggest looking closely at the generated stuff when using newer API.

这篇关于如何避免java.lang.NoClassDefFoundError:pre / L上的android / os / PersistableBundle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆