Intermittent ClassNotFoundException on app update

73 views
Skip to first unread message

JonS

unread,
Feb 28, 2015, 3:23:24 PM2/28/15
to android-...@googlegroups.com
Hi,

I've noticed that a large number of my apps that I am publishing in Google Play have crashes (shown in the "Crash and ANR"  tab) that look like this.

java.lang.RuntimeException: Unable to instantiate application com.domain.app.MainApplication: java.lang.ClassNotFoundException: com.domain.app.MainApplication
    at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4265)
    at android.app.ActivityThread.access$1400(ActivityThread.java:143)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1301)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4962)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.domain.app.MainApplication
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    at android.app.Instrumentation.newApplication(Instrumentation.java:982)
    at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
    ... 11 more

Note that all my apps are pretty much independent of each other and do not have shared code.

From the Google Play developer console, I've noticed that these crashes mostly occur when the app is being updated.  My guess is that when the PackageManager attempts to update my app, that the Android platform is not completely stopping my app.  Therefore, since the app is still running while the APK is being removed, when the app needs code or any resources, it is unable to locate it (apk has been deleted during update) and therefore throws this exception.

Again, this exception is intermittent.  Out of every 100 or so updates, this crash will appear once or twice.

Has anyone else experienced this?  My theory is that the platform itself must be buggy, but I am unable to confirm this.  Is there a way for me to confirm this is a platform issue?

Thanks!
J


David Cameron

unread,
Mar 2, 2015, 10:17:02 AM3/2/15
to android-...@googlegroups.com
I've seen something similar in a situation where we were trying to keep a service perpetually running in the background. During an upgrade, the system would notice that the service wasn't running anymore and try to restart it before the new apk was correctly in place. I think we ended up working around it by detecting upgrades, stopping the service, and scheduling a re-launch in AlarmManager for an arbitrary amount of time later.

This was also a system level app, in case that is relevant in your case as well.

I suppose it is a platform issue, at least a type of race condition. In our case we blamed it on our somewhat unorthodox desire to keep the service constantly running.


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.
To post to this group, send email to android-...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.

JonS

unread,
Mar 2, 2015, 12:46:59 PM3/2/15
to android-...@googlegroups.com
Thanks David.  I appreciate the feedback.  We do have quite a bit of services that run in my app.  They are all in-process non-system services though.  I'll try to add logging in the onDestroy(...) and onCreate(...) of each service method to see what I can find out.

We also have a lot of broadcast receivers so I am wondering if maybe the system is not unregistering my receivers prior to the update.  Therefore, I wonder if it's possible for my  receivers to receive a system event when my app is in the middle of an update (i.e. after APK has been removed and before it has been re-installed?).

J

David Cowden

unread,
Mar 2, 2015, 1:01:55 PM3/2/15
to android-...@googlegroups.com
I don't think "we have an everlasting service so whatever" is a valid rationalization for the general issue because, if the issue is indeed as described, then this could happen to any service that requests to be restarted if it's killed in-flight. It doesn't seem the long-lasting aspect has anything to do with this--the race condition exists nonetheless.
Reply all
Reply to author
Forward
0 new messages