flutterfirebase-admob

Flutter firebase_admob does not display Ad in testdevice


I cannot display my ad unit on my device in test app.

I'am using the firebase_admob 0.9.1+1 plugin

This is the code I use :

import 'package:firebase_admob/firebase_admob.dart';

Future initAppAds() async {
  //Récupère du coup le bon ID selon si je suis sous IOS ou Android
  print(getAppId());
  await FirebaseAdMob.instance.initialize(appId: 'ca-app-pub-xxxxxxxxMyAppIdxxxxxxxxxxx');

}


Future launchAds() async {
  print("launchAds");
  print(getInterstitialId());
  MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
    nonPersonalizedAds: true, 
  );


  InterstitialAd myInterstitial = InterstitialAd(
    adUnitId: 'ca-app-pub-xxxxxxxxxxxxx/xxxxMyAdBloc',
    targetingInfo: targetingInfo, //Info de l'utilisateur
    listener: (MobileAdEvent event) {
      print("InterstitialAd event is $event");
    },
  );

  await myInterstitial.load();
  await myInterstitial.show(
    anchorType: AnchorType.bottom,
    anchorOffset: 0.0,
    horizontalCenterOffset: 0.0
  );

}

Here is the log I get :

2866-2866/com.fabien.movizz I/Ads: Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("6C11832B439BDE4C399171C8D4CC6515") to get test ads on this device.
6769-3457/? W/Ads: App does not have the required permissions to get location
6769-3539/? I/Ads: SDK version: afma-sdk-a-v20088999.15301000.1
6769-3539/? W/Ads: Received error HTTP response code: 400
2866-2866/com.fabien.movizz I/Ads: Ad failed to load : 0

So I specified the ID of my device like this:

  MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
    nonPersonalizedAds: true,
    testDevices: <String>["6C11832B439BDE4C399171C8D4CC6515"],
  );

But the ad still doesn't appear. Here is the log I get :

2866-2866/com.fabien.movizz I/Ads: This request is sent from a test device.
6769-3380/? W/Ads: App does not have the required permissions to get location
6769-3457/? I/Ads: SDK version: afma-sdk-a-v20088999.15301000.1
6769-3457/? W/Ads: Received error HTTP response code: 400
2866-2866/com.fabien.movizz I/Ads: Ad failed to load : 0

If I use a test advertisement provided by Google, the advertisement works well and here is the log I get:

2866-2866/com.fabien.movizz I/Ads: This request is sent from a test device.
6769-3539/? W/Ads: App does not have the required permissions to get location
6769-5440/? I/Ads: SDK version: afma-sdk-a-v20088999.15301000.1

What's wrong with my ad unit? I created it 2 days ago, did I wait long enough for it to appear?

Thanks for your help ;)

enter image description here

Here is my flutter doctor : enter image description here


Solution

  • You are getting Ad failed to load : 0 from admob which means there is no fault in your code and you need to wait a little. Your ad id is newly created so it will take some time to fetch ads from google servers.

    If your ad is not newly created then the error might be from using a bad Admob Application ID or in some cases not adding payment information to your admob dashboard.