简体   繁体   中英

Game crashes when loading Admob smart banner

I just upgrade my game to Unity 2019.2.0f1 and Admob 3.18.2

Now it crashes when I load smart banner (other adsize works fine).

Here is the log:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.google.android.gms.ads.AdSize.equals(java.lang.Object)' on a null object reference 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at com.google.android.gms.internal.ads.zzwu.zza(com.google.android.gms:play-services-ads-lite@@18.1.1:248) 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at com.google.android.gms.internal.ads.zzwu.zza(com.google.android.gms:play-services-ads-lite@@18.1.1:87) 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at com.google.android.gms.ads.BaseAdView.loadAd(com.google.android.gms:play-services-ads-lite@@18.1.1:15) 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at com.google.android.gms.ads.AdView.loadAd(com.google.android.gms:play-services-ads-lite@@18.1.1:18) 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at com.google.unity.ads.Banner$5.run(Banner.java:278) 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:789) 08-03 14:57:29. 307 19834 19834 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:98) 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164) 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6944) 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 08-03 14:57:29.307 19834 19834 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Here is the code:

m_BannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);

m_BannerView.OnAdLoaded += HandleOnAdLoaded;
m_BannerView.OnAdFailedToLoad += HandleOnAdFailedToLoad;
m_BannerView.OnAdOpening += HandleOnAdOpened;
m_BannerView.OnAdClosed += HandleOnAdClosed;
m_BannerView.OnAdLeavingApplication += HandleOnAdLeavingApplication;

AdRequest request = new AdRequest.Builder().Build();
m_BannerView.LoadAd(request);

There's a thread on googleads-mobile-unity github about this issue: https://github.com/googleads/googleads-mobile-unity/issues/987

One of contributors replied: I recommend using Unity version 2019.1.11f1 until we determine the cause of this. We believe it could be a Unity issue, as the Smart banner reference is null even when proguard is off.

luvjungle的解决方案,尤其是Juan Bentel的评论,对我来说就像是一个魅力。至:返回新的AndroidJavaObject(AdSizeClassName,adSize.Width,adSize.Height).GetStatic(“ SMART_BANNER”); – Juan Bentel 8月11日8:03“

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM