Himel
Himel

Reputation: 163

Using test banner ad id in flutter throwing exception - "Ad for following adId already exists: 0"

I was trying to load a test banner ad in my app. I used test ad id from this link - https://developers.google.com/admob/android/test-ads#sample_ad_units and I used this package - https://pub.dev/packages/google_mobile_ads . But when I tried to run my app the following exception occurred.Here is a snap of my android studio console

Upvotes: 6

Views: 4469

Answers (5)

Magnus Johansson
Magnus Johansson

Reputation: 28325

Check that you haven't forgot to add:

MobileAds.instance.initialize();

Reference: https://developers.google.com/admob/flutter/quick-start

Upvotes: 20

Himel
Himel

Reputation: 163

Using hot reload or hot restart while working with ads creates this problem. It can be solved by using flutter clean or running it after closing. When someone hot reloads or restarts app while checking ad functionality, the system takes the previously running app and the one that will come after reload or restart as two different entity. And these entities are trying to use the same ad id and that pulls the trigger of this problem.

Upvotes: 2

Fabio
Fabio

Reputation: 735

Update google_mobile_ads to 0.11.0+4 version. In that version the problem was solved as you can see in changelog https://pub.dev/packages/google_mobile_ads/changelog

Upvotes: 0

Mehmet Filiz
Mehmet Filiz

Reputation: 720

Unfortunately the google_mobile_ads lacks documentation and it seems that no proper way to check if the ad loaded already from the previous app state. It is possible by saving the status to persistent storage then reading it just before the load is called.

Upvotes: 0

SK. Fuad
SK. Fuad

Reputation: 386

I also had a similar problem. I found out after research and testing that one unit ad needs a unique ad unit id.

The unique identifier for an ad unit. When you implement a new ad unit in your app, you'll reference the ad unit ID to tell ad networks where to send ads when they're requested. You can find the ad unit ID of an app in the app's ad units table.

Check

Go to your adMob dashboard and for your dsired app create new ad unit.

In my case there were two ads in my application's dashboard. So I created two ad units. And don't froget to release your ad object.

@override
void dispose() {
  // TODO: Dispose a BannerAd object
  _ad?.dispose();

  super.dispose();
}

Upvotes: 1

Related Questions