Skip to content

Instantly share code, notes, and snippets.

@aiekick
Forked from Bigfoot71/AndroidManifest.xml
Created June 3, 2025 18:05
Show Gist options
  • Save aiekick/b91e8b35ce5dba4b8f194daed1847c33 to your computer and use it in GitHub Desktop.
Save aiekick/b91e8b35ce5dba4b8f194daed1847c33 to your computer and use it in GitHub Desktop.
Example of AdMob integration in Raymob

AdMob Integration in the Raymob Repository

This gist serves as a guide on how to integrate AdMob into your Raymob project. For the actual Raymob repository, please refer to Raymob.

Please note that this gist focuses on the integration of interstitial ads, but the process is similar for other types of ads as well.

If you have any doubts, please consult the AdMob Android Quick Start Guide for further information.

To integrate AdMob into your project, follow these steps:

  1. Add the following line to the end of the app/build.gradle file, under dependencies:
    implementation 'com.google.android.gms:play-services-ads:22.4.0'
  2. Edit the existing NativeLoader.java and app/AndroidManifest.xml files in your project with the corresponding files provided in this gist.
  3. Add the example file admob.h to your project.
  4. Think about setting android.useAndroidX to true at the beginning of your gradle.properties; you'll need it for using the @NonNull annotations.

That's it! AdMob should now be successfully integrated into your Raymob repository.

NOTE: The AdMob identifiers provided in this example are meant for testing purposes and are provided by Google. Remember to replace them with your own identifiers.

Additional Information

If your application is intended to be available only on the Google Play Store, you can also use com.google.android.gms:play-services-ads-lite:22.4.0 instead of com.google.android.gms:play-services-ads:22.4.0.

This implementation will be much lighter and will help reduce the size of your application. For more information, please refer to this link: https://developers.google.com/admob/android/lite-sdk?hl=en

#ifndef ADMOB_H
#define ADMOB_H
#include "raymob.h"
void RequestInterstitialAd(void);
bool IsInterstitialAdLoaded(void);
void ShowInterstitialAd(void);
#ifdef ADMOB_IMPL
void RequestInterstitialAd(void)
{
const jobject nativeLoaderInstance = GetNativeLoaderInstance();
if (nativeLoaderInstance != NULL)
{
JNIEnv *env = AttachCurrentThread();
jclass nativeLoaderClass = (*env)->GetObjectClass(env, nativeLoaderInstance);
jmethodID method = (*env)->GetMethodID(env, nativeLoaderClass, "requestInterstitialAd", "()V");
(*env)->CallVoidMethod(env, nativeLoaderInstance, method);
DetachCurrentThread();
}
}
bool IsInterstitialAdLoaded(void)
{
bool adLoaded = false;
const jobject nativeLoaderInstance = GetNativeLoaderInstance();
if (nativeLoaderInstance != NULL)
{
JNIEnv* env = AttachCurrentThread();
jclass nativeLoaderClass = (*env)->GetObjectClass(env, nativeLoaderInstance);
jmethodID method = (*env)->GetMethodID(env, nativeLoaderClass, "isInterstitialAdLoaded", "()Z");
adLoaded = (bool)((*env)->CallBooleanMethod(env, nativeLoaderInstance, method));
DetachCurrentThread();
}
return adLoaded;
}
void ShowInterstitialAd(void)
{
jobject nativeLoaderInstance = GetNativeLoaderInstance();
if (nativeLoaderInstance != NULL)
{
JNIEnv* env = AttachCurrentThread();
jclass nativeLoaderClass = (*env)->GetObjectClass(env, nativeLoaderInstance);
jmethodID method = (*env)->GetMethodID(env, nativeLoaderClass, "showInterstitialAd", "()V");
(*env)->CallVoidMethod(env, nativeLoaderInstance, method);
DetachCurrentThread();
}
}
#endif //ADMOB_IMPL
#endif //ADMOB_H
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<!-- Add this for apps targeting Android 13 or higher & GMA SDK version 20.3.0 or lower -->
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
<application>
<activity>
<!-- [...] -->
</activity>
<!-- Add this for AdMob (change the test ID on your own when the time comes) -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
</application>
</manifest>
package com.raylib.raymob;
/* Add these imports */
import androidx.annotation.NonNull;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
/* Add this to your class */
public class NativeLoader extends NativeActivity {
private InterstitialAd mInterstitialAd;
/* [...] */
public void requestInterstitialAd() {
AdRequest adRequest = new AdRequest.Builder().build();
runOnUiThread(new Runnable() {
@Override
public void run() {
// This is the test ID for interstitial ads; replace it with your own when the time comes.
InterstitialAd.load(NativeLoader.this, "ca-app-pub-3940256099942544/1033173712", adRequest,
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
mInterstitialAd = interstitialAd;
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
mInterstitialAd = null;
}
}
);
}
});
}
public boolean isInterstitialAdLoaded() {
return mInterstitialAd != null;
}
public void showInterstitialAd() {
if (mInterstitialAd != null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mInterstitialAd.show(NativeLoader.this);
mInterstitialAd = null;
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment