4

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

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.

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.

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

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

/mnt/asec/com.xxx.yyy-2/pkg.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.

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.

HitOdessit
  • 7,198
  • 4
  • 36
  • 59
Anders
  • 109
  • 1
  • 8

2 Answers2

0

I am experiencing the same crash. One theory I'm wondering about is whether specifying a relative or absolute package name matters.

In my case I was using "android:name=" because my app does extend Application. So I was using: android.name="com.foo.bar.myapp" instead of: android.name=".myapp"

Seems like this shouldn't make a difference, but I'm wondering if the loader is using a different package name, like the one with the "-1" or "-2" suffixes.

0

"/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.

Anatoly Lubarsky
  • 3,026
  • 1
  • 18
  • 16
  • Expected? Really? To me, this appears to be a bug in the BackupAgent. Or can I avoid this crash by adding something in the code for my app? – Anders Mar 03 '12 at 00:02
  • I mean it is expected to fail. Sure it is a bug. The same is happening BTW on application upgrades when you update the binary, I guess this is the meaning of the suffixes out there. I'm looking for the solution as well, this is the root of the problem though. – Anatoly Lubarsky Mar 04 '12 at 02:49
  • 1
    Reviewing my own question, this is actually the answer to it. Thank you! I suppose there is nothing that "normal" developers can do about it. It is up to the developer(s) at Google, who are responsible for the BackupAgent, to fix this bug. – Anders Mar 06 '12 at 15:03