A modern Android sample project that demonstrates how to integrate Google AdMob banner, interstitial, and rewarded ads with the Google Mobile Ads SDK. The project is intentionally small and focused, making it useful for learning the ad lifecycle, testing demo ad units, and adapting the implementation to a production app.
This repository uses Google's official sample ad unit IDs so you can run and test the app safely. Replace them with your own AdMob App ID and ad unit IDs before publishing an app to Google Play.
This app contains practical examples for the three most common AdMob ad formats used in Android apps:
- Banner Ads displayed at the bottom of the main screen.
- Interstitial Ads shown as a full-screen transition before opening the second screen.
- Rewarded Ads shown as a full-screen rewarded experience that reports the earned reward to the user.
The implementation is designed to be easy to read and extend. It uses ViewBinding, explicit ad-loading functions, full-screen content callbacks, and banner lifecycle methods so each ad type has a clear responsibility.
The project has been updated for a modern Android development setup:
| Area | Version / Choice |
|---|---|
| Android Gradle Plugin | 9.2.0 |
| Gradle Wrapper | 9.4.1 |
| Kotlin Android Plugin | 2.4.0 |
| Compile SDK | 36 |
| Target SDK | 36 |
| Minimum SDK | 23 |
| Java / Kotlin Toolchain | 17 |
| Google Mobile Ads SDK | 25.3.0 |
| UI Toolkit | XML layouts with Material Components |
Key modernization highlights:
- Migrated Gradle configuration to the plugins DSL.
- Centralized repository configuration in
settings.gradle. - Updated SDK targets for Android 16 / API 36.
- Replaced legacy Android support dependencies with AndroidX dependencies.
- Removed unnecessary multidex configuration for the current minimum SDK.
- Added Material Components for a cleaner, modern sample UI.
- Updated ad loading and full-screen callback handling for clearer behavior.
- Added banner lifecycle handling with
resume(),pause(), anddestroy().
- Language: Kotlin
- UI: XML layouts, ConstraintLayout, Material Components
- Ads: Google Mobile Ads SDK for Android
- Build System: Gradle with Android Gradle Plugin
- Architecture: Simple Activity-based demo flow
AdMobApp/
βββ app/
β βββ build.gradle
β βββ src/main/
β βββ AndroidManifest.xml
β βββ java/com/halil/ozel/admobapp/
β β βββ MainActivity.kt
β β βββ SecondActivity.kt
β βββ res/
β βββ layout/
β β βββ activity_main.xml
β β βββ activity_second.xml
β βββ values/
β βββ colors.xml
β βββ strings.xml
β βββ styles.xml
βββ build.gradle
βββ settings.gradle
βββ gradle/wrapper/gradle-wrapper.properties
Important files:
MainActivity.ktinitializes Mobile Ads, loads all ad formats, shows interstitial/rewarded ads, and manages banner lifecycle events.activity_main.xmlcontains the modern demo UI and the bannerAdView.AndroidManifest.xmlcontains the AdMob App ID metadata required by the Mobile Ads SDK.app/build.gradledefines the Android SDK targets and dependency versions.
| Format | Where It Appears | Behavior |
|---|---|---|
| Banner | Bottom of the main screen | Loads after MobileAds.initialize() and follows the Activity lifecycle. |
| Interstitial | Main screen button | Shows a full-screen ad when available, then opens the second screen after dismissal. |
| Rewarded | Main screen button | Shows a rewarded ad when available, displays the reward amount/type, then opens the second screen after dismissal. |
MainActivityinflates the layout usingActivityMainBinding.MobileAds.initialize()is called duringonCreate().- After initialization, the app starts loading:
- the banner ad,
- the interstitial ad,
- the rewarded ad.
- When the user taps Show Interstitial Ad, the app:
- shows the cached interstitial ad if it is ready,
- registers a full-screen callback,
- reloads the next interstitial after dismissal or show failure,
- opens
SecondActivitywhen the ad flow is complete.
- When the user taps Show Rewarded Ad, the app:
- shows the cached rewarded ad if it is ready,
- displays the reward amount and reward type,
- reloads the next rewarded ad after dismissal or show failure,
- opens
SecondActivitywhen the ad flow is complete.
- If an ad is not ready yet, the app shows a short message, starts loading another ad, and continues the demo flow.
Install the following tools before opening the project:
- Android Studio Meerkat or newer.
- Android SDK Platform 36.
- JDK 17 or a newer JDK compatible with the configured Gradle/AGP versions.
- A device or emulator with Google Play services.
git clone https://github.com/halilozel1903/AdMobApp.git
cd AdMobApp- Open Android Studio.
- Select Open and choose the project folder.
- Wait for Gradle sync to finish.
- Select an emulator or physical device.
- Run the
appconfiguration.
Build the debug APK from the command line:
./gradlew assembleDebugInstall the debug APK on a connected device:
./gradlew installDebugRun unit and instrumentation checks as needed:
./gradlew test
./gradlew connectedAndroidTestThe project currently uses Google sample ad IDs. These are safe for development and do not generate real revenue.
Before releasing your own app:
- Create or open your app in the AdMob console.
- Replace the AdMob App ID in
AndroidManifest.xml:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-your-app-id" />- Replace the banner ad unit ID in
activity_main.xml:
app:adUnitId="ca-app-pub-your-banner-unit-id"- Replace the interstitial and rewarded ad unit IDs in
MainActivity.kt:
private const val INTERSTITIAL_AD_UNIT_ID = "ca-app-pub-your-interstitial-unit-id"
private const val REWARDED_AD_UNIT_ID = "ca-app-pub-your-rewarded-unit-id"- Test thoroughly with test devices before publishing.
This sample includes several practices that are useful in real Android apps:
- Uses official Google test ad IDs during development.
- Loads full-screen ads ahead of time instead of loading only at click time.
- Keeps nullable references for interstitial and rewarded ads because loaded ads are single-use.
- Clears consumed full-screen ads and reloads the next ad after dismissal or failure.
- Uses
FullScreenContentCallbackto coordinate post-ad navigation. - Manages banner ad lifecycle with Activity lifecycle methods.
- Keeps UI strings in resources for easier localization.
- Uses Material Components for a more modern interface.
Make sure Android Studio has installed the Android SDK Platform 36 package and that your network can access Google's Maven repository and the Gradle distribution service.
Check the following:
- The device or emulator has Google Play services installed.
- The app has internet access.
- You are using test ad IDs during development.
- You waited long enough for the ad request to complete.
- Logcat does not show AdMob configuration or policy errors.
Verify that AndroidManifest.xml contains a valid com.google.android.gms.ads.APPLICATION_ID metadata entry.
This is expected behavior. Full-screen ads are single-use, so the sample reloads a new ad after the previous one is dismissed or fails to show.
- Android Admob Ad π¦
- Android Banner Ad π΅
- Android Interstitial Ad πΆ
- Android Rewarded Ad π·
If this project helps you, you can support the maintainer with a coffee. β
MIT License
Copyright (c) 2022 Halil OZEL
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.




