capacitor-community / admob

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

Update has broken Android and has changed display on iOS #299

Closed davelyons-4ob closed 7 months ago

davelyons-4ob commented 7 months ago

I was previously on version 5.0.0. Visually this was perfect however I found out this morning that it doesn't work for Android.

On the attempt to show a banner, the app closes and shows the following error

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:958)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                        at android.os.Looper.loop(Looper.java:294)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8177)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

It doesn't seem to be able to find the view/sub view it is attempting to put the admob banner in.

In an attempt to fix this thinking I maybe had something out of date I updated the package version (and the corresponding ones too) to the latest 5.3.1.

This error still occurs on Android and now the display in iOS now has black bars to the top and the bottom were as before it didn't.

Any ideas?

davelyons-4ob commented 7 months ago

Couldn't delete but found the issue.

Using Ionic I had a check to see if the app was running in Native Mode or PWA, if it was native it initialised the AdMob plugin. There is no check in the plugin to see if it as been initialised or just called (i.e. ShowBanner). This was my issue.