Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: NoClassDefFoundError android.os.AsyncTask

Since a couple of weeks, I'm seeing more and more crashes of my app with the following exception

Fatal Exception: java.lang.NoClassDefFoundError android.os.AsyncTask

This code has run for month without any issue, and it seems now to fail on some devices (75% android 2.3.x and 25% android 4.0.3) It fails when I create a new instance of a class which extends AsyncTask.

I create this class from the UI thread.

How can that class be not found as it's defined within the SDK ?

like image 208
user1026605 Avatar asked Nov 25 '14 07:11

user1026605


1 Answers

Yes, looks like it is a problem with one of the versions of Google play Services. See https://code.google.com/p/android/issues/detail?id=81083

A work around is to add:

try {
      Class.forName("android.os.AsyncTask");
}
catch(Throwable ignore) {
      // ignored
}

into your Application#onCreate()

this appears to ensure that the root classloader loads AsyncTask so that it is then available from within Play Services.

like image 170
William Avatar answered Oct 22 '22 06:10

William