This page covers the instructions to initialize GMA Next Gen SDK.
Before you begin
To use GMA Next Gen SDK, you must either integrate without mediation or use AdMob as the mediation platform. The other mediation platforms are not compatible with GMA Next Gen SDK.
Configure your build for GMA Next Gen SDK
The following sections show you the necessary steps to configure GMA Next Gen SDK.
Include GMA Next Gen SDK dependency
The GMA Next Gen SDK requires a different Gradle dependency. In your app-level build file, remove the reference to the current Mobile Ads SDK dependency and include the new artifact.
| Gradle dependencies | |
|---|---|
| Current |
Kotlindependencies { // ... implementation("com.google.android.gms:play-services-ads:24.7.0") } Groovydependencies { // ... implementation 'com.google.android.gms:play-services-ads:24.7.0' } |
| GMA Next Gen SDK |
Kotlindependencies { // ... // Comment out/remove play-services-ads. // implementation("com.google.android.gms:play-services-ads:24.7.0") implementation("com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:0.21.0-beta01") } Groovydependencies { // ... // Comment out/remove play-services-ads. // implementation 'com.google.android.gms:play-services-ads:24.7.0' implementation 'com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:0.21.0-beta01' } |
Exclude com.google.android.gms modules in mediation integrations
Mediation adapters continue to depend on the current Mobile Ads SDK. However, GMA Next Gen SDK includes all classes required by mediation adapters. To avoid compile errors related to duplicate symbols, you need to exclude the current Mobile Ads SDK from being pulled in as a dependency by mediation adapters.
In your app-level build file, exclude both play-services-ads and
play-services-ads-lite modules globally from all dependencies.
Kotlin
configurations.all { exclude(group = "com.google.android.gms", module = "play-services-ads") exclude(group = "com.google.android.gms", module = "play-services-ads-lite") }
Groovy
configurations { all { exclude(group = "com.google.android.gms", module = "play-services-ads") exclude(group = "com.google.android.gms", module = "play-services-ads-lite") } }
Set the minimum and compile Android API levels
GMA Next Gen SDK requires a minimum Android API level of 24 and a
compile Android API level of 34. Adjust the minSdk and compileSdk values in
your app-level build file to 24 or higher and 34 or higher, respectively.
Initialize GMA Next Gen SDK
GMA Next Gen SDK requires initialization before loading ads, a change from the current Mobile Ads SDK where initialization is optional but recommended. Update your code if you weren't previously initializing the SDK before loading ads.
This section covers the differences in SDK initialization implementation between the current and GMA Next Gen SDK.
Set the AdMob app ID
The following examples set the AdMob app ID in the current and GMA Next Gen SDK:
| Current |
Integration requires a <manifest> <application> <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 --> <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="SAMPLE_APP_ID"/> </application> </manifest> |
| GMA Next Gen SDK |
Provide your AdMob app ID programmatically as part of SDK initialization. Kotlin// Initialize the Google Mobile Ads SDK. val initConfig = InitializationConfig.Builder("SAMPLE_APP_ID").build() MobileAds.initialize(this@MainActivity, initConfig) {} Java// Initialize GMA Next Gen SDK. InitializationConfig initConfig = new InitializationConfig.Builder("SAMPLE_APP_ID").build(); MobileAds.initialize(this, initConfig, initializationStatus -> {}); |
Review implementation changes
The following examples initialize the current and GMA Next Gen SDK:
| Current |
Call Kotlinimport com.google.android.gms.ads.MobileAds import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val backgroundScope = CoroutineScope(Dispatchers.IO) backgroundScope.launch { // Initialize the Google Mobile Ads SDK on a background thread. MobileAds.initialize(this@MainActivity) {} } } } Javaimport com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.initialization.InitializationStatus; import com.google.android.gms.ads.initialization.OnInitializationCompleteListener; public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new Thread( () -> { // Initialize the Google Mobile Ads SDK on a background thread. MobileAds.initialize(this, initializationStatus -> {}); }) .start(); } } |
| GMA Next Gen SDK |
Call
Kotlinimport com.google.android.libraries.ads.mobile.sdk.MobileAds import com.google.android.libraries.ads.mobile.sdk.initialization.InitializationConfig import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val backgroundScope = CoroutineScope(Dispatchers.IO) backgroundScope.launch { // Initialize GMA Next Gen SDK on a background thread. MobileAds.initialize( this@MainActivity, // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 InitializationConfig.Builder("SAMPLE_APP_ID").build() ) { // Adapter initialization is complete. } // Other methods on MobileAds can now be called. } } } Javaimport com.google.android.libraries.ads.mobile.sdk.MobileAds; import com.google.android.libraries.ads.mobile.sdk.initialization.InitializationConfig; public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new Thread( () -> { // Initialize GMA Next Gen SDK on a background thread. MobileAds.initialize( this, // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 new InitializationConfig.Builder("SAMPLE_APP_ID") .build(), initializationStatus -> { // Adapter initialization is complete. }); // Other methods on MobileAds can now be called. }) .start(); } } |