1

I could not find enough information on the internet on merging unity ads  through Admob Mediation in flutter. Can someone guide me in the changes needed to be done in the project after setting Mediation in Admob. The changes that need to be clear are :

  1. What are the dependencies I should add excluding google_mobile_ads?
  2. What are the implementations that should be added to the build.gradle and podfile?
  3. Are there anything to be done on any other folders?

here is what i did so far:

  1. in the build.gradle/app:
flutter {
    source '../..'
}

dependencies {
   .......
    implementation 'com.google.android.gms:play-services-ads:21.5.0'
    implementation 'com.unity3d.ads:unity-ads:4.5.0'
    implementation 'com.google.ads.mediation:unity:4.5.0.0'
}
  1. in the podfile:
#platform :ios, '12.0'

pod 'Google-Mobile-Ads-SDK'
pod 'GoogleMobileAdsMediationUnity'
  1. i added the App id in both AndroidManifest and info.plist files

  2. in the code i added the unit id's for both ios and android:

class AdHelper {
  //TODO Must changed to false when releasing
  static const bool _testMode = false;

  static String get bannerAdUnitId {
    if (_testMode) {
      return Platform.isAndroid
          ? "ca-app-pub-3940256099942544/6300978111" //android test id
          : "ca-app-pub-3940256099942544/2934735716"; //ios test id
    }
    return Platform.isAndroid
        ? BANNER_ID_ANDROID //android real id
        : BANNER_ID_IOS; //ios real id
  }
}

and pass the ID'S to :

bannerAd = BannerAd(
      size: AdSize(
          height: height_60.toInt(),
          width: double.parse(fullWidthScreen(context: context).toString())
              .toInt()),
      request: AdRequest(),
      adUnitId: AdHelper.bannerAdUnitId,
      listener: BannerAdListener(
        onAdLoaded: (Ad ad) {
          log('$BannerAd loaded.');
          setState(() {
            bannerAdIsLoaded = true;
          });
        },
        onAdFailedToLoad: (Ad ad, LoadAdError error) {
          log('$BannerAd failedToLoad: $error');
          ad.dispose();
        },
        onAdOpened: (Ad ad) => log('$BannerAd onAdOpened.'),
        onAdClosed: (Ad ad) => log('$BannerAd onAdClosed.'),
      ),
    );
    bannerAd.load();
  }

is there anything i need to add? because unity ads didnt show up

0 Answers0