App prerequisites
- Make sure that your app's build file uses the following values:
- Minimum SDK version of
19or higher - Compile SDK version of
33or higher
Add the dependencies for the Google Mobile Ads SDK to your module's
app-level Gradle file, normally
app/build.gradle:dependencies { implementation ("com.google.android.gms:play-services-ads:22.6.0") }
- Add your AdMob app ID, as identified in the AdMob web interface, to your app's
AndroidManifest.xmlfile.
- To do so, add a
<meta-data>tag withandroid:name="com.google.android.gms.ads.APPLICATION_ID".
- You can find your app ID in the AdMob web interface. For
android:value, insert your own AdMob app ID, surrounded by quotation marks.
<manifest> <application> <!-- Below this is test id replace for value tag--> <!-- 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>
- In a real app, replace the sample app ID with your actual AdMob app ID. You can use the sample ID if you're just experimenting with the SDK in a Hello World app.
- Also, note that failure to add the
<meta-data>tag exactly as shown results in a crash with the message:
The Google Mobile Ads SDK was initialized incorrectly.
(Optional)
Declare
AD_ID permission for previous versions to work with Android 13.Initialize the Google Mobile Ads SDK
Before loading ads, have your app initialize the Google Mobile Ads SDK by
calling
MobileAds.initialize()- which initializes the SDK and calls back a completion listener once initialization is complete, or after a 30-second timeout. This needs to be done only once, ideally at app launch.
Here's an example of how to call the
initialize() method in an Activity:Example MainActivity (excerpt)
import com.google.android.gms.ads.MobileAds class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // To Intialize AdMob MobileAds.initialize(this) {} } }
Select an ad format
The Google Mobile Ads SDK is now imported and you're ready to implement an ad.
AdMob offers a number of different ad formats, so you can choose the one that best fits your app's user experience.
Banner
- Rectangular ads that appear at the top or bottom of the device screen.
- Banner ads stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time. If you're new to mobile advertising, they're a great place to start.
Documentation: Implement banner ads
Interstitial
- Full-screen ads that cover the interface of an app until closed by the user.
- They're best used at natural pauses in the flow of an app's execution, such as between levels of a game or just after a task is completed.
Documentation: Implement interstitial ads
Native
- Customizable ads that match the look and feel of your app.
- You decide how and where they're placed, so the layout is more consistent with your app's design.
Documentation : Implement native ads
Rewarded
- Ads that reward users for watching short videos or interacting with playable ads and surveys. Used for monetizing free-to-play apps.
Documentation : Implement rewarded ads




