I have created a game I would like to publish, but I need to add ads to it. I have looked through a lot of posts about adding Google AdMob to a sketch, but all of the post are out dated and when applied, they do not work. I have attached a very small sketch that includes a button and a counter. Can anyone help me get an ad to be displayed when pressing the button?
@akenaton
I had looked at your code, but could not seem to get it to run. I canât get it to run with your code you have linked either. I have included the google play services version 28 .jar file in my code folder, as well as included the android permissions for access network state, access wifi state, internet, read phone state, set orientation. My build fails with these warnings:
Execution failed for task â:app:transformDexArchiveWithExternalLibsDexMergerForDebugâ.
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
So I compared my android manifest with your example manifest from 4 years ago, and they arenât identical, but I tried to recreate it as much as possible. Here is my manifest:
@akenaton
I have changed the value in my android manifest, but I get the same build error. I appreciate the fast response, thank you! Now what should I try?
@Lucas === the error you get seems to be related to the .jar; i have to give a look at that as soon as possible but as i have tested my code eight days ago for the other guy i am sure that it worksâŚ
I have managed to get the test ad after exporting to android studios and changing a few things. I will post a list of step as well as any working files. I would still like to get it to work in processing, but for now it will work. If you are able to figure out anything akenaton, that would be excellent to add! I am going to mess around with the code a little more and later I will upload the steps and working files. Thank you for your help as well as the code templates akenaton!
I was able to get the code to work after adding one additional line in android studios. It appears that I was using too many methods. Google can explain it better than me:
Here are the steps that are needed to get this code up and running:
Put the google-play-services.jar file in the code folder, which I have attached. In the folder I have attached, it is already located in the proper folder.
@akenaton
I was able to get it working with the procedure above. I would still like for it to run in processing to make testing faster. If you have any ideas, that would be great! Also, have you been able to add rewarded videos to one of your sketches? I tired to convert the code by google into one to work with processing but I couldnât get very far. If you have, could you post your working code? Thank you again for all of your help!
For everyone who is following along, I have been able to get an Interstitial Ad to display. However, after closing the ad and returning back to the sketch, the sketch/app is no longer responsive for about a minute. If anyone can help me understand or fix this issue, that would be great. I am going to continue to work on the code. Once I get a working version, I will create a list of steps like I did for the banner ad and add working files. I plan on creating a file and steps to easily allow everyone to add the three types of admob ads to their projects.
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.
Make sure you are in android processing mode, then click file at the top of the screen, then export android project.
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.
It is going to ask you if you want to recreate the wrapper. Click ok.
After it builds, in the top left corner, click the app folder, than manifests, and open your manifests file.
At the bottom right corner there should be a box that says plugin update recommended. Click update.
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.
At the top of the page, click the Build tab and then Clean Project.
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:
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.
Next uncomment the RelativeLayout, the InterstitialAd, and the RewardedVideoAd.
Under mouseReleased(), uncomment the Play_Reward_Ad(), the Show_Interstitial_Ads(), and the Banner_On_Off().
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.
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: