# Trouble Implementing AdMob

**URL:** https://discourse.processing.org/t/trouble-implementing-admob/4474
**Category:** Processing for Android
**Created:** [October 15, 2018, 1:53am UTC](https://discourse.processing.org/t/trouble-implementing-admob/4474 "2018-10-15T01:53:36Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![MatterLinx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matterlinx/32/3121_2.png) [@MatterLinx](https://discourse.processing.org/u/MatterLinx)
#### Post date: [October 15, 2018, 1:53am UTC](https://discourse.processing.org/t/trouble-implementing-admob/4474/1 "2018-10-15T01:53:36Z")

</div>

_ **Hello!** _

I’m having trouble implementing AdMobs in processing.

**I have looked at these posts regarding the issue:**

- [https://forum.processing.org/two/discussion/16686/how-to-add-admob/p2](https://forum.processing.org/two/discussion/16686/how-to-add-admob/p2)
- [https://forum.processing.org/two/discussion/24396/what-are-the-exact-steps-to-add-admob-to-my-app](https://forum.processing.org/two/discussion/24396/what-are-the-exact-steps-to-add-admob-to-my-app)

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:**

```auto
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:**

```auto
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:**

```auto
<?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:

```auto
: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!**

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [October 15, 2018, 7:19am UTC](https://discourse.processing.org/t/trouble-implementing-admob/4474/2 "2018-10-15T07:19:09Z")

</div>

@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

---

<div class="post-metadata">

### Author: ![MatterLinx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matterlinx/32/3121_2.png) [@MatterLinx](https://discourse.processing.org/u/MatterLinx)
#### Post date: [October 16, 2018, 2:27am UTC](https://discourse.processing.org/t/trouble-implementing-admob/4474/3 "2018-10-16T02:27:59Z")

</div>

I checked the zip file that I have download from:

- [https://dl-ssl.google.com/android/repository/google\_play\_services\_8298000\_r28.zip](https://dl-ssl.google.com/android/repository/google_play_services_8298000_r28.zip)

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:

```auto
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED

```

Am I missing something obvious here?

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [October 16, 2018, 7:23am UTC](https://discourse.processing.org/t/trouble-implementing-admob/4474/4 "2018-10-16T07:23:04Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![MatterLinx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matterlinx/32/3121_2.png) [@MatterLinx](https://discourse.processing.org/u/MatterLinx)
#### Post date: [October 16, 2018, 3:54pm UTC](https://discourse.processing.org/t/trouble-implementing-admob/4474/5 "2018-10-16T15:54:29Z")

</div>

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

```auto
<?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? 🤔

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [October 16, 2018, 4:18pm UTC](https://discourse.processing.org/t/trouble-implementing-admob/4474/6 "2018-10-16T16:18:51Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![MatterLinx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matterlinx/32/3121_2.png) [@MatterLinx](https://discourse.processing.org/u/MatterLinx)
#### Post date: [October 16, 2018, 8:02pm UTC](https://discourse.processing.org/t/trouble-implementing-admob/4474/7 "2018-10-16T20:02:37Z")

</div>

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. 👍

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!

---

<div class="post-metadata">

### Author: ![androidtuts](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@androidtuts](https://discourse.processing.org/u/androidtuts)
#### Post date: [March 31, 2021, 9:18am UTC](https://discourse.processing.org/t/trouble-implementing-admob/4474/8 "2021-03-31T09:18:22Z")

</div>

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](https://www.learnvern.com/unit/android-components-content-providers)

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [March 31, 2021, 5:55pm UTC](https://discourse.processing.org/t/trouble-implementing-admob/4474/9 "2021-03-31T17:55:32Z")

</div>

@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:

```auto

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);
};

```
