I cant bring myself to share my entire sketch, as I am planning on releasing it on the play store.
When I implement this code into any of my pre-existing android sketches, it causes the errors mentioned above.
But when I put it into a new sketch, it causes no errors, running fine.
import android.os.Bundle;
import android.view.Window;
import android.widget.RelativeLayout;
import android.app.Activity;
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();
RelativeLayout adsLayout = new RelativeLayout(this.getActivity());
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.MATCH_PARENT);
AdView adView = new AdView(this.getActivity());
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
adsLayout.addView(adView);
AdRequest newAdReq = new AdRequest.Builder()
.build();
adView.loadAd(newAdReq);
window.addContentView(adsLayout, lp2);
};
It needs a few additional things to work:
this file to be placed in the /sketch/code folder to work
<meta-data android:name="com.google.android.gms.version" android:value="8298000"/>
in the <application> bit of the android manifest
I may have figured something out.
After exporting the project to android studio and doing the usual fixes required following that, I got this error: Cannot fit requested classes in a single dex file (# methods: 68587 > 65536)
and somewhere else in the errors this: The number of method references in a .dex file cannot exceed 64K.
the solution to this normally according to this stackoverflow is to add multiDexEnabled true in build.gradle
This worked but I want to continue working in processing for now.
I will mark this as a solution and start a new topic for that.