Bug 39567 - Getting System.NotSupportedException on a couple Android apps with AdMob ads and interstitials
Summary: Getting System.NotSupportedException on a couple Android apps with AdMob ads ...
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jon Dick
URL:
Depends on:
Blocks:
 
Reported: 2016-03-13 03:41 UTC by Ivan Toledo
Modified: 2017-04-25 14:15 UTC (History)
7 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Ivan Toledo 2016-03-13 03:41:11 UTC
Hi:
Getting a lot of these nasty exceptions on a couple of my apps. One of them is live on the Play store. I was about to package the second one to the store but when testing on Release mode it crashes sometimes when it should be showing an interstitial ad.

Using latest stable Xamarin.Android on VS2015. App is using Xamarin.GooglePlayServices.Ads version 29.0.0.1. Tried with no/system/full linking, AOT, LLVM, different architectures, it just crashes more than 50% of the time. Looks like a bug in Xamarin.GooglePlayServices.Ads but not sure. Seems to happen when someone clicks on a banner ad or an interstitial ad is about to be shown.


Stack trace:

System.NotSupportedException: Unable to activate instance of type Android.Gms.Ads._InternalAdActivity from native handle 0xbfa5f3d0 (key_handle 0x19d08ab9).
at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type)
at Java.Lang.Object._GetObject<T>(IntPtr handle, JniHandleOwnership transfer)
at Java.Lang.Object.GetObject<T>(IntPtr handle, JniHandleOwnership transfer)
at Android.App.Application.IActivityLifecycleCallbacksInvoker.n_OnActivityCreated_Landroid_app_Activity_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_activity, IntPtr native_savedInstanceState)
at (wrapper dynamic-method) System.Object:3d21c515-6290-4d24-ad14-58e0d994203c (intptr,intptr,intptr,intptr)


System.MissingMethodException: No constructor found for Android.Gms.Ads._InternalAdActivity::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
at Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer)
at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)

Java.Lang.Error: Exception of type 'Java.Interop.JavaLocationException' was thrown.
Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.

--- End of managed exception stack trace ---

java.lang.Error: Java callstack:
at md55caa6fe88082d2d5789caeda3e8fc56c.BackgroundManager.n_onActivityCreated(Native Method)
at md55caa6fe88082d2d5789caeda3e8fc56c.BackgroundManager.onActivityCreated(BackgroundManager.java:47)
at android.app.Application.dispatchActivityCreated(Application.java:189)
at android.app.Activity.onCreate(Activity.java:937)
at com.google.android.gms.ads.AdActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Comment 1 Chama 2016-04-12 11:00:39 UTC
I have the same issue, any idea??
Comment 2 Jonathan Pryor 2016-04-12 19:05:26 UTC
I have an idea: it's likely due to the intermixing of two things:

1. Type mappings:

https://developer.xamarin.com/releases/android/xamarin.android_6/xamarin.android_6.0/#Reduced_NoClassDefFoundError_Generation.

2. The Xamarin.GooglePlayServices.Ads component introduces a "new" `_InternalAdActivity` type to contain the <activity/> for the Java AdActivity type.

If you have two types which map to the same Java type, the type mapping picks the first one ~arbitrarily (a warning will be emitted).

What's likely happening here is that the com.google.android.gms.ads.AdActivity has two managed mappings, the "real" AdActivity binding and the _InternalAdActivity type, and _InternalAdActivity is preferred by the type mapping.

_InternalAdActivity isn't a "normal" binding type, in that it doesn't have an _InternalAdActivity(IntPtr, JniHandleOwnership) constructor, so if an instance of AdActivity enters managed code and we try to wrap it, the wrapping will fail because the type mapping wants to use _InternalAdActivity but there's no appropriate constructor.

The fix would be to "merge" the _InternalAdActivity and AdActivity types so that there is only one type mapping for AdActivity: the binding type.
Comment 3 Ivan Toledo 2016-04-12 19:08:15 UTC
A workaround is to use v27 of Xamarin.GooglePlayServices.
Does anyone know who maintains the GooglePlayServices bindings? I think they should be informed of this bug/issue.
Comment 4 Jon Dick 2016-04-12 19:09:10 UTC
Yes, we will be addressing this in a 29.0.0.2 release of the bindings.

Thanks
Comment 5 Chama 2016-04-22 09:42:18 UTC
I am using 29.0.0.2 beta and I still have the problem
Comment 6 ColonelDePoulet 2016-04-22 16:09:28 UTC
@Jon Dick : do you have an idea of when the 29.0.0.2 release is planned for ?
Comment 7 Ray Kelly 2016-05-02 16:58:57 UTC
Same thing here, beta does not fix it.
Comment 8 Ray Kelly 2016-05-17 19:50:26 UTC
Any update?  ETA?
Comment 9 Jon Dick 2016-05-18 19:52:41 UTC
29.0.0.2 is now live now, it should fix this :)
Comment 10 Hines Vaughan III 2017-04-25 14:15:48 UTC
For anyone finding this bug and using Xamarin Forms Maps. If you are targeting Android 7.0+, you can safely updated your Google Play Services libraries greater than the minimum version. Meaning you can update to 29.0.0.2 as long as your TargetFrameworkVersion is 7.0 or more.

See Jon's comment for reference:
https://forums.xamarin.com/discussion/comment/268542/#Comment_268542