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

Viewed 1826
5 Answers

Check that you haven't forgot to add:

MobileAds.instance.initialize();

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.

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();
}

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.

Related