How to add Google AdMob to android sketch?

I have found a way to include the current AdMob ads in your sketch app. I would recommend adding your ads last, because these changes will have to be done in android studio. I have added my working processing sketch so you can go through these steps with it. In the sketch I have attached, I have commented all the code that we will have to add in android studio.

  1. Make sure you are in android processing mode, then click file at the top of the screen, then export android project.
  2. Open android studio and click import project. Find your sketch folder. In the folder you should see a folder that say android and has the same logo as android studio. Select it and click ok.
  3. It is going to ask you if you want to recreate the wrapper. Click ok.
  4. After it builds, in the top left corner, click the app folder, than manifests, and open your manifests file.
  5. Remove this line:
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="28"/>
  1. At the bottom right corner there should be a box that says plugin update recommended. Click update.
  2. At the top of the screen go to the refactor tab, then select migrate to androidX. It is up to you if you want to keep a .zip or not. Then click Migrate. At the bottom of the screen click Do Refactor.
  3. At the top of the page, click the Build tab and then Clean Project.
  4. On the left hand side, click Gradle Scripts, then build.gradle (Module: app). At the bottom of the file you will see dependencies. Add this inside the dependencies brackets at the bottom:
implementation 'com.google.android.gms:play-services-ads:19.3.0'
  1. At the top of this file it will ask you to sync now, go ahead and sync.
  2. Go back to the android manifest and add this code under the activity:
<meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>

Make sure that you put your Google Admob App ID for the android value!
Your android manifest should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="processing.test.ads">
    <application android:icon="@mipmap/ic_launcher" android:label="Ads">
        <activity android:name=".MainActivity" android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>
</manifest>
  1. On the left hand side, go to app, than java, and than Ads (or your sketch name) and open the file. Add the imports that I have commented out to the imports… area and make sure you uncomment them.
  2. Next uncomment the RelativeLayout, the InterstitialAd, and the RewardedVideoAd.
  3. Under mouseReleased(), uncomment the Play_Reward_Ad(), the Show_Interstitial_Ads(), and the Banner_On_Off().
  4. Everything that I have commented out below that, go ahead and uncomment.
    Now you can build and install on your device or install on the virtual phone. The onRewarded() call will reward your user when they finish watching the add.
  5. When you are done testing, make sure to switch out the test ad ids with your ad ids. Other than that, you are all set.

I hope this helps you out! As mentioned, the processing sketch I created is attached below and can be modified to fit your sketches:

1 Like