神秘的ClassNotFoundException当Android系统搞BackupAgent [英] Mysterious ClassNotFoundException when Android system engage BackupAgent

查看:306
本文介绍了神秘的ClassNotFoundException当Android系统搞BackupAgent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从当Android系统决定做备份使用BackupAgent谷歌云计算得到了我的应用程序数(4)错误报告。我使用的共享preferencesBackupHelper。
堆栈跟踪看起来像这样(我的真包的名字是由以下com.xxx.yyy替换):

I have got a few (4) error reports on my app from when the Android system decides to do the backup to Google cloud using the BackupAgent. I am using the SharedPreferencesBackupHelper. The stack trace looks like this (my real package name is replaced below by com.xxx.yyy):

java.lang.RuntimeException: Unable to create BackupAgent com.xxx.yyy.MyBackupAgent: java.lang.ClassNotFoundException: com.xxx.yyy.MyBackupAgent in loader dalvik.system.PathClassLoader[/mnt/asec/com.xxx.yyy-1/pkg.apk]
at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:2114)
at android.app.ActivityThread.access$3200(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1138)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4196)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.xxx.yyy.MyBackupAgent in loader dalvik.system.PathClassLoader[/mnt/asec/com.xxx.yyy-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:2064)
... 10 more

我甚至得到了程序崩溃一次我自己,在我自己的手机,它运行的是Android 2.3.3。令我百思不解这个程序崩溃的是,我肯定知道,类MyBackupAgent是包present。我也知道肯定备份到云正在同一部手机上,我曾经得到了崩溃。

I have even got the program crash once myself, on my own phone which is running Android 2.3.3. What puzzles me with this program crash is that I for sure knows that the class "MyBackupAgent" IS present in the package. I also know for sure that the backup to cloud is working on the same phone where I once got the crash.

我在网上搜索了很多针对其原因可能是什么这个问题的解决方案。我已经在类似的问题中找到的所有情况下,这是一个ClassNotFoundException从PathClassLoader抛出即使类在APK present,有一个共同点。他们都有一个结尾的-1或-2,并在安装的apk包名称目录的结尾。

I have searched quite a lot on the net for a solution for what the reason could be for this problem. All cases I have found on similar problems, that is a ClassNotFoundException is thrown from PathClassLoader even though the class is present in the apk, have one thing in common. They all have a trailing "-1" or "-2" and the end of the package name directory where the apk is installed.

在我的错误报告,这些都是那里的dalvik.system.PathClassLoader搜索我的备份类不同的名字:

In my error reports, these are the different names for where the dalvik.system.PathClassLoader searches for my backup class:

/mnt/asec/com.xxx.yyy-1/pkg.apk

/mnt/asec/com.xxx.yyy-1/pkg.apk

/data/app/com.xxx.yyy-1.apk

/data/app/com.xxx.yyy-1.apk

/mnt/asec/com.xxx.yyy-2/pkg.apk

/mnt/asec/com.xxx.yyy-2/pkg.apk

也许我钓错湖在这里,但什么这些追加-1和-2的包名目录的到底是什么意思,并可以在问题与此有关?我怀疑问题就出在我的code,因为只是告诉系统来安排我的共享preferences的备份。那么Android系统从事在未来合适的时间备份的动作 - 而这正是崩溃发生。纵观堆栈跟踪,我的code甚至没有提及。这是所有的系统例程结束了寻找我的APK,并能对某些未知的原因备份类找不到它。

Maybe I am fishing in the wrong lake here but what does these appended "-1" and "-2" at the end of the package name directory mean, and could the problem be related to this? I doubt the problem lies in my code, since just tell the system to schedule the backup of my sharedpreferences. Then the Android system engage the backup action at a suitable time in the future - and this is where the crash happens. Looking at the stack trace, my code is not even mentioned. It is all system routines that ends up searching for my backup class in the apk and can for some unknown reason not find it.

我没有设置机器人:在清单,我看可能会导致类似的错误应用程序标记的name属性。

I have not set android:name attribute in the application tag in the Manifest, which I read could cause similar error.

有没有人有什么可能导致此线索?或者更好的是,如何避免这种情况的发生。

Does anyone have a clue for what could cause this? Or better yet, how to avoid that this happens.

推荐答案

到/ mnt / ASECpreFIX表示手机被安装到PC,并在这段时间里,当应用程序试图运行或backupagent是试图运行(应用程序尚未使用)崩溃。因为手机安装预期。

"/mnt/asec" prefix means that the phone is mounted to the pc and during that time when the app is trying to run or backupagent is trying to run (the app is not used already) it crashes. It is expected since the phone is mounted.

这篇关于神秘的ClassNotFoundException当Android系统搞BackupAgent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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