Google play services 5.0.77

前端 未结 10 1214
我寻月下人不归
我寻月下人不归 2021-01-30 04:23

From the 25th of june two unrelated apps that are using ads started to have this NPE

java.lang.NullPointerException
   at zo.a(SourceFile:172)
   at aeh.a(SourceF         


        
相关标签:
10条回答
  • 2021-01-30 04:38

    This is a partial solution and it seems (so far) to fix 100% the crashes: you should postpone the ad request a few milliseconds to avoid this crash!

    Simplified example:

        Handler handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                AdRequest adRequest = new AdRequest.Builder().build();
                adView.loadAd(adRequest);
                super.handleMessage(msg);
            }
        };
    
        if (handler != null) {
            handler.sendEmptyMessageDelayed(0, 200);
        }
    
    0 讨论(0)
  • 2021-01-30 04:39

    I have find temporary semi-solution. I use thiagolr advice above with delayed ad request:

        Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            AdRequest adRequest = new AdRequest.Builder().build();
            adView.loadAd(adRequest);
            super.handleMessage(msg);
        }
    };
    
    if (handler != null) {
        handler.sendEmptyMessageDelayed(0, 200);
    }
    

    Also I removed onResume and onPause methods, so I don't know which solution helps me, but beforee this workaround I had 100-130 java.lang.NullPointerException at zo.a(SourceFile:172) per day. After this workaround I had 6-10 NullPointerException per day. If you want you could try this solutions separately to define which of them helps.

    My removed methods in activity:

    //    @Override
    //    public void onPause() {
    //      adView.pause();
    //      super.onPause();
    //    }
    //
    //    @Override
    //    public void onResume() {
    //      super.onResume();
    //      adView.resume();
    //    }
    
    0 讨论(0)
  • 2021-01-30 04:40

    I was seeing the exact same issue with one of my apps since Jun 25th as well. You are right this is a Google issue, I think I have managed to resolve it by updating my Android Support Library to version 20 (I was using android-support-v4.jar) and my Google Play Services to version 17.

    I am not sure which of the two revisions resolved this but it's been 24 hours and the Crash reports have stopped.

    EDIT: Sorry this is still not resolved. But I got a response from the AdMod SDK team that they are looking into it. https://groups.google.com/forum/#!topic/google-admob-ads-sdk/DkjtCx_Zvn8

    0 讨论(0)
  • 2021-01-30 04:42

    I have discovered a workaround.

    In my case, I was showing the ad from within a service running in a custom process. For example:

        <service
            android:name="com.example.MyService"
            android:exported="false"
            android:process=":svc" 
            />
    

    In my AndroidManifest.xml, I then set the same android:process attribute for the declared AdActivity, and the problem went away.

        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:process=":svc"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
            />
    

    In the case of my application, I don't particularly care which process the ad activity runs in, so this workaround is sufficient. Hopefully this will be of some use to others.

    0 讨论(0)
  • 2021-01-30 04:42

    Move to using other ad sdk. I tried most of the thing mentioned and error still remains. And i personally hate applying such hacks in code. So decided to switch rather using google ad sdk with crashes and bugs.

    0 讨论(0)
  • 2021-01-30 04:47

    Found this solution by Mateusz Matela at https://groups.google.com/forum/#!topic/google-admob-ads-sdk/DkjtCx_Zvn8.

    I have tried on a Motorola DEFY+ that crashed from this bug two out of three times. It seems to work even when the warnings assositated with this bug appears in the log. It even says "AdWorker thread thrown an exception". My ads even reappeard when continuing to use the app.

    final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread thread, Throwable ex) {
                if (thread.getName().startsWith("AdWorker")) {
                    Log.w("ADMOB", "AdWorker thread thrown an exception.", ex);
                } else if (defaultHandler != null) {
                    defaultHandler.uncaughtException(thread, ex);
                } else {
                    throw new RuntimeException("No default uncaught exception handler.", ex);
                }
            }
    });
    
    0 讨论(0)
提交回复
热议问题