We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello all!
I am new to coding, been only doing it daily for a month or two, and I just finished my first game for android. I would like to add it to the Google Play Store with AdMob. I have registered for AdMob, and now I need to incorporate the ads to my code, however, I have no idea how to do that.
I already saw https://forum.processing.org/two/discussion/16686/how-to-add-admob and I read through all of it twice, but am still completely at a loss. The topic is really messy and riddled with trials and errors, and has code and symbols that I have never used nor understood at all, making its contents practically unreadable for someone with as little coding experience as me. What is a manifest? What's a .jar file, why do I need it and where do I get it?
I put so much effort into my game and I am so eager to see it in the store, but I just can't get past this final step.
If some kind soul could give me and, likely, the thousands of other newcomers looking for an answer, a step-by-step walkthrough of exactly what I need to download, where I need to download it, and provide an organized snippet of code that I can adapt for my program, words can't describe how grateful I would be.
Thank you all in advance!
Answers
https://developers.google.com/admob/android/quick-start
This is the default AdMob guide that I have gone through but also don't understand as it's made for Android Developer Studio.
"The topic is really messy and riddled with trials and errors, and has code and symbols that I have never used nor understood at all, making its contents practically unreadable for someone with as little coding experience as me."
Welcome to programming.
@randomdude===
first step: get your Ad unit id from your admob account; it should be something like ca-app-pub-(+ a lot of numbers); if only for testing use the ad unit id given by Google: ca-app-pub-3940256099942544~3347511713; then choose a format among the 3 provided: as for now choose "banner" which is the more simple.
second step: use the code i have already given and that i give again:
step 3: modify your Manifest a) adding permissions:::
all these details are explained in the link you posted in this forum and you can find an example i have given for the Manifest;
step 4: verify that googlePlayServices is installed in your SDK (SDK menu, Extras)
step 5: try and see wether the imports can be solved; if not (that was the case in the discussion you have seen) get the .jar from the url i have given in the same discussion, create a folder "code" in your sketch and add the .jar. When you download it it is a .zip and its name contains the version number you have to write in your Manifest.
@akenaton THANK YOU!
Where in my code should I place the manifest?
@randomdude===
you have only to edit the Manifest; nothing to do (in this case) by code.
Ooh I see.
And does it matter where in the manifest I add these permissions (start, middle, end)?
No need to modify the manifest directly. Instead, if you are using Processing, go to the Android in the menu bar and click on sketch permissions. There you can check the permission you want to enable. This action will update your manifest for you.
***Edit: Here I am only referring to permissions btw.
Kf
@kfrajer===
you are right for permissions, but in this case it s necessary to edit the manifest in order to add (metadata) the com.google.android.gms.version required.
I can't compose the metadata on my own. Is it too much to ask to give a bit more detailed explanation on how to add metadata?
@randomdude===
yes that is possible:: see the link you posted here and see my manifest example... and be conscious that you ask for things rather complicated && know nothing about android
@akenaton
I don't just know nothing about Android - I basically know nothing about coding altogether.
I started merely a month ago. But I am a quick learner and have gotten pretty far already, relying (and owing) only to experienced programmers like you who are willing to help.
I don't know what I can do to show my gratitude for your help. It is in my nature to want to know more, so I will probably keep asking rather complicated things. If you think I know too little to achieve the things I want to achieve, you don't have to bother to answer. However, so far I have been able to grasp everything I ask about if somebody provides a good description.
AdMob is clear to me now and has been successfully implemented in my code.
THANKS A LOT FOR EVERYONE'S HELP!
@randomdude===
be happy when coding! but think= learning is for each day!
@randomdude===
&& never think that you "KNOW"
@akenaton
I am having tremendous fun while coding, that is why I am so eager to get better -- FASTER. I have so many ideas that I want to see come to life!! I just need the experience and knowledge. And I can acquire experience and knowledge much more efficiently by relying on others sharing theirs with me.
"If I have seen further it is by standing on the shoulders of giants." -Isaac Newton
@akenaton ===
For some reason after reinstalling processing it stopped recognizing the com.google imports no matter what I do. This 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="ca-app-pub-3940256099942544/6300978111"/> </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>
I got the ca-app-pub for testing from the admob site.
Maybe it's a problem with the .jar file. The .zip that you have sent a link to in the other topic has a LOT of files in it -- which one exactly do I need to put in my code folder? I'm confused
@randomdude===
error in your manifest for metadata: as value you are puting your unitId and not your gms.version...
@akenaton===
Thanks!
Strange, it's not the same gms.version that I had before I reinstalled Processing...
This new SDK is really confusing. I tried to find the gms version and all I found was this manifest inside the gms folder:
I'm not sure which one is the actual version that I should be using (not familiar with xml). Do you have any idea?
@randomdude===
try to put "@integer/google_play_services_version" instead of any number
normally (i am not sure if it is still ok) the exact integer value is here= google-play-services_lib>res>values>version.xml and you can use this; yet, harcoding is bad as this value can change in the future.
looking to your xml i think that the actual value (last updated) is : "20170........."; try this value.
@akenaton
I tried both the number after lastUpdated and @integer/google_play_services (found the second on stackOverflow) and none of them work.
The weird thing is that the imports dont give an error, but their functions do. I'm not sure if it's a processing bug. Here is a sample with your code.
However when I start the sketch I do get this in console:
No library found for com.google.android.gms.ads No library found for com.google.android.gms.ads No library found for com.google.android.gms.ads No library found for com.google.android.gms.ads
Followed by a long error.
Maybe it won't work with this SDK. Can you recommend me an SDK? What SDK are you using?
Can anyone recommend an SDK that has a clear gms version and works with AdMob?
@randomdude===
are you sure that googlePLayservices is installed in your SDK (folder "extras")???
@akenaton
There is a folder named 'google' in my SDK's extras folder. There are multiple folders inside folders but among all the folders inside the 'google' folder there is one named 'gms' and inside there are many folders called 'play-services', 'play-services-ads', 'play-services-all-wear', etc, so presume google play services is installed.
Can you recommend me a new SDK please?
@randomdude=== installed: verify with the sdk manager
@akenaton ===
That's the problem, I can't seem to find an sdk manager in this sdk.....
That is why I have to do everything manually.
@randomdude===
I dont think that you have a "special" SDK; so go to "tools" and launch "android": that launches the SDK manager.
@akenaton===
I tried that long ago - it closes immediately after it launches. It simply will not open.
I think that the best idea is to reinstall everything again and try a new SDK...
@randomdude===
anyway dont install your new SDK with P5: download it and install it manually...
@akenaton===
I tried downloading from here https://developer.android.com/studio/index.html#downloads Tried getting the SDK under 'Get Just the Command Line Tools' and its manager also did not open. I found this post on StackOverflow: https://stackoverflow.com/questions/14504325/cant-get-android-sdk-manager-to-open And I did find 'find_java.bat' and edited it as the post said but it still does not help, SDK manager will not open.............. It feels like every step forward takes me 2 steps backwards :(
@randomdude===
When you edit the .bat is the path to java the good one? When you try to run android from the command line is there some error message?
@akenaton===
I thought it’s the good one but apparently I don’t have a java.exe in my pc... I’m sorry for my inexperience.
What should I do? What executable exactly should I make a path to?
@randomdude===
take the path in your.bat
verify that you find, following the path, a folder with jdk1.8 as name; if not of course the manager cannot run
A folder with the name 'jdk1.8' or anything with 'jdk' does not exist in my computer.
This is how the .bat looked before any editing (no path), if it helps:
@randomdude===
then android manager cannot run:: download && instal the jdk for your OS (from oracle, line 59 in your .bat)
@akenaton
I downloaded and installed it. I tried opening android.bat both without editing my find_java and after editing find_java with the proper path - both times I get a 'This app can't run on your PC" message .....................
@akenaton===
Reinstalled processing all over again, downloaded new SDK; android.bat again did not open - again no error, just getting a window appear for 0.1 seconds then it disappears and nothing happens like before.
Edited find_java.bat with the proper path. Still same thing - window appears and disappears immediately.
I also tried this:
Computer -> Advanced system settings -> Environment variables -> PATH -> edit: make sure they are in this order: C:\Program Files\Java**my JDK folder**\bin;%SystemRoot%\system32
Did not change a thing.
I also tried EVERYTHING here:: https://stackoverflow.com/questions/5199811/android-sdk-manager-wont-open
NOTHING worked. I don't even have 'set java_exe' in my android.bat!
This is the android.bat:
Also the oracle link installed jdk-9.0.1 not jdk1.8 or jdk1.7 ....
@randomdude===
are you sure that it can run with your OS??? - Have you downloaded the good version for your OS (64 or X356????)
@akenaton===
Yes, 10000% sure. I have Windows 10 64bit, downloaded the 64bit version for windows. This is the error that I get when I try to open android.bat from powershell (I get this when I use ".\android", otherwise if I type "start android" I get the same thing when I try to start it by clicking on it):
By the way, in case I don't say it enough, THANK YOU so much for trying to help me despite everything.
This error I get when I try to open 'sdkmanager' in the bin folder. If I open it normally the error flashes for a moment and the screen closes but opening it with powershell allowed me to see the error for longer:
According to this https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j maybe the problem is with my JDK version. I will try to find an older JDK and try with it, then I will report my result...
@akenaton===
I opened tools/bin with powershell and used '.\sdkmanager --list' and I can confirm that I did NOT have Google Play Services installed. I then installed it using powershell and now I have these packages installed:
However AdMob STILL DOES NOT WORK.
I tried a few different gms versions in the manifest with no success. The imports are still not recognized. Do I need to install another package?
The problem could be because my sketch is missing a .jar file... however I am using rev30 and it has no libproject folder and I am puzzled as to what to do (I prefer not to use old rev), because that same problem was in the post that I linked at the beginning of this post and it was not solved there ....
After doing this processing finally recognizes the imports:
These were the steps: 1. Download and unzip this: https://dl-ssl.google.com/android/repository/google_play_services_8298000_r28.zip
Open Google Play Services and copy 'libproject' folder
Go to your sdk folder and follow this path: android\sdk\extras\google\google_play_services
Paste libproject there
Go to libproject\google-play-services_lib\libs
Copy google-play-services.jar --- this is the jar that the sketch will use
Paste jar in CODE folder in sketch. That's it!
However I now when I try to run the code I get this error:
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:transformClassesWithDexForDebug'.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I also tried getting using r28 (not just copying libproject but replacing the whole google_play_services folder) and I still get this error.
I presume this bug was because I am using the full library, so I opened the .jar file and deleted most of the libraries that I don't use and now I get this:
FINALLY FIXED!!!
So I also had to do that:
Open the .jar file that you have put in your CODE folder inside your sketch; Go to com >> google >> android >> gms and delete Wallet and Wearable (maybe you could delete more for faster compiling but I haven't experimented)
Now edit your manifest and make sure to add the following: Instead of:
Add this instead:
That's it! Now it works!!