Monetizing Apps using Google Mobile Ads SDK for Flutter

Monetizing Apps using Google Mobile Ads SDK
Monetizing Apps using Google Mobile Ads SDK

🎁 Reward Coins increases after watching the Rewarded Video Ad

Flutter AdMob Test Ads App
Flutter AdMob Test Ads App

How do I display AdMob ads in my Flutter app and start earning revenue πŸ’°?

This guide explains how to enable test ads in Flutter app. These ad units are not associated with your AdMob account and are sample ad units that are used for building and testing your apps.

Prerequisites πŸ“

Make sure you have installed/upgraded the Prerequisites : Developer Guide

  1. Flutter 1.22.0 or higher βœ…
  2. Android
  • Android Studio 3.2 or higher βœ…
  • Target Android API level 19 or higher βœ…
  • Set compileSdkVersion to 28 or higher βœ…
  • Android Gradle Plugin 4.1 or higher βœ…

step 1 : Adding the package in pubspec.yaml

Flutter Package : google_mobile_ads

dependencies:google_mobile_ads: ^0.11.0+4
Adding Flutter Package
Adding Flutter Package

step 2 : Add meta data to Android-Manifest.xml

  • Navigate to Android Manifest.xml file
  • Path to file : android/app/src/main/AndroidManifext.xml
  • Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713
<manifest>
<application>
<!-- TODO: Replace ca-app-pub-################~########## with your AdMob App ID or Sample Admob App ID -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-################~##########"/>
</application>
</manifest>
Add meta data to Android-Manifest.xml
Add meta data to Android-Manifest.xml

step 3 : Coding β€” Sample Flutter App Code

Note: Enable Wi-Fi or mobile network on your test device or emulator to see test ads

πŸ“ŒHow to Integrate Banner Ads into a Flutter app ?

Flutter Mobile Ads AdMob Banner Ad
Flutter Banner Ad

πŸ“ŒHow to Integrate Interstitial Ads into a Flutter app ?

Flutter Mobile Ads AdMob Interstitial Ad
Flutter Interstitial Ad

πŸ“ŒHow to Integrate Rewarded Video Ads into a Flutter app ?

Flutter Mobile Ads AdMob Rewarded Video Ad
Flutter Rewarded Video Ad

πŸ’»This is a simple app demo to learn how to integrate admob ads in your flutter app.

Flutter Google Mobile Ads SDK - Dart Code
$ flutter clean
$ flutter run

GitHub Repository :πŸ“‚ flutter_test_ads_app

πŸ”¨ Top 3 Common Error Messages and Guide to Fix them

You can skip this section if you are not facing any issues/errors

Running Gradle task 'assembleDebug'...                                  
/android/app/src/debug/AndroidManifest.xml Error:
uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:google_mobile_ads] /build/google_mobile_ads/intermediates/library_manifest/debug/AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 19,
or use tools:overrideLibrary="io.flutter.plugins.googlemobileads" to force usage (may lead to runtime failures)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:google_mobile_ads] build/google_mobile_ads/intermediates/library_manifest/debug/AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 19,
or use tools:overrideLibrary="io.flutter.plugins.googlemobileads" to force usage (may lead to runtime failures)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 35s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 156.1s (!)
Exception: Gradle task assembleDebug failed with exit code 1
  • Navigate to build.gradle file
  • Path to file : android/app/build.gradle
  • compileSdkVersion 29
  • minSdkVersion 19 βœ…
  • targetSdkVersion 29
minSdkVersion 19 or higher
minSdkVersion 19 or higher
FAILURE: Build failed with an exception.                                

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
/home/.gradle/caches/transforms-2/files-2.1/554200784d0157df45da8212b6e09519/play-services-ads-lite-19.7.0/AndroidManifest.xml:27:5-43:15: AAPT: error: unexpected element <queries> found in <manifest>.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 9s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 9.9s
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
Building plugin google_mobile_ads...
Exception: The plugin google_mobile_ads could not be built due to the issue above.
  • Path to file : /android/build.gradle
dependencies { classpath 'com.android.tools.build:gradle:3.5.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }
  • Change version to 4.1.1
dependencies { classpath 'com.android.tools.build:gradle:4.1.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }
build gradle version 4.1.1
build gradle version 4.1.1
FAILURE: Build failed with an exception.                                

* Where:
Build file '/android/app/build.gradle' line: 24

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.internal.version-check']
> Minimum supported Gradle version is 6.5. Current version is 5.6.2. If using the gradle wrapper, try editing the distributionUrl in /android/gradle/wrapper/gradle-wrapper.properties to gradle-6.5-all.zip

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 425ms
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 0.9s
Exception: Gradle task assembleDebug failed with exit code 1
  • Path to file : /android/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
  • Change the distributionUrl zip package to gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Gradle wrapper properties distribution urls - gradle-6.5-all.zip
Gradle wrapper properties distribution urls - gradle-6.5-all.zip

πŸ“šUseful Resources

--

--

Helping designers and developers build high quality websites and cross platform mobile apps with our step-by-step developer guides πŸ“š at akshatapp.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
AkshatApp

AkshatApp

16 Followers

Helping designers and developers build high quality websites and cross platform mobile apps with our step-by-step developer guides πŸ“š at akshatapp.com