capacitor-community / admob

Community plugin for using Google AdMob
MIT License
205 stars 66 forks source link

Attempt to invoke virtual method 'void android.view.ViewGroup.addView(android.view.View)' #316

Closed bayonmbayo closed 2 months ago

bayonmbayo commented 3 months ago

Describe the bug

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.addView(android.view.View)' on a null object reference
  at com.getcapacitor.community.admob.banner.BannerExecutor.lambda$createNewAdView$4 (BannerExecutor.java:290)
  at com.getcapacitor.community.admob.banner.BannerExecutor.$r8$lambda$1EMVLVvjFaJLwYRq7cDZGsVkudM
  at com.getcapacitor.community.admob.banner.BannerExecutor$$ExternalSyntheticLambda0.run
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8757)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)

To Reproduce Steps to reproduce the behavior:

  1. Open the App
  2. Crash the App
  3. Close automatically the App

Expected behavior The App has to open normally and to show ads

The App is crashing on these devices Device List on Excel-Data Admob_Capacitor_Crash_DeviceList.xlsx

Tools React 18.2.0, Capacitor 5 & Admob Capacitor 5

BaluRaut commented 2 months ago

any update here?

BaluRaut commented 2 months ago

Expecting binder but got null! endAllActiveAnimators on 0x7911aed94200 (RippleDrawable) with handle 0x7910bedd2840 To native (Capacitor plugin): callbackId: 129802094, pluginId: AdMob, methodName: addListener callback: 129802094, pluginId: AdMob, methodName: addListener, methodData: {"eventName":"bannerAdLoaded"} To native (Capacitor plugin): callbackId: 129802095, pluginId: AdMob, methodName: showBanner callback: 129802095, pluginId: AdMob, methodName: showBanner, methodData: {"adId":"removing my banner id here","isTesting":true,"adSize":"ADAPTIVE_BANNER","position":"BOTTOM_CENT Ad ID: removing my app id from here Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:240304704 Selected remote version of com.google.android.gms.ads.dynamite, version >= 240304704 Instantiated singleton DynamitePackage. Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("B3EEABB8EE11C2BE770B684D95219ECB")) to get test ads on this device. Unable to open '/data/user/0/io.ionic.starter/cache/1700159444520.dm': No such file or directory Waiting for a blocking GC ClassLinker Failed to measure fs-verity, errno 1: /data/app/~~RjlomzNY6NLNdk-hW9F8uQ==/io.ionic.starter-juGrsCLM1higoiTWvs-GtQ==/base.apk Invoke Firebase method getInstance error. The Google Mobile Ads SDK will not integrate with Firebase. Admob/Firebase integration requires the latest Firebase SDK jar, but Firebase SDK is either missing or out of date Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.CACHE Shutting down VM FATAL EXCEPTION: main Process: io.ionic.starter, PID: 2098 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.addView(android.view.View)' on a null object reference at com.getcapacitor.community.admob.banner.BannerExecutor.lambda$createNewAdView$4(BannerExecutor.java:290) at com.getcapacitor.community.admob.banner.BannerExecutor.$r8$lambda$1EMVLVvjFaJLwYRq7cDZGsVkudM(Unknown Source:0) at com.getcapacitor.community.admob.banner.BannerExecutor$$ExternalSyntheticLambda0.run(Unknown Source:4) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7872) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)

BaluRaut commented 2 months ago

any update?

distante commented 2 months ago

@bayonmbayo this problem happens because you are calling show before prepare.

Please check the documentation. There are other several issues with this explanation.

bayonmbayo commented 3 weeks ago

I solved by adding some line in the file "BannerExecutor.java", it is about to handle the "NullException" coming from Android-Layout Elements

I upload here the updated file BannerExecutor.java.txt

After updating the file "BannerExecutor.java", ANR and Crash was reduced drastically in the new version of the App 😎

PS : I use only a banner in the App, if you are using an interstitial (AdInterstitialExecutor.java) or a reward interstitial (AdRewardExecutor.java), just handle the "NullException" coming from Android-Layout Elements

Tools React 18.2.0, Capacitor 6 & Admob Capacitor 6