Mobile Ads (AdMob)
Generate revenue with your app by integrating Google AdMob. AdMob let's you select ad formats and customize ad experiences to match your app's look and feel.
Integration
To integrate Google AdMob into your project you'll have to create yourself an accounton Google AdMob. Checkout the official integration tutorial here.
Before you can start using real ads, AdMob will have to review your app. This will require your app being present on the stores. In the meantime you can use test ads and finish the verification process later.
The Mobile Ads Block will by default use test ads when your app is running in a dev environnement.
Project Setup
Once you have created an account you'll have to create two apps, one for Android and one for iOS. Make sure to copy your app id's as you'll need them in the next step.
- iOS
- Android
Modify your ios/Runner/Info.plist
file by adding the GADApplicationIdentifier
key with the value of your AdMob iOS app ID like shown below:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-################~##########</string>
Modify your android/app/src/main/AndroidManifest.xml
file by adding a <meta-data>
tag with the value of your AdMob Android app ID like shown below:
<manifest>
<application>
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
<application>
<manifest>
Ad Units Setup
It's now time to create ad units. AdMob provides several different ad formats to choose from. For now let's create an interstitial ad unit. Create on for each platform and copy the ad unit id's.
Go to the lib/D-Infrastrucutre/plugins/mobile_ads/mobile_ads_repository.dart
file and replace the values in the AdMobUnitIds
class with the ad unit id AdMob provided you with.
class AdMobUnitIds {
// Update the following values.
static String interstitialAndroidProd = '';
static String interstitialIosProd = '';
static String bannerAndroidProd = '';
static String bannerIosProd = '';
...
}