Trouble Implementing AdMob

Hello!

I’m having trouble implementing AdMobs in processing.

I have looked at these posts regarding the issue:

From the information that I have gathered, I have a few issues.

In regards to the googlePlayServices library, I understand that people have been using revision 29 and below because there is no libproject folder in revision 30 and above. I also am aware that the googlePlayServices library has been split into separate files revision 30 and above. I wanted to use the most recent revision of google play services, so I tried to extract the extract a jar file through the following steps:

  1. I navigated to: C:\Users\user\AppData\Local\Android\Sdk\extras\google\m2repository\com\google\android\gms\play-services-ads\11.0.4

  2. I then copied: play-services-ads-11.0.4.aar

  3. I change the name to: play-services-ads-11.0.4.zip

  4. Then I extracted the zip file, and inside there was a jar file called: classes

  5. I placed this jar file into the code folder of my sketch

After all of this, these imports could not be resolved:

import com.google.ads.*;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.MobileAds;

So, after failing to import what I needed from the google play services library, I decided to download revision 28 and use the googlePlayServices jar file located in the libproject folder. This worked, and the imports were all resolved.

This is the link I got it from: ttps://dl-ssl.google.com/android/repository/google_play_services_8298000_r28.zip

I am using this code, which was provided by akenaton:

import android.os.Looper;//for setup() if needed
import android.os.Bundle;
import android.view.Window;
import android.widget.RelativeLayout;
import android.app.Activity;
import com.google.ads.*;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.MobileAds;


public void setup() {
  fullScreen();
}

public void draw() {
  background(0);
}

@ Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  //here you get the window
  Window window = getActivity().getWindow();
  //here you add a layout to your window; working with AS or Eclipse you can skip that because you can modify the xml; with processing you have to do that by code
  RelativeLayout adsLayout = new RelativeLayout(this.getActivity());
  //here you set the params for your layout
  RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.MATCH_PARENT);

  // now you create your View

  AdView adView = new AdView(this.getActivity());

  adView.setAdSize(AdSize.BANNER);
  
  // TEST UNIT ID: ca-app-pub-3940256099942544
  adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");

  // here you add the view to the layout and build your AdRequest
  adsLayout.addView(adView);
  AdRequest newAdReq = new AdRequest.Builder().addTestDevice("I have my device id here").build();

  adView.loadAd(newAdReq);

  ///and finally ad the whole stuff to your window
  window.addContentView(adsLayout, lp2);
};

Here is my manifest:

<?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="">
    <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="26"/>
    <application android:icon="@drawable/icon" android:label="">
        <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>
        <activity android:configChanges="keyboard|keyboardHidden|orientation" android:name="com.google.ads.AdActivity"/>
        <meta-data android:name="com.google.android.gms.version" android:value="8298000"/>
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.SET_ORIENTATION"/>
</manifest>

Unfortunately the project does not build. Here is where it failed:

:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED

I think this has to do with compatibility issues with newer SDK versions, or perhaps I have done something wrong in my manifest.

I any case, I would really appreciate it if someone could assist me. If possible, I would love to get this working with the most current revision of google play services.

Thank you advance!

@MatterLinx===

  • the value you have put for com.google.android.gms.version does not seem to me to be the good one (it is not the rev value): that is the first point to check

I checked the zip file that I have download from:

The name of the zip file is google_play_services_8298000_r28

From my understanding the gms version is in the file name, which in this case is: 8298000
This android:value did not work, so I tried 8298000_r28, and 28 as the android:value.

Everything I have tried for the gms value has resulted in the same failure in the build:

:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED

Am I missing something obvious here?

@MatterLinx===
normally this value is written in the version.xml file which (normally) is in a sub folder of the sdk called google…i dont know wether you have it when downloading the.zip but i think it s possible.

I found the file that you were mentioning, here it is:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="google_play_services_version">8298000</integer>
</resources>

I was using the correct value all along. What could be the issue now? :thinking:

@MatterLinx===
ok, so that is the good value ; as for now i cannot guess what is the problem, i have to verify directly with the code, but i begin to think that there is a compatibility issue as you told, because the code must work.

It’s inevitable that this version will lose compatibility over time. I think that’s it would be best to figure out how to use the newest version of Google play services with processing. I want to solve this issue once and for all.

@akenaton, I know that you have answer this question multiple times over the years. By the end of this I would love it if anyone could simply read this thread and be able to implement admobs. :+1:

As I said in my original post, I was able to convert play-services-ads-11.0.4.aar into a zip file. I just need help with setting it up to work with processing.

By the way, thanks for the help thus far!

1 Like

The Value you set for com.google.android.gms is not perfect as per my knowledge. after all you can check it on other forum.

Read More: Content Providers in Android

@MatterLinx === though the code you are using (from me) is rather old i am sure that it must run with your Manifest and your .jar; i have tested it (MM && nougat) and i see the banner. So there is another problem; 1) are you sure that the permissions are granted on runtime? -2) Question of “compatibility” does not seem to be the culprit: the new package for ads is exactly the same (of course for other playservice it has changed) and so the .jar must work. Of course i suppose that you downloaded the good one and put the googlePlayService .jar in the code folder. Below you can find the code i have tested (from this post) with your Manifest. try it:


import android.os.Looper;//for setup() if needed
import android.os.Bundle;
import android.view.Window;
import android.widget.RelativeLayout;
import android.app.Activity;
//import com.google.ads.*;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.MobileAds;


public void setup() {
  fullScreen();
}

public void draw() {
  background(0);
}

@ Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  //here you get the window
  Window window = this.getActivity().getWindow();
  //here you add a layout to your window; working with AS or Eclipse you can skip that because you can modify the xml; with processing you have to do that by code
  RelativeLayout adsLayout = new RelativeLayout(this.getActivity());
  //here you set the params for your layout
  RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.MATCH_PARENT);

  // now you create your View

  AdView adView = new AdView(this.getActivity());

  adView.setAdSize(AdSize.BANNER);
  
  // TEST UNIT ID: ca-app-pub-3940256099942544
  adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");

  // here you add the view to the layout and build your AdRequest
  adsLayout.addView(adView);
  AdRequest newAdReq = new AdRequest.Builder().addTestDevice("I have my device id here").build();

  adView.loadAd(newAdReq);

  ///and finally ad the whole stuff to your window
  window.addContentView(adsLayout, lp2);
};