I have several (4) error reports in my application when the Android system decides to back up in the Google Cloud using BackupAgent. I am using SharedPreferencesBackupHelper. The stack trace looks like this (my real package name is replaced below with 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 even had an accident with the program when I myself, on my own phone running Android 2.3.3. What puzzles me with this program is that I know for sure that the "MyBackupAgent" class is present in the package. I also know for sure that backing up to the cloud works on the same phone where I once crashed.
I searched quite a bit on the net to solve a problem that might be causing this problem. All cases that I found with similar problems, that is, a ClassNotFoundException exception, is thrown from PathClassLoader, although the class is present in apk, has one thing in common. They all have trailing "-1" or "-2" and the end of the package name directory where apk is installed.
In my error reports, these are different names, where dalvik.system.PathClassLoader searches for my reservation class:
/mnt/asec/com.xxx.yyy-1/pkg.apk
/data/app/com.xxx.yyy-1.apk
/mnt/asec/com.xxx.yyy-2/pkg.apk
I may be fishing in the wrong lake here, but what do these “-1” and “-2” mean at the end of the package name directory, and can there be a problem with this? I doubt that the problem lies in my code, since just tell the system to schedule a backup of my sharedpreferences. The Android system then triggers the backup action at an appropriate time in the future - and this happens in the event of a failure. Considering the stack trace, my code is not even mentioned. All system procedures end with a search for my backup class in apk and, for some unknown reason, may not find it.
I did not set the android: name attribute in the application tag in the manifest, which, as I read, could cause a similar error.
Does anyone know what can do this? Or better yet, how to avoid it.