Install GMA Next-Gen SDK

To adopt Android latency and stability improvements, use GMA Next-Gen SDK. This guide covers configuring Google Mobile Ads Flutter Plugin to use GMA Next-Gen SDK for Android.

Prerequisites

Before you continue, do the following:

Configure Android Gradle settings

To use GMA Next-Gen SDK on Android, you must update your Gradle configurations:

Run with environment declaration

To use GMA Next-Gen SDK when building and running your Android app, you must supply the USE_NEXT_GEN_SDK environment declaration set to the true value.

Each time you build or run your app, run the following:

flutter run --dart-define USE_NEXT_GEN_SDK=true

Run with IDE configuration

If you run your app using an Integrated Development Environment (IDE), you can configure your environment declarations in your launch configuration instead of passing the flag using the command line.

For example, you can define these variables in a JSON file and add them to your IDE setup. For details, see specifying environment declarations.

Update native ads templates

If you use native ads templates, make the following updates to support GMA Next-Gen SDK:

Update NativeAdFactory package import

For Android, update the import statement for the NativeAdFactory class:

Java

// Replace this import:
import io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.NativeAdFactory;

// With this import:
import io.flutter.plugins.googlemobileads.NativeAdFactory;

Kotlin

// Replace this import:
import io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.NativeAdFactory

// With this import:
import io.flutter.plugins.googlemobileads.NativeAdFactory

Update native ad view layout XML views

In the layout XML files for your native ads, update the native ad view class:

<!-- Replace this element: -->
<com.google.android.gms.ads.nativead.NativeAdView ... />

<!-- With this element: -->
<com.google.android.libraries.ads.mobile.sdk.nativead.NativeAdView ... />

Configure dependencies for both setups

If your project must support both Google Mobile Ads SDK and GMA Next-Gen SDK, you can configure your android/app/build.gradle file to conditionally define dependencies based on the environment declaration.

Google Mobile Ads Flutter Plugin provides a sample configuration in the example app build.gradle file.