App crashing after adding admob extension

Hello!

I’ve encountered a problem with my project after i added the admob extension (https://github.com/defold/extension-admob/archive/master.zip) that causes the app that i’ve build to crash with the following message(taken from adb logcat):
08-06 19:59:39.161 14065 14065 D AndroidRuntime: Shutting down VM
08-06 19:59:39.161 14065 14065 E AndroidRuntime: FATAL EXCEPTION: main
08-06 19:59:39.161 14065 14065 E AndroidRuntime: Process: com.TBCtalents, PID: 14065
08-06 19:59:39.161 14065 14065 E AndroidRuntime: java.lang.IllegalStateException: View android.widget.LinearLayout{df59b0a V.E… …I. 0,0-840,168} has already been added to the window manager.
08-06 19:59:39.161 14065 14065 E AndroidRuntime: at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:370)
08-06 19:59:39.161 14065 14065 E AndroidRuntime: at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:96)
08-06 19:59:39.161 14065 14065 E AndroidRuntime: at com.defold.admob.AdmobJNI$9.run(AdmobJNI.java:489)
08-06 19:59:39.161 14065 14065 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:883)
08-06 19:59:39.161 14065 14065 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:100)
08-06 19:59:39.161 14065 14065 E AndroidRuntime: at android.os.Looper.loop(Looper.java:214)
08-06 19:59:39.161 14065 14065 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7682)
08-06 19:59:39.161 14065 14065 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
08-06 19:59:39.161 14065 14065 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
08-06 19:59:39.161 14065 14065 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Information about the project:
My project is a Talent calculator for The burning crusade classic (just needed something to create while learing defold/LUA and it was the first thing that came to mind). During the building of my app i’ve been bundling and deploying to my phone and also had some testers using the app and so far not encountered any major issues.

The problem:
After adding the admob exstension to my app the app crashed when running admob.show_banner(admob.POS_TOP_CENTER). I’ve also tried admob.show_banner(admob.POS_BOTTOM_CENTER) with the same result. I did some testing adding wrong unit ID’s and such. In those situations i get the prompted that the unit ID is wrong when trying to initialize or loading the banner. When using the correct ID’s i can set callback, initialize and load banner like so:
if admob then
admob.set_callback(admob_callback)
admob.initialize()
admob.load_banner(self.banner_ad_unit)
end

When i do this i get printed message from intialization and loading that everything seems fine:
08-08 15:05:01.645 17523 17563 D defold : DEBUG:SCRIPT: EVENT_COMPLETE: Initialization complete
08-08 15:05:03.668 17523 17563 D defold : DEBUG:SCRIPT: EVENT_LOADED: Banner AD loaded. Height: 168px Width: 1078px
08-08 15:05:03.668 17523 17563 D defold : DEBUG:SCRIPT: EVENT_IMPRESSION_RECORDED: Banner did record impression

When i fire of the admob.show_banner(admob.POS_TOP_CENTER) method like this:
if admob.is_banner_loaded() then
print(“inside is banner loaded”)
admob.show_banner(admob.POS_TOP_CENTER)
end
the banner flashes for a split second on the top of the screen then the app crashes (as explaned in the log above).

I dont know what more i can try. I did try to find some information about the LinearLayout crash in the window manager but i feel stuck not know if there is a general problem with my project or if the problem is related to some conflict in my dependencies.

The issue is the same on two devices (Oneplus 6 and Sony Xperia 5 II) that i’ve tried and started after adding admob to the project.

Has anyone encountered something simular? I appreciate any help i can get solving this issue.
Thanks!

Video showing what happens:

Where exactly you have this code?

UPD:
Ok, Now I see.
It happens because you call admob.show_banner() more than once in a row.
ppbly because your code is in update or something like that. Please, check example where you can find a way how to use callback.

Hey! Thanks for having a look.
I dont quite follow that show_banner is used on more that once. The only thing i have in update function is related to druid:
image

This is my init:


and the callback is taken from the API page. i just added the self.initialized = true (as in the sample project) in case i want to use it later. Callback function:



and to not have the show banner run in the same init (while trouble shooting) i put to fire of when i click the main menu button:

It’s hard to say why it’s happening in your code.
Make sure that “inside is banner loaded” called once. Also check that you don’t have another show_banner call anywhere.

I’ve just released a new version of the extension where I ignore multiple show_banner() calls to prevent such crashes.

Release Crash when call `show_banner()` multiple times in a row · defold/extension-admob · GitHub

2 Likes

Yeah, i’ll do another runthrough and see if i can find anything obvious that i’ve missed.
But only get printed “inside is banner loaded” once and searching through all scripts (not just this one) i cant fint show.banner being called anywhere else.

The new version is working lovely. I can show banner without the app crashing!

Many thanks!

2 Likes

Some follow up:
Did some changes to my code which might have been the root cause to the double calling of show_banner but since the fix is in place I cant say for sure.

Next question:
After uploading the new package to Google Play (Internal testing) the banner won’t load. If I push install directly to my devices the banner is shown without any issue. Once again, tested on two devices with the same result on both.

This is the Stack trace from the Google Play Pre-launch:

 StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Ljava/nio/Buffer;->address:J
	at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
	at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
	at java.lang.Class.getDeclaredField(Native Method)
	at com.google.android.gms.internal.ads.zzewd.zzC(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzewd.zzB(com.google.android.gms:play-services-ads@@20.1.0:3)
	at com.google.android.gms.internal.ads.zzewd.<clinit>(com.google.android.gms:play-services-ads@@20.1.0:34)
	at com.google.android.gms.internal.ads.zzewd.zzq(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzeur.<clinit>(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzeur.zzl(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzeug.zza(com.google.android.gms:play-services-ads@@20.1.0:10)
	at com.google.android.gms.internal.ads.zzeuw.zzb(com.google.android.gms:play-services-ads@@20.1.0:3)
	at com.google.android.gms.internal.ads.zzetd.zzag(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzetd.zzah(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzclp.zzb(com.google.android.gms:play-services-ads@@20.1.0:7)
	at com.google.android.gms.internal.ads.zzeyk.zzb(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzcmt.zza(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzcma.zzb(com.google.android.gms:play-services-ads@@20.1.0:3)
	at com.google.android.gms.internal.ads.zzeyk.zzb(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzeyu.zzc(com.google.android.gms:play-services-ads@@20.1.0:4)
	at com.google.android.gms.internal.ads.zzdvh.zza(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzdvg.zzb(com.google.android.gms:play-services-ads@@20.1.0:3)
	at com.google.android.gms.internal.ads.zzeyk.zzb(com.google.android.gms:play-services-ads@@20.1.0:1)
	at com.google.android.gms.internal.ads.zzbju.zzb(com.google.android.gms:play-services-ads@@20.1.0:5)
	at com.google.android.gms.internal.ads.zzdna.zza(com.google.android.gms:play-services-ads@@20.1.0:43)
	at com.google.android.gms.internal.ads.zzdci.zzN(com.google.android.gms:play-services-ads@@20.1.0:4)
	at com.google.android.gms.internal.ads.zzdci.zze(com.google.android.gms:play-services-ads@@20.1.0:2)
	at com.google.android.gms.internal.ads.zzacs.zzg(com.google.android.gms:play-services-ads-lite@@20.1.0:22)
	at com.google.android.gms.ads.BaseAdView.loadAd(com.google.android.gms:play-services-ads-lite@@20.1.0:1)
	at com.defold.admob.AdmobJNI$7.run(AdmobJNI.java:450)
	at android.os.Handler.handleCallback(Handler.java:873)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:193)
	at android.app.ActivityThread.main(ActivityThread.java:6718)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Is my code causing the Non-SKD Violation? I’ve not added any dependencies nor changed anything major from my first post.

Please open an issue in extension-admob repository, I’ll take a look.
But! It can’t affect anything because it’s a warning (ppbly we use some outdated API and this warning just notify about it). I would recommend you to check if admob returns any errors in callback. It’s possible that you don’t have banners to show in your region or something like that.

1 Like

Issue created!

Is there some way to log/debug the releasepackage after upload to Google play? I cant upload a debug package to see the callback. And the banner does work before uploading the release package.