Android: NoClassDefFoundError android.os.AsyncTask

后端 未结 5 1254
面向向阳花
面向向阳花 2020-12-14 03:10

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.AsyncTas

相关标签:
5条回答
  • 2020-12-14 03:45

    It looks like yet another Google Play Services bug...

    https://groups.google.com/forum/#!topic/google-admob-ads-sdk/_x12qmjWI7M

    Edit: confirmed by Google staff => https://groups.google.com/d/msg/google-admob-ads-sdk/_x12qmjWI7M/9ZQs-v0ZZTMJ

    0 讨论(0)
  • 2020-12-14 03:51

    I experienced same error on android 2.3.3, but same app was stable on 4.0+. It's a Freemium and the error occurs only when in FREE mode, which runs Google Admob adverts. So the error has to be connected with this but I do no have the detail. Here is how I solved the problem:

    Execute a statement that would cause the AsyncTask class to be loaded before loading the ads.

    steps 1: Create a dummy AsyncTask extension class

    public class DummyAsyncTask extends AsyncTask<Void, Void, Void>{
    
        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub
            return null;
        }
    }
    

    step 2: just in your main activity:

    public class MainActivity extends Activity {
    
        public void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
            new DummyAsyncTask();
            .
            .some code
            .
            load your ads here
        }
    }
    

    After step 2 above, all other code section that instantiates AsyncTask extended class run normally.

    0 讨论(0)
  • 2020-12-14 03:58

    I have the same error:

    BuscaDatosJugador().execute(participante.getIconImageUrl(),String.valueOf(altoenvio), String.valueOf(contador));
    

    My solution:

    final Runnable r = new Runnable()
    {
        public void run() 
        {
            try {
                 --- my code ---
            }
        };
    
        r.run();
    }
    
    0 讨论(0)
  • 2020-12-14 04:04

    Same issue here. I see them for 95% of the cases on android 4.0.3 devices. remaining 5% for 2.3 devices

    Errors are randomly occurring from different parts of the code. Some examples:

       java.lang.NoClassDefFoundError: android/os/AsyncTask
       at android.webkit.WebView.setupPackageListener(WebView.java:1305)
       at android.webkit.WebView.<init>(WebView.java:1176)
       at android.webkit.WebView.<init>(WebView.java:1136)
    

    and

       java.lang.NoClassDefFoundError: android/os/AsyncTask
       at android.webkit.WebView.setupPackageListener(WebView.java:1354)
       at android.webkit.WebView.access$10900(WebView.java:363)
       at android.webkit.WebView$PrivateHandler.handleMessage(WebView.java:10411)
    

    and

       java.lang.NoClassDefFoundError: android.os.AsyncTask
       at android.webkit.WebView.setupPackageListener(WebView.java:1385)
       at android.webkit.WebView.<init>(WebView.java:1192)
       at android.webkit.WebView.<init>(WebView.java:1150)
       at android.webkit.WebView.<init>(WebView.java:1135)
       at android.webkit.WebView.<init>(WebView.java:1106)
       at android.webkit.WebView.<init>(WebView.java:1093)
       at com.google.android.gms.ads.internal.util.g.f(SourceFile:400)
       at com.google.android.gms.ads.internal.util.g.a(SourceFile:385)
    

    it is completely unclear why these errors are happening. usually i dont see anything in the stacktrace pointing to my code.

    0 讨论(0)
  • 2020-12-14 04:08

    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.

    0 讨论(0)
提交回复
热议问题