I am using version 1.2.1 (tried with latest version 1.2.2) of android's youtube player api. It works fine on most of the devices. However now and then, I keep on getting crashes on crashlytics. I am getting the following crashes
Fatal Exception: java.lang.IllegalStateException: android.os.TransactionTooLargeException
at com.google.android.youtube.api.jar.client.RemoteEmbeddedPlayer.x(SourceFile:558)
at bpd.w(SourceFile:576)
at tef.onTransact(SourceFile:390)
at android.os.Binder.transact(Binder.java:395)
at com.google.android.youtube.player.internal.d$a$a.r(Unknown Source)
at com.google.android.youtube.player.internal.s.h(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView.e(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerSupportFragment.onSaveInstanceState(Unknown Source)
at android.support.v4.app.Fragment.performSaveInstanceState(Fragment.java:1936)
at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1654)
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1722)
at android.support.v4.app.Fragment.performSaveInstanceState(Fragment.java:1938)
at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1654)
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1722)
at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:527)
at com.newshunt.news.activities.NewsBaseActivity.onSaveInstanceState(NewsBaseActivity.java:56)
at com.newshunt.news.activities.NewsDetailsActivity.onSaveInstanceState(NewsDetailsActivity.java:613)
at android.app.Activity.performSaveInstanceState(Activity.java:1388)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1286)
at android.app.ActivityThread.callCallActivityOnSaveInstanceState(ActivityThread.java:4588)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3960)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:4023)
at android.app.ActivityThread.access$1200(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6117)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Also getting crashes for the following exception.
Fatal Exception: java.lang.IllegalStateException: android.os.DeadObjectException
at com.google.android.apps.youtube.api.jar.a.eo.surfaceDestroyed(SourceFile:236)
at android.view.SurfaceView.updateWindow(SurfaceView.java:589)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:237)
at android.view.View.dispatchDetachedFromWindow(View.java:12854)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2757)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2757)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3844)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3819)
at android.view.ViewGroup.removeView(ViewGroup.java:3751)
at com.google.android.youtube.player.YouTubePlayerView$1.b(Unknown Source)
at com.google.android.youtube.player.internal.r.h(Unknown Source)
at com.google.android.youtube.player.internal.r$e.onServiceDisconnected(Unknown Source)
at android.app.LoadedApk$ServiceDispatcher.doDeath(LoadedApk.java:1111)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1125)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(NativeStart.java)
The crash happens to appear in specific versions of youtube application like 5.2.27. Although there are a lot of issues filed for these crashes, there has been no reply from the youtube developers on how to mitigate this issue.
Some of the fellow developers have suggested the following workarounds
1) Use loadVideo instead of cueVideo. But I cannot use this workaround because loadVideo always autoplays the video which is not a requirement of my application. Also someone mentioned that with loadVideo also, this problem is happening although in some different version.
2) Put check in the code to check the youtube application version and then put the specific code. Now the problem with this approach is that I have to check each and every version of youtube app ever released and check which versions are causing the issue which is not a good workaround.
Now is there any fix which I can apply to avoid this issue or are the youtube developers planning to release some jar which internally takes care of all these issues?
I reduced the bug occurrence by putting youtube calls (like youtubePlayer.loadVideo(), cueVideo(), getCurrentTimeMillis() etc.) in a try catch block and catch the IllegalStateException exception then reinitialize youtube player.
To create a new instance of the YoutubePlayer just call the initialize() method in the catch block.
Example:
if (youtubePlayer != null) {
try {
youtubePlayer.loadVideo(videoId);
} catch (IllegalStateException e) {
initialize(API_KEY, this);
}
}
but the bug still occurred , I worked around it by catching these exceptions and restart activity. This uncaught exceptions and to catch them you need to use UncaughtExceptionHandler
example :
private Thread.UncaughtExceptionHandler defaultUEH;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
// setup handler for uncaught exception
Thread.setDefaultUncaughtExceptionHandler(_unCaughtExceptionHandler);
}
private Thread.UncaughtExceptionHandler _unCaughtExceptionHandler =
new Thread.UncaughtExceptionHandler() {
#Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e(TAG, "uncaughtException: ", ex);
PendingIntent myActivity = PendingIntent.getActivity(getApplicationContext(),
192837, new Intent(getApplicationContext(), MainActivity.class),
PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager;
alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
15000, myActivity );
System.exit(2);
// re-throw critical exception further to the os (important)
defaultUEH.uncaughtException(thread, ex);
}
};
The android YouTube Player API is not stable, there are known bugs in it. The team from YouTube said that they will release a new version of the library.
For now, the best solution I have found is to build my own library.
Related
I'm trying to play a video faster/slower via the following block of code.
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
socket.send(positionID + ":playState:ready:empty");
player = mp;
player.setPlaybackParams(new PlaybackParams().setSpeed(1.0f));
}
});
I'm passing '1' as the parameter at the moment just for testing, which is supposed to be normal playback speed. But I get the following error regardless of what number I pass.
01-04 18:49:17.308 24548-24548/com.spectiv.slave E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.spectiv.slave, PID: 24548
java.lang.SecurityException
at android.media.MediaPlayer.setPlaybackParams(Native Method)
at com.spectiv.slave.videoActivity$3.onPrepared(videoActivity.java:80)
at android.widget.VideoView$2.onPrepared(VideoView.java:432)
at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2830)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I'm working targeting API level 23 with a compiled SDK version of 24 and I'm running the application on an Odroid C2. Any help is greatly appreciated.
EDIT - This error doesn't happen on an emulator. I have no idea what's different about the Android running on this Odroid C2. They were both Marshmallow.
I would try with
player.setPlaybackParams(player.getPlaybackParams().setSpeed(1.0f))
assuming that the video is playing without setting the playback params
Just wanted to put this as an answer for anyone searching. The error only happens on this specific piece of hardware (Odroid C2). Running the code in an emulator works.
I got the same problem on C2.
Try release media player onDestroyView() function of your fragment.
or release media player quicker than that.
It appears because pervious media player is not correctly released.
You have not started the Media Player..
player = mp;
player .start()
player.setPlaybackParams(new PlaybackParams().setSpeed(1.0f));
I am using Ionic framework to build the hybrid Android app and the app works fine. I am using Fabric Crash analytics plugin and its reporting the crashes of the app.
I am getting the below crash details very often and not sure what's the reason for the same. I am not sure what would be the starting point to start analysizing this.
Fatal Exception: java.lang.NullPointerException
at android.webkit.WebViewClassic.setNetworkAvailable(WebViewClassic.java:4224)
at android.webkit.WebView.setNetworkAvailable(WebView.java:731)
at org.apache.cordova.engine.SystemWebViewEngine$1.setNetworkAvailable(SystemWebViewEngine.java:112)
at org.apache.cordova.NativeToJsMessageQueue$OnlineEventsBridgeMode$2.run(NativeToJsMessageQueue.java:340)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5319)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(NativeStart.java)
Is it related to any plugin or any issue in Ionic or Cordvoa? Any help or advise would be helpful.
I have the same problem. I also use Cordova and Fabric Crashlytics.
It's reproduced only on Android 4.1.2, 4.2.2, 4.3.
I have reproduced the bug:
open WebView with content that contain javascript functions;
open new WebView and close it;
disable network (wifi and mobile) as soon as possible;
return to app and show stacktrace.
I found a solution:
I'm not using CordovaActivity in my app. I'm using CordovaInterface.
PluginManager associated with deleted WebView continues to call its methods. So I manual call WebView.handleDestroy() to destroy PluginManager.
In my Fragment:
#Override
public void onDestroy()
{
if (webView != null)
{
webView.handleDestroy();
webView.destroy();
webView = null;
}
super.onDestroy();
}
Update:
It's reproduced when you destroy WebView, but PluginManager continues to live and sends javascripts events to subscribers (WebViews). Because I call WebView.handleDestroy().
You could swallow the exception? Edit this file:
/platforms/android/CordovaLib/src/org/apache/cordova/engineChange/SystemWebViewEngine.java
And change this
webView.setNetworkAvailable(value);
to this
import java.lang.NullPointerException;
...
try {
webView.setNetworkAvailable(value);
}
catch (NullPointerException e) {
Log.d(TAG, "webView.setNetworkAvailable called after destroy");
}
Not really a solution, but given the difficulty in reproducing locally, it may be an option to consider.
My solution was in SystemWebViewEngine.java.
change protected final SystemWebView webView; to protected SystemWebView webView;
in destroy() method after
if (receiver != null)
{
try
{
webView.getContext().unregisterReceiver(receiver);
}
catch (Exception e)
{
Log.e(TAG, "Error unregistering configuration receiver: " + e.getMessage(), e);
}
}
add
webView = null;
Replace webView.setNetworkAvailable(value); with
if (webView != null)
webView.setNetworkAvailable(value);
In the "Crashes and ANRs" of the Google Play Developer console I've got such a report:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.content.res.Resources.getAssets()' on a null object reference
at android.app.LoadedApk.getAssets(LoadedApk.java:590)
at android.app.LoadedApk.makeApplication(LoadedApk.java:646)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5088)
at android.app.ActivityThread.access$1600(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
The device that has this problem is Galaxy S4 and runs Android 5.0
What it can be - there is not a single line from my code, why does it fail?
Thanks a lot!
I've got this in my console too.
It seems this occurs when users start the app when it's currently being updated or just after that.
A possible workaround would be to check if getResources returns null when the application start, and kill it if it does:
public class DevToolsApplication extends Application {
private static final String TAG = "DevToolsApplication";
#Override
public void onCreate() {
super.onCreate();
AppLogger.i(TAG, "app start...");
checkAppReplacingState();
}
private void checkAppReplacingState() {
if (getResources() == null) {
AppLogger.w(TAG, "app is replacing...kill");
Process.killProcess(Process.myPid());
}
}
}
See this for more information
https://issuetracker.google.com/issues/36972466
Make sure that anywhere you call getAssets(), you call it as:
getApplicationContext().getAssets()
It would appear as if you are calling getAssets() in a class that does not have the application context available, hence the fact that it is null.
I've got the same exception while added the below overlay in the AndroidManifest.xml file. Even after removing the Overlay code, landed into the above exception.
<overlay android:targetPackage="com.android.systemui"
android:priority="1"/>
Just close the Android Studio completely. Open the project again. Clean and Build the exception got cleared.
Following the suggestions provided in this question I modified my AdMob code to be compliant with the recommendations, that effectively worked reducing the number of exceptions that were appearing. However a new exception is rising.
The code is the following:
#Override
protected void onDestroy() {
if ( adView != null ) {
adView.destroy();
adView = null;
Log.i(ApplicationData.APP_TAG, TAG + ": OnDestroy, destroying the Adview");
}
super.onDestroy();
}
The method adView.destroy() appears to work well as the LogCat message is published. Just after this message I am getting the following exception on WebView:
java.lang.NullPointerException
at android.webkit.WebViewClassic.loadDataWithBaseURL(WebViewClassic.java:2741)
at android.webkit.WebView.loadDataWithBaseURL(WebView.java:919)
at com.google.android.gms.ads.internal.request.n.run(SourceFile:206)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
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:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Unfourtunately I am not able to find a way to reproduce the problem but is happening in production regularly. I have not been able to find any problem, has somebody any hint of what I can do?
One of Google Mobile Ads SDK Team said (March 14),
We looked into this issue when it was first reported, and a fix has been released within Google Play services. You should see fewer and fewer instances as your users' devices update to the new version.
Refer to https://groups.google.com/forum/#!topic/google-admob-ads-sdk/oYpQI_L14Tg
This occurs when the WebView is destroyed before loadDataWithBaseUrl is called( probably by other thread). In AdMob code, i saw that they handle this now as follows
public void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl) {
synchronized(this) {
if(!this.isDestroyed()) {
super.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
} else {
Log.d("The webview is destroyed. Ignoring action.");
}
}
}
So it should not occur now.
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(SourceFile:120)
at afw.run(SourceFile:14)
at afy.run(SourceFile:30)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
I think this is related to google play services update. Is anyone able to help me out on this issue?
Just to confirmed that the issue is related to play service I have managed to get this from crashlytics from a thread called AdWorker:
thread
at java.lang.Object.wait(Object.java)
at java.lang.Thread.parkFor(Thread.java:1231)
at sun.misc.Unsafe.park(Unsafe.java:323)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:813)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:973)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1282)
at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:207)
at zo.a(SourceFile:147)
at zo.a(SourceFile:170)
at aeh.a(SourceFile:120)
at afw.run(SourceFile:14)
at afy.run(SourceFile:30)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
it is not the right place... but there is no place at all where to report them
Number of exceptions it has double from 1 july, it is now almost 3 times what it was the 27th of june.
Issue on android google code project
The discussion is now in this thread on admob google Heading group
Last reply from google "We're aware of these crashes and are working on fixes. We hope to push out these fixes in the next week or two." (July 7th)
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);
}
}
});
Today, Google posts this : http://android-developers.blogspot.fr/2014/07/google-play-services-5.html
And now it works for me. Just try again to update the GooglePlayService in your mobile and update your ADT.
Edit :
Code to check GPS version :
// Check if GooglePlay Service is good;
resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.getActivity());
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this.getActivity(), 1).show();
rootView = inflater.inflate(R.layout.fragment_googleplayerror, container, false);
return rootView;
} else {
Log.i(Tag, "This device is not supported.");
getActivity().finish();
}
}
I got exactly same errors on different android versions after updating admob to google play services.
I think it can't be solved on user side.
It is related to Play services update, see sample crash log below. Since it crashes onCreate it might be happening when user click on an advert or a specific type of advert
USER_COMMENT=
ANDROID_VERSION=4.1.2
APP_VERSION_NAME=8.9
BRAND=samsung
PHONE_MODEL=GT-I9100
CUSTOM_DATA=
STACK_TRACE=java.lang.RuntimeException: Unable to start activity ComponentInfo{xxxxx/com.google.android.gms.ads.AdActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
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:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at acm.a(SourceFile:215)
at acz.onTransact(SourceFile:58)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.internal.ck$a$a.onCreate(Unknown Source)
at com.google.android.gms.ads.AdActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
... 11 more
java.lang.NullPointerException
at acm.a(SourceFile:215)
at acz.onTransact(SourceFile:58)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.internal.ck$a$a.onCreate(Unknown Source)
at com.google.android.gms.ads.AdActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
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:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
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
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);
}
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.
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();
// }
According to: https://groups.google.com/forum/#!topic/google-admob-ads-sdk/DkjtCx_Zvn8
Some have had a success by adding android:theme="#android:style/Theme.Translucent" to activity android:name="com.google.android.gms.ads.AdActivity" in the manifest.
I'm rolling out a new version with that fix now. Will see in a couple of days if it helps.
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.