Integrating the Google Mobile Ads SDK is the foundation of displaying ads and generating revenue in your swift app development project. Before diving into the setup process, ensure that your app meets the specified minimum and compile SDK versions.

To prepare your app for integration, complete the steps outlined below.

App Prerequisites

Before you begin, make sure that your app's build file uses the following values:

  • Minimum SDK version of 23 or higher
  • Compile SDK version of 35 or higher

Configure Your App

In your Gradle settings file, include the Google's Maven repository and Maven central repository:

  • Kotlin: pluginManagement { repositories { google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } } rootProject.name = "My Application" include(":app")
  • Groovy: pluginManagement { repositories { google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } } rootProject.name = "My Application" include ':app'

Add the dependencies for Google Mobile Ads SDK to your app-level build file:

  • Kotlin: dependencies { implementation("com.google.android.gms:play-services-ads:24.9.0") }
  • Groovy: dependencies { implementation 'com.google.android.gms:play-services-ads:24.9.0' }

Click Sync Now.

Add Your Ad Manager App ID

Add your Ad Manager app ID, as identified in the Ad Manager web interface, to your app's AndroidManifest.xml file. To do so, add a tag with android:name="com.google.android.gms.ads.APPLICATION_ID" and android:value=your unique application ID.

Initialize the Google Mobile Ads SDK

Before loading ads, initialize Google Mobile Ads SDK by calling MobileAds.initialize(). This method initializes the SDK and calls a completion listener once both Google Mobile Ads SDK and adapter initializations have completed, or after a 30-second timeout. This needs to be done only once, ideally at app launch.

If you're using mediation, wait until the completion handler is called before loading ads. This ensures that all mediation adapters are initialized.

Select an Ad Format

Google Mobile Ads SDK is now imported and you're ready to implement an ad. Ad Manager offers a number of different ad formats, so you can choose the one that best fits your app's user experience. Popular ad formats include banner and interstitial ads.

By following these steps, you'll be well on your way to creating a swift app development project that effectively utilizes Google Mobile Ads SDK for swift app development.