Google Banner Admob crash: The specified child already has a parent. You must call removeView() on the child's parent first.

1,360 views
Skip to first unread message

cuong van

unread,
Dec 28, 2022, 8:58:36 PM12/28/22
to Google Mobile Ads SDK Developers
Hi,

Some time when i show banner ads, this app will crash.

My version SDK google ads: 

implementation 'com.google.android.gms:play-services-ads:21.3.0'
37%: Android 13
19%: Android 9
19%: Android 10
19%: Android 12

Here's the error logs:

Fatal Exception: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
       at android.view.ViewGroup.addViewInner(ViewGroup.java:5477)
       at android.view.ViewGroup.addView(ViewGroup.java:5296)
       at android.view.ViewGroup.addView(ViewGroup.java:5236)
       at android.view.ViewGroup.addView(ViewGroup.java:5208)
       at com.google.android.gms.ads.internal.mraid.e.a(e.java:2)
       at com.google.android.gms.ads.internal.gmsg.an.a(an.java:11)
       at com.google.android.gms.ads.internal.webview.q.B(q.java:4)
       at com.google.android.gms.ads.internal.webview.q.e(q.java:8)
       at com.google.android.gms.ads.internal.webview.ah.run(ah.java:4)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at ass.a(ass.java)
       at com.google.android.gms.ads.internal.util.f.a(f.java:1)
       at ass.dispatchMessage(ass.java)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8741)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.ja

Mobile Ads SDK Forum Advisor

unread,
Dec 29, 2022, 12:24:17 AM12/29/22
to vancuon...@gmail.com, google-adm...@googlegroups.com

Hi Cuong,

 

Thank you for reaching out to us.

 

For us to further check the crashes happening in your banner ads, can you provide us the following information below privately? You can provide the following details via reply privately to author option or directly provide it to the link below.

 

  • Sample app project where the crashes is reproducible
  • Steps to replicate
  • SDK version used
  • Device name and versions affected
  • App Id

 

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

 

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002hOxjCQAS&entry.80707362=00162006

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

 

Regards,

Google Logo
Princess Pamela
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2hOxjC:ref

cuong van

unread,
Dec 29, 2022, 12:55:16 AM12/29/22
to Mobile Ads SDK Forum Advisor, google-adm...@googlegroups.com
Hi Mobile Ads SDK Team,

I have sent you the form according to the link you sent me, hope it can help you to solve the problem. Hope to hear from you soon. Thank you!

Vào Th 5, 29 thg 12, 2022 vào lúc 12:23 Mobile Ads SDK Forum Advisor <mobile...@forumsupport.google> đã viết:


--

Thanks and Best regards,

Nguyễn Văn Cường

Mobile: 0982429650

Email: vacuon...@gmail.com

Mobile Ads SDK Forum Advisor

unread,
Dec 29, 2022, 10:50:46 AM12/29/22
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi Cuong,

Thank you for getting back to us.

I could see that you provided a document which contains the steps to reproduce the issue. Could you please provide to us at least a sample project as well? You may provide it using the steps provided by my colleague on this thread.

Regards,
Google Logo
Teejay Wennie
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2hOxjC:ref

اسلام محمد

unread,
Dec 29, 2022, 11:02:39 AM12/29/22
to Mobile Ads SDK Forum Advisor, vancuon...@gmail.com, google-adm...@googlegroups.com

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/OjTZ0000000000000000000000000000000000000000000000RNNTBS00Kb9uNTEfSWe9PhlPdKMVjA%40sfdc.net.

Mobile Ads SDK Forum Advisor

unread,
Jan 3, 2023, 4:42:19 AM1/3/23
to am68...@gmail.com, google-adm...@googlegroups.com, vancuon...@gmail.com

Hi اسلام محمد,

 

Do you have any concerns related to Mobile Ads SDK? If so, please provide us the details. We'll be happy to assist you.

 

On the other hand, I've deleted your post as it contains private information. Below is the copy of your post with scrubbed information.

 

Regards,

Google Logo
Princess Pamela
Mobile Ads SDK Team
 

 

+xxxxxxxxxxx



ref:_00D1U1174p._5004Q2hOxjC:ref

Andrey K

unread,
May 21, 2024, 12:26:43 PM5/21/24
to Google Mobile Ads SDK Developers
Hello Google AdMob Ads SDK team,

I am facing the same issue in 2024. Please find my stacktrace attached:

com.google.android.gms:play-services-ads:23.0.0

```

Exception: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
       at android.view.ViewGroup.addViewInner(ViewGroup.java:5505)
       at android.view.ViewGroup.addView(ViewGroup.java:5324)
       at android.view.ViewGroup.addView(ViewGroup.java:5264)
       at android.view.ViewGroup.addView(ViewGroup.java:5236)
       at com.google.android.gms.ads.internal.mraid.f.b(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:30)
       at com.google.android.gms.ads.internal.mraid.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:47)
       at com.google.android.gms.ads.internal.webview.r.d(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:52)
       at com.google.android.gms.ads.internal.webview.ag.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:32)
       at com.google.android.gms.ads.internal.webview.y.run(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:3)
       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at m.azn.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:1)
       at com.google.android.gms.ads.internal.util.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:2)
       at m.azn.dispatchMessage(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:1)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8893)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
```

I carefully read this conversation and I see you asked for the sample project to reproduce this issue. 
Unfortunately, nobody provided it. And I won't be able to provide it either - the issue happens for 1%-2% of my users and I don't have repro steps.

Some stats:
76%
Samsung
11%
Xiaomi
4%
Google
3%
Huawei
6%
Other (7)
------
67%
Android 14
11%
Android 11
9%
Android 13
8%
Android 10
5%
Other (2)

1. Could you kindly deobfuscate the stacktrace I shared, find the problematic line of code and add the "remove parent ViewGroup" one-line fix?

2. Btw, I have recently migrated my app from `AdManagerView` to `AdView` - we started using AdMob instead of AdManager. I didn't have such an issue using `AdManagerView`. Could you tell me if I can continue using `AdManagerView` for AdMob ads?

I'm looking forward to hearing from you and will appreciate any help.


Mobile Ads SDK Forum Advisor

unread,
May 22, 2024, 2:16:28 AM5/22/24
to kotkov...@gmail.com, google-adm...@googlegroups.com
Hi Andrey,

Could you please confirm whether you have removed all the adViews before adding adView into the ad container while loading an ad? Also check your source code whether you are using any loop or loading banner again on ad view.

If found then the best practice is to remove those ad from container.

Could you please check and manage your ad view before loading ads.
adContainerView.removeAllViews();
adContainerView.addView(adView);

Kindly refer to our sample project BannerExample for further assistance.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02hOxjC:ref" (ADR-00162006)

Thanks,
 
Google Logo Mobile Ads SDK Team


Andrey K

unread,
May 22, 2024, 6:32:17 AM5/22/24
to Google Mobile Ads SDK Developers
Hi Mobile Ads SDK Forum Advisor,

First of all, I would like to mention that we use Jetpack Compose in our android application.
```
@Composable
fun AdGoogleBannerView(
   cachedAdView: AdView,
   modifier: Modifier = Modifier,
) {
   AndroidView(
      modifier = modifier,
      factory = { context ->
         (cachedAdView.parent as? ViewGroup)?.removeView(cachedAdView)
         FrameLayout(context).apply {
            addView(cachedAdView)
         }
      },
   )
}
```

Second of all, to show Ads asap and prevent the app UI from jumping, we cache AdViews.

> Could you please confirm whether you have removed all the adViews before adding adView into the ad container while loading an ad? Also check your source code whether you are using any loop or loading banner again on ad view.

The ad container is a composable AdGoogleBannerView() with the FrameLayout in our case. When a new composable AdGoogleBannerView() is created, a new empty `FrameLayout` is created as well. If the `cachedAdView` has a parent, we remove it before adding to the `FrameLayout`.

Please let me know if you see issues in our approach and if it can be improved.

Mobile Ads SDK Forum Advisor

unread,
May 22, 2024, 9:58:48 AM5/22/24
to kotkov...@gmail.com, google-adm...@googlegroups.com
Hi Andrey,

The implementation seems to be correct in regards to cache since you are removing adView before adding to the `FrameLayout`. Please note that AdMob is not natively supported in Jetpack Compose yet. Please be informed that AdMob exclusively provides support for the following platforms:

Andrey K

unread,
May 22, 2024, 12:48:21 PM5/22/24
to Google Mobile Ads SDK Developers
Hi Mobile Ads SDK Forum Advisor,

Thanks for checking my implementation. I am glad it seems to be correct to you as well.

1. I would be interested to know if you have plans to add native support of Jetpack Compose for android AdMob? Would be really helpful.

2. If my implementation seems to be correct (I understand you cannot check my full code, but at least the general idea is correct), could you deobfuscate the stack trace I shared above and fix the problematic line (remove a parent probably) in Android AdMob SDK?

3. Also, I mentioned that we have moved from AdManager to AdMob recently. Could you tell me if I could use `AdManagerView` for AdMob banners? Because we didn't have any issues when we used `AdManagerView`.

Could you reply to all 3 questions one by one? Thanks in advance!

Mobile Ads SDK Forum Advisor

unread,
May 23, 2024, 2:35:28 AM5/23/24
to kotkov...@gmail.com, google-adm...@googlegroups.com
Hi Andrey,


1. I would be interested to know if you have plans to add native support of Jetpack Compose for android AdMob? Would be really helpful.

-> This process is in queue, please keep a eye on android release notes.


2. If my implementation seems to be correct (I understand you cannot check my full code, but at least the general idea is correct), could you deobfuscate the stack trace I shared above and fix the problematic line (remove a parent probably) in Android AdMob SDK?

-> The error you're might be occurring because cachedAdView is already attached to a parent view, and you need to remove it from that parent before re-adding it to the new FrameLayout.


3. Also, I mentioned that we have moved from AdManager to AdMob recently. Could you tell me if I could use `AdManagerView` for AdMob banners? Because we didn't have any issues when we used `AdManagerView`.

-> I recommend you to use AdView instead of AdManager View as it might lead to some exceptions.

Andrey K

unread,
May 23, 2024, 7:22:21 AM5/23/24
to Google Mobile Ads SDK Developers
Hi Mobile Ads SDK Forum Advisor,

Thanks for your replies. I would like to ask more about the second question.


> -> The error you're might be occurring because cachedAdView is already attached to a parent view, and you need to remove it from that parent before re-adding it to the new FrameLayout.

As you see in my code below, I remove a parent of the `cachedAdView` before adding it to the new FrameLayout:
```
@Composable
fun AdGoogleBannerView(
   cachedAdViewAdView,
   modifierModifier Modifier,
) {
   AndroidView(
      modifier = modifier,
      factory = context ->
         (cachedAdView.parent as? ViewGroup)?.removeView(cachedAdView) // <----- Remove parent here
         FrameLayout(context).apply {
            addView(cachedAdView)
         }
      },
   )
}
```
Also, please have a look at the stack trace:
```
Exception: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
       at android.view.ViewGroup.addViewInner(ViewGroup.java:5505)
       at android.view.ViewGroup.addView(ViewGroup.java:5324)
       at android.view.ViewGroup.addView(ViewGroup.java:5264)
       at android.view.ViewGroup.addView(ViewGroup.java:5236)
       at com.google.android.gms.ads.internal.mraid.f.b(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:30)
       at com.google.android.gms.ads.internal.mraid.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:47)
       at com.google.android.gms.ads.internal.webview.r.d(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:52)
       at com.google.android.gms.ads.internal.webview.ag.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:32)
       at com.google.android.gms.ads.internal.webview.y.run(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:3)
       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at m.azn.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:1)
       at com.google.android.gms.ads.internal.util.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:2)
       at m.azn.dispatchMessage(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:1)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8893)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
com.google.android.gms:play-services-ads:23.0.0
```
The crash doesn't happen because the `AdView` (`cachedAdView` in my case) with a parent are being added to a ViewGroup. The crash happens because the `AdMob SDK` tries to add a child to some `ViewGroup` inside the `AdView` (the `internal` package of the `AdMob SDK`).

Could you deobfuscate this stack trace and add a check `if (hasParent) removeParent` to the problematic line of code in the `internal` SDK package?
It would be extremely helpful because about 1-2% of our users face crashes and we cannot add any fix - the crash happens inside the `AdMob SDK`.

Look forward to hearing from you and would appreciate any help!

Mobile Ads SDK Forum Advisor

unread,
May 23, 2024, 1:07:57 PM5/23/24
to kotkov...@gmail.com, google-adm...@googlegroups.com
Hi,

As we already mentioned in the previous mail that AdMob is not natively supported in Jetpack Compose yet, we could not provide any information for Jetpack implementations as this is out of scope for us.

Andrey K

unread,
May 24, 2024, 3:10:02 AM5/24/24
to Google Mobile Ads SDK Developers
Hi Mobile Ads SDK Forum Advisor,

I appreciate your guidance, but could we please focus on the issue without considering Jetpack Compose implementation for now?

I have the next stack trace:

```
Exception: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
       at android.view.ViewGroup.addViewInner(ViewGroup.java:5505)
       at android.view.ViewGroup.addView(ViewGroup.java:5324)
       at android.view.ViewGroup.addView(ViewGroup.java:5264)
       at android.view.ViewGroup.addView(ViewGroup.java:5236)
       at com.google.android.gms.ads.internal.mraid.f.b(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:30)
       at com.google.android.gms.ads.internal.mraid.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:47)
       at com.google.android.gms.ads.internal.webview.r.d(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:52)
       at com.google.android.gms.ads.internal.webview.ag.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:32)
       at com.google.android.gms.ads.internal.webview.y.run(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:3)
       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at m.azn.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:1)
       at com.google.android.gms.ads.internal.util.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:2)
       at m.azn.dispatchMessage(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:1)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8893)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
com.google.android.gms:play-services-ads:23.0.0
```
The crash happens because the `AdMob SDK` tries to add a child to some `ViewGroup` inside the `AdView` (the `internal` package of the `AdMob SDK` - please have a look at the bold line  com.google.android.gms.ads.internal.mraid.f.b....... 1:30).

Would it be possible for you to deobfuscate this stack trace and implement a conditional check—something along the lines of `if (hasParent) removeParent`—at the source of the issue within the `internal` SDK package?

Regretfully, we find ourselves unable to directly address this crash (it happens inside the AdMob SDK). Your assistance in resolving this would be immensely beneficial and greatly appreciated.

Thank you for your attention to this matter.

Mobile Ads SDK Forum Advisor

unread,
May 24, 2024, 5:50:57 AM5/24/24
to kotkov...@gmail.com, google-adm...@googlegroups.com
Hi,

Could you please confirm whether you are using any third party network adapter, in your application?

Andrey K

unread,
May 24, 2024, 5:58:12 AM5/24/24
to Google Mobile Ads SDK Developers
Hi,

Could you clarify what exactly third party network adapters you mean? Could you provide a few examples of third party network adapters?

Mobile Ads SDK Forum Advisor

unread,
May 24, 2024, 12:19:49 PM5/24/24
to kotkov...@gmail.com, google-adm...@googlegroups.com

Hi Andrey,

I will check with our team regarding your query and one of my team members will reach out to you once we have an update on this. Meanwhile, your patience is highly appreciated.

Mobile Ads SDK Forum Advisor

unread,
May 28, 2024, 1:54:23 PM5/28/24
to kotkov...@gmail.com, google-adm...@googlegroups.com

Hi Andrey,

 

Can you provide the code which caused this error?

 

The error "The specified child already has a parent. You must call removeView() on the child's parent first." Implies the cause of this bug is not internal to the Google Mobile Ads SDK, but from irregular view hierarchy.

 

This message is in relation to case "ref:!00D1U01174p.!5004Q02hOxjC:ref" (ADR-00162006)

Thanks,
 
Google Logo
Nicholas Ventimiglia
Mobile Ads SDK Team


Andrey K

unread,
May 28, 2024, 2:57:17 PM5/28/24
to Google Mobile Ads SDK Developers
Hi Nicholas,

The code / sample project to reproduce the issue was already asked several times in this thread but nobody provided it because the issue happens just for about 1% of our users - I don't have stable repro steps.
But please have a look at the stack trace I have:

```
Exception: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
       at android.view.ViewGroup.addViewInner(ViewGroup.java:5505)
       at android.view.ViewGroup.addView(ViewGroup.java:5324)
       at android.view.ViewGroup.addView(ViewGroup.java:5264)
       at android.view.ViewGroup.addView(ViewGroup.java:5236)
       at com.google.android.gms.ads.internal.mraid.f.b(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:30)
       at com.google.android.gms.ads.internal.mraid.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:47)
       at com.google.android.gms.ads.internal.webview.r.d(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:52)
       at com.google.android.gms.ads.internal.webview.ag.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:32)
       at com.google.android.gms.ads.internal.webview.y.run(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:3)
       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at m.azn.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:1)
       at com.google.android.gms.ads.internal.util.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:2)
       at m.azn.dispatchMessage(:com.google.android.gms.policy_ads_fdr_dynamite@241199803@241199801034.618989241.618989241:1)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8893)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
com.google.android.gms:play-services-ads:23.0.0
```

The bold line says that the `ViewGroup.addView()` method is called at the line:
```
com.google.android.gms.ads.internal.mraid.f.b....... 1:30)
```
It's AdMob SDK code. There is no any reference to my code in this stack trace.

Could you deobfuscate this play-services-ads:23.0.0 stack trace and have a look at the problematic line of code?

Mobile Ads SDK Forum Advisor

unread,
May 28, 2024, 5:18:47 PM5/28/24
to kotkov...@gmail.com, google-adm...@googlegroups.com

Hi Andrey,

I think the problem is in your use of caching. Can you try a simpler implementation? For instance:

@Composable
fun BannerAd(adSize: AdSize, adRequest: AdRequest, adUnitId: String, modifier: Modifier) {
  
  // Remember the adView so we can dispose of it later.
  var adView by remember { mutableStateOf<AdView?>(null) }

  if (LocalInspectionMode.current) {
    Box(
      modifier =
        Modifier.background(Color.Gray)
          .width(adSize.width.dp)
          .height(adSize.height.dp)
    ) {
      Text(text = "Google Mobile Ads Preview Banner.", modifier.align(Alignment.Center))
    }
    return
  }

  AndroidView(
    modifier = modifier.fillMaxWidth(),
    factory = { context ->
      AdView(context).apply {
        // Make sure we only run this code block once and in non-preview mode.
        if (adView != null) {
          return@apply
        }

        adView = this
        this.adUnitId = adUnitId
        this.setAdSize(adSize)
        this.adListener = ...
        this.loadAd(adRequest)
      }
    },
  )
  // Clean up the AdView after use.
  DisposableEffect(Unit) { onDispose { adView?.destroy() } }
}

Andrey K

unread,
May 29, 2024, 4:58:26 AM5/29/24
to Google Mobile Ads SDK Developers
Hi Nicholas,

Thank you for the code example. 

We aim to utilize Ad caching to enhance our users' app experience. By displaying cached Ads immediately, we can prevent any UI disruptions that occur when Ads are loaded in real-time. Based on my understanding, caching AdViews is permitted.

According to this link (https://groups.google.com/g/google-admob-ads-sdk/c/OAGAtvMJyXE/m/4q6bTdzMBwAJ), preloading ads in 2023 (and I hope in 2024) is still fine.

I would be interested to know if you could provide us with any suggestions on how to fix or prevent this crash using Ads caching.

Mobile Ads SDK Forum Advisor

unread,
May 29, 2024, 1:41:49 PM5/29/24
to kotkov...@gmail.com, google-adm...@googlegroups.com
Hi Andrey,

Give me some time to cross check this issue with the Jetpack team. I will let you know the results shortly.

cuong van

unread,
Jul 4, 2024, 10:04:02 PM7/4/24
to Google Mobile Ads SDK Developers

Hi  Mobile Ads SDK Forum Advisor,

Lately we've been seeing more of these crashes when using Collapse Banner. When we turned off Collapse Banner crash no longer occurred. According to our investigation, the cause comes from Admob SDK. Maybe while you were showing Collapse View it crashed. Please check it or is there any way we can prevent this crash.

This is the error log:

 Fatal Exception: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

       at android.view.ViewGroup.addViewInner(ViewGroup.java:5505)
       at android.view.ViewGroup.addView(ViewGroup.java:5324)
       at android.view.ViewGroup.addView(ViewGroup.java:5264)
       at android.view.ViewGroup.addView(ViewGroup.java:5236)
       at com.google.android.gms.ads.internal.mraid.f.b(:com.google.android.gms.policy_ads_fdr_dynamite@241806205@241806202034.633974825.633974825:30)
       at com.google.android.gms.ads.internal.mraid.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@241806205@241806202034.633974825.633974825:47)
       at com.google.android.gms.ads.internal.webview.r.d(:com.google.android.gms.policy_ads_fdr_dynamite@241806205@241806202034.633974825.633974825:52)
       at com.google.android.gms.ads.internal.webview.ai.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@241806205@241806202034.633974825.633974825:34)
       at com.google.android.gms.ads.internal.webview.x.run(:com.google.android.gms.policy_ads_fdr_dynamite@241806205@241806202034.633974825.633974825:3)

       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at m.bah.a(:com.google.android.gms.policy_ads_fdr_dynamite@241806205@241806202034.633974825.633974825:1)
       at com.google.android.gms.ads.internal.util.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@241806205@241806202034.633974825.633974825:1)
       at m.bah.dispatchMessage(:com.google.android.gms.policy_ads_fdr_dynamite@241806205@241806202034.633974825.633974825:1)

       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8893)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Vào lúc 00:41:49 UTC+7 ngày Thứ Năm, 30 tháng 5, 2024, Mobile Ads SDK Forum Advisor đã viết:

Mobile Ads SDK Forum Advisor

unread,
Jul 8, 2024, 2:50:59 PM7/8/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi cuong,

Can you provide a code snippet of your implementation? I think this error ("The specified child already has a parent. You must call removeView() on the child's parent first.") might be solvable on your end.

cuong van

unread,
Jul 9, 2024, 12:35:24 PM7/9/24
to Google Mobile Ads SDK Developers
Hi, 
Im Flow in the document https://developers.google.com/admob/android/banner/collapsible , no have any special of my code 

Vào lúc 01:50:59 UTC+7 ngày Thứ Ba, 9 tháng 7, 2024, Mobile Ads SDK Forum Advisor đã viết:

Mobile Ads SDK Forum Advisor

unread,
Jul 9, 2024, 1:42:09 PM7/9/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi cuong,

How do you ad the banner to the view hierarchy? According to the crash message, that is the area of interest.

cuong van

unread,
Jul 10, 2024, 11:11:19 PM7/10/24
to Google Mobile Ads SDK Developers
Untitled.png

see my code


Vào lúc 00:42:09 UTC+7 ngày Thứ Tư, 10 tháng 7, 2024, Mobile Ads SDK Forum Advisor đã viết:

Mobile Ads SDK Forum Advisor

unread,
Jul 11, 2024, 1:50:54 PM7/11/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
This code is much different than our kotlin sample code, which makes me reason that the issue is the custom layout code. I am not familiar with IKSDKLoadCore, and it appears much of the code is related to reparenting the AdView, which is the issue. For me to investigate this further I need to prove this bug is either in our sample project and the SDK and would need to replicate this issue in the sample before I could propose a fix.

cuong van

unread,
Jul 12, 2024, 3:46:36 AM7/12/24
to Google Mobile Ads SDK Developers
About IKSDKLoadCore, just , is my callback to manage callbacks. and then I use a viewgroup to add AdView. I think it crashed after adding AdView. AdMob SDK will then add the view to a WindowView to show CollapseAd. And for some reason I think the problem lies in adding CollapseAd to WindownView

Vào lúc 00:50:54 UTC+7 ngày Thứ Sáu, 12 tháng 7, 2024, Mobile Ads SDK Forum Advisor đã viết:

Mobile Ads SDK Forum Advisor

unread,
Jul 12, 2024, 12:25:16 PM7/12/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi cuong,

That sounds plausible, what steps do I need to take in order to replicate this on my end? For me to forward this to engineering I need to demonstrate the issue. Currently, the sample app will not cause issues on its own.

cuong van

unread,
Jul 15, 2024, 11:04:46 PM7/15/24
to Google Mobile Ads SDK Developers
Hi Mobile Ads SDK Forum Advisor,
Any update?

Vào lúc 23:25:16 UTC+7 ngày Thứ Sáu, 12 tháng 7, 2024, Mobile Ads SDK Forum Advisor đã viết:

Mobile Ads SDK Forum Advisor

unread,
Jul 16, 2024, 6:56:30 PM7/16/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi cuong,

I am unable to replicate this issue on my end. Can you modify the minimal sample application so that I can demonstrate the issue on me end?

cuong van

unread,
Jul 17, 2024, 10:49:37 PM7/17/24
to Google Mobile Ads SDK Developers
While in the test environment or when we test, this bug does not appear. It only occurs in a limited number of users when using it, so we cannot reproduce it or provide the source so you can reproduce it. Can you provide a way to help us make sure we don't crash according to the log we provided so we can provide the best user experience?

Vào lúc 05:56:30 UTC+7 ngày Thứ Tư, 17 tháng 7, 2024, Mobile Ads SDK Forum Advisor đã viết:

Mobile Ads SDK Forum Advisor

unread,
Jul 18, 2024, 2:02:03 PM7/18/24
to vancuon...@gmail.com, google-adm...@googlegroups.com

Hi Cuong,

Maybe we can try changing how we remove the adview from the parent. In the case we are using some sort of dynamic or recycled view, the parent might change.

ViewGroup viewParent = (ViewGroup) adView.getParent();
viewParent.removeView(adView);

cuong van

unread,
Jul 22, 2024, 11:09:13 PM7/22/24
to Google Mobile Ads SDK Developers
As shown in the photo I posted above, I have done this. I think the problem is not the adView, but the collapseAdView. and that is in the adMob SDK. You can also view the crash log. It's in the adMob SDK.

Vào lúc 01:02:03 UTC+7 ngày Thứ Sáu, 19 tháng 7, 2024, Mobile Ads SDK Forum Advisor đã viết:

Mobile Ads SDK Forum Advisor

unread,
Jul 23, 2024, 3:22:06 PM7/23/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi cuong van,

I attempted to replicate this using our recycle view example (here) by modifying it to load collapsible banners. This attempted failed and my application did not crash.

To move forward, I need a minimal sample app that I can run which demonstrates the issue.

cuong van

unread,
Jul 24, 2024, 11:26:32 PM7/24/24
to Google Mobile Ads SDK Developers
The problem is with the Collapse banner, not BannerInline. As I said above, we cannot reproduce the crash. It only happens to some users on Google Play. It would be difficult to recreate it. I just want to ask if there is any way to make sure the user does not crash in any case, when the user crashes, the user experience will be very bad.


Vào lúc 02:22:06 UTC+7 ngày Thứ Tư, 24 tháng 7, 2024, Mobile Ads SDK Forum Advisor đã viết:

Mobile Ads SDK Forum Advisor

unread,
Jul 25, 2024, 1:29:29 PM7/25/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi,

That is fair, give me some more time to try to see if I can replicate this issue and I will get back to you. In the mean time any additional details (such as affected devices) will help.

Mobile Ads SDK Forum Advisor

unread,
Jul 31, 2024, 9:09:57 PM7/31/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi,

I spoke with engineering and they asked if you attached root when inflating the view. For instance: inflater.inflate(R.layout.fragment_main, container, false).

Mobile Ads SDK Forum Advisor

unread,
Jul 31, 2024, 9:11:02 PM7/31/24
to vancuon...@gmail.com, google-adm...@googlegroups.com

Hi,

The engineer also asked for complete source code if possible so that we can better understand the issue and get this fixed.

Mobile Ads SDK Forum Advisor

unread,
Aug 5, 2024, 2:33:00 PM8/5/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi,

Good news we have identified the issue and are working on a fix. Thank you for reporting this.

cuong van

unread,
Aug 7, 2024, 10:09:19 AM8/7/24
to Google Mobile Ads SDK Developers
hi, 
Great, can you share what is the cause of the error. and when will we get the fixed sdk version?

Vào lúc 01:33:00 UTC+7 ngày Thứ Ba, 6 tháng 8, 2024, Mobile Ads SDK Forum Advisor đã viết:

Mobile Ads SDK Forum Advisor

unread,
Aug 8, 2024, 1:45:37 PM8/8/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi,

The scheduled release is v64 which will be launched by Wed, Sep 4th.

cuong van

unread,
Sep 18, 2024, 10:13:17 PM9/18/24
to Google Mobile Ads SDK Developers
hi Mobile Ads SDK Forum Advisor,

Has your new version to fix this bug been released yet? And has the admob sdk for Android been updated with this fix yet?

Vào lúc 00:45:37 UTC+7 ngày Thứ Sáu, 9 tháng 8, 2024, Mobile Ads SDK Forum Advisor đã viết:

Mobile Ads SDK Forum Advisor

unread,
Sep 20, 2024, 1:50:01 PM9/20/24
to vancuon...@gmail.com, google-adm...@googlegroups.com
Hi,

The fix has not been released yet, but it is scheduled to be released very soon.

Lin Xia

unread,
Feb 5, 2025, 8:00:15 AMFeb 5
to Google Mobile Ads SDK Developers
Hello,After verification, if two consecutive pages both contain foldable advertisements and the initialization of the advertisements is carried out in the onCreate method of both pages, and the user switches back and forth between the two pages, a crash may occur. This issue remains unresolved in version 23.5.0, which was released after the time you mentioned it had been fixed.

Mobile Ads SDK Forum Advisor

unread,
Feb 5, 2025, 5:19:53 PMFeb 5
to happybi...@gmail.com, google-adm...@googlegroups.com
Hi,

This sounds like a new issue. Do you have sample code which demonstrates this bug?

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02hOxjC:ref" (ADR-00162006)

Thanks,
 
Google Logo
Nicholas Ventimiglia
Mobile Ads SDK Team


Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
 

 



zhou

unread,
Feb 13, 2025, 12:27:16 PMFeb 13
to Google Mobile Ads SDK Developers
  Our online project has encountered the same crash with collapsible banners, but we are unable to reproduce it. Has your new version resolved this issue? When can it be fixed?  

Mobile Ads SDK Forum Advisor

unread,
Feb 13, 2025, 1:42:02 PMFeb 13
to zhou97...@gmail.com, google-adm...@googlegroups.com

Hi zhou,


The fix has not been released yet, but it is scheduled to be released very soon.
 

Sohaib Ahmed

unread,
Jul 16, 2025, 7:29:07 AMJul 16
to Google Mobile Ads SDK Developers
I'm still facing this issue... When they are going to release?

Mobile Ads SDK Forum Advisor

unread,
Jul 16, 2025, 12:29:16 PMJul 16
to sohaibahme...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for contacting the Mobile Ads SDK Support team.
Are you experiencing this issue with the latest SDK version  24.4.0? If so, please provide a sample project that reproduces the issue.

Kindly provide the requested details via Reply privately to author option

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to


https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002hOxjCQAS&entry.80707362=00162006

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-07-16 16:28:14Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02hOxjC:ref" (ADR-00162006)



Mobile Ads SDK Forum Advisor

unread,
Jul 16, 2025, 6:39:58 PMJul 16
to sch...@hotmail.com, google-adm...@googlegroups.com

Hi,

Please note that the issue has been resolved. So, To investigate this issue again we required your sample project where the issue is reproducible and also confirm whether the issue is happening on our Google sample project.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002hOxjCQAS&entry.80707362=00162006

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-07-16 22:38:58Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02hOxjC:ref" (ADR-00162006)



Steven .

unread,
Jul 17, 2025, 1:53:48 AMJul 17
to Mobile Ads SDK Forum Advisor, sohaibahme...@gmail.com, google-adm...@googlegroups.com
Yes, I think the issue is misunderstood. It was working fine and suddenly stopped after 1 day. It has nothing to do with the project, it is on the admob side. Just to confirm, do you work with admob? 


From: 'Mobile Ads SDK Forum Advisor' via Google Mobile Ads SDK Developers <google-adm...@googlegroups.com>
Sent: Wednesday, July 16, 2025 5:28:16 PM
To: sohaibahme...@gmail.com <sohaibahme...@gmail.com>
Cc: google-adm...@googlegroups.com <google-adm...@googlegroups.com>
Subject: Re: [google-admob-ads-sdk] Google Banner Admob crash: The specified child already has a parent. You must call removeView() on the child's parent first.
 
--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-admob-ads-sdk/Z_n0t000000000000000000000000000000000000000000000SZI33300XttwPWr5Q22xDqipbK0J2A%40sfdc.net.

Mobile Ads SDK Forum Advisor

unread,
Sep 19, 2025, 4:58:27 AM (5 days ago) Sep 19
to zhou97...@gmail.com, google-adm...@googlegroups.com

Hi Zhou,

It is always recommended to use the latest version of the SDKs to avoid any issues. As of today, the latest version of Android is 24.6.0

Could you try once by updating to the latest version and confirm the results? 


Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-09-19 08:57:35Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02hOxjC:ref" (ADR-00162006)



Reply all
Reply to author
Forward
0 new messages