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/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:
-
I navigated to: C:\Users\user\AppData\Local\Android\Sdk\extras\google\m2repository\com\google\android\gms\play-services-ads\11.0.4
-
I then copied: play-services-ads-11.0.4.aar
-
I change the name to: play-services-ads-11.0.4.zip
-
Then I extracted the zip file, and inside there was a jar file called: classes
-
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!