Admob Ads Not Showing Unity 4.3 /NO CONSOLE ERROR EITHER/

1,748 views
Skip to first unread message

PJ Deghaim

unread,
May 16, 2014, 10:12:52 PM5/16/14
to google-adm...@googlegroups.com
Hey guys!

I have an issue, I'm implementing my ads as seen in the README and am getting no errors in the console. However, when I open the app on my Android device, I get an error? Any idea how to fix this?

Here's the ad script.
using System;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class ads : MonoBehaviour {
private BannerView bannerView;


void Start()
{
//adunitid
string AdUnitId = "ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx";
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(AdUnitId, AdSize.Banner, AdPosition.Top);
//request ad
AdRequest request = new AdRequest.Builder().Build();
//show ad
bannerView.LoadAd(request);
}

}

I attach this script to the camera of every scene I want ads to show in, it works for none yet when running in the console it says the usual DummyAdLoad stuff...

Even my interstitial ads don't work...
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
using GoogleMobileAds;

public class interstitial : MonoBehaviour {

private InterstitialAd interstitialAdLose;

// Use this for initialization
void Start () {

//initialize interstitial
interstitialAdLose = new InterstitialAd("ca-app-pub-xxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxx");
//create empty ad request
AdRequest request = new AdRequest.Builder().Build();
//load
interstitialAdLose.LoadAd(request);
}
// Update is called once per frame
void Update () {

if(interstitialAdLose.IsLoaded()){
interstitialAdLose.Show();
}
}
}


I attach the interstitial ads to an empty game object on the lose game script and again, the Dummies show in the console but on the actual phone nothing loads.

As a side note, I am using Unity 4.3.4f1 and I am using the 2D framework. :)

rei...@gmail.com

unread,
May 17, 2014, 4:40:34 AM5/17/14
to google-adm...@googlegroups.com
Did you remember to copy the GoogleAdMobAdsSdk-6.3.0.jar (or other version) file into the ./Assets/Plugins/Android directory? Also, dod you make an AndroidManifest.xml file?

PJ Deghaim

unread,
May 17, 2014, 4:45:53 AM5/17/14
to google-adm...@googlegroups.com
yep thats all there and yes the android:value is set to true... any other ideas?

Eric Leichtenschlag

unread,
May 19, 2014, 7:55:05 PM5/19/14
to google-adm...@googlegroups.com
Hey PJ,

The v2.0 plugin doesn't support the old standalone SDK (GoogleAdMobAdsSdk-xxx.jar). Instead it is written against the newer Google Play services version of the SDK. You'll need to grab Google Play services from Android's SDK manager, and put the entire <android_sdk_folder>/extras/google/google_play_services/libproject into your Assets/Plugins/Android directory as described in the README.

Thanks,
Eric

PJ Deghaim

unread,
May 19, 2014, 8:06:00 PM5/19/14
to google-adm...@googlegroups.com
Thanks for that but unfortunately, even after getting rid of the SDK and dragging the Google Play Services in there and even reimporting the new unitypackage, it still doesnt work... any ideas?

Eric Leichtenschlag

unread,
May 19, 2014, 9:01:47 PM5/19/14
to google-adm...@googlegroups.com
Can you listen for the ad events and log the error, if any:



bannerView
.AdLoaded += HandleAdLoaded;
bannerView
.AdFailedToLoad += HandleAdFailedToLoad;



public void HandleAdLoaded(object sender, EventArgs args)
{
   
print("HandleAdLoaded event received.");
}
public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
 
print("Interstitial Failed to load: " + args.Message);
};

PJ Deghaim

unread,
May 20, 2014, 7:27:32 PM5/20/14
to google-adm...@googlegroups.com
Thanks for that but unfortunately there are still no errors....

Eric Leichtenschlag

unread,
May 20, 2014, 8:14:28 PM5/20/14
to google-adm...@googlegroups.com
Hmm, I'm surprised that you'd get a dummy loadAd call when running in the editor, but not an AdLoaded or AdFailedToLoad callback on device. Can you zip up and attach your Unity project?

Thanks,
Eric

PJ Deghaim

unread,
May 20, 2014, 10:51:23 PM5/20/14
to google-adm...@googlegroups.com
oh i thought you meant errors in the console aha. i unfortunately dont know how to run the android debug stuff on unity though i do have experience with it with past projects. do you know how to run the debug using unity?

thanks for all the help :)

Eric Leichtenschlag

unread,
May 21, 2014, 6:31:22 PM5/21/14
to google-adm...@googlegroups.com
I run adb from the terminal (see http://developer.android.com/tools/help/adb.html) for debugging. "adb logcat" (or "./adb logcat" or however you execute an executable on your machine) gets you all logs, and "adb logcat Ads:* *:S" will print logs from the Ads tag and silence everything else, so it'll be easy to see what error message the SDK is providing.

Thanks,
Eric

Diggie9

unread,
May 22, 2014, 6:01:50 AM5/22/14
to google-adm...@googlegroups.com
Hi, the debug log is as follows:

I/Unity   (28995): AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.ads.AdSize
I/Unity   (28995):   at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0
I/Unity   (28995):   at UnityEngine.AndroidJNISafe.CallStaticObjectMethod (IntPtr clazz, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0
I/Unity   (28995):   at UnityEngine.AndroidJavaObject._CallStatic[AndroidJavaObject] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0
I/Unity   (28995):   at UnityEngine.AndroidJavaObject.CallStatic[AndroidJavaObject] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0
I/Unity   (28995):   at UnityEngine.AndroidJavaObject.FindClass (System.String name) [0x00000] in <filename unknown>:0
I/Unity   (28995):   at UnityEngine.AndroidJavaObject._AndroidJavaObject (System.String className, System.Object[] args) [0x00000] in <filename unknown>:0
I/Unity   (28995):   at UnityEngine.AndroidJavaObject..ctor (System.String className, System.Object[] args) [0x00000] in <filename unknown>:0
I/Unity   (28995):   at GoogleMobileAds.Android.Utils.Get
I/Unity   (28995): setScreenSize: -1x-1 (1920x1080 / 1920x1080)
I/Unity   (28995): setScreenSize: keeping layout size 1920x1080
 
Everything that needed to be done is done. i also get the 'dummy' call. Have imported the latest version of google play etc etc. They are just not showing

PJ Deghaim

unread,
May 22, 2014, 9:07:21 AM5/22/14
to google-adm...@googlegroups.com
I have yet to do the debugging as I'm getting a DEX error (I need to clean up my plugins lol) but taking a logical guess that we're both on the same SDK and what not I'm guessing the missing AdSize class is the issue at hand...

Diggie9

unread,
May 22, 2014, 10:19:05 AM5/22/14
to google-adm...@googlegroups.com
Yep, but its strange since the AdSize seems to be included in the project GoogleMobileAds.Api.AdSize and the references to that particular Api seem to work as intended. So i'm not sure where it fails, the one thing i know for sure is that the Ads are not working, and the only thing the debug log of android says about any ad is the AdSize part.

Eric Leichtenschlag

unread,
May 23, 2014, 7:06:21 PM5/23/14
to google-adm...@googlegroups.com
@Diggie, the com.google.android.gms.ads.AdSize class is part of Google Play services which contains the Android Google Mobile Ads library. As mentioned in the README you'll need to download that library from Android and place it inside of Assets/Plugins/Android in your app.

Thanks,
Eric

Eric Leichtenschlag

unread,
May 23, 2014, 7:11:23 PM5/23/14
to google-adm...@googlegroups.com
@PJ, one reason you may end up with dex errors is having 2 copies of the same class when you try and build your project.

That's actually the main reason I have the .unitypackage set up with just the unity-plugin-library.jar inside of Assets/Plugins/Android instead of the entire plugin-library/ android library project. I found that when I had the entire library project in Assets/Plugins/Android, Eclipse would generate a new unity-plugin-library.jar inside of Assets/Plugins/Android/plugin-library/bin. Then when I went to build, I'd have the plugin source files and the compiled jar inside Assets/Plugins/Android, so it would throw some dex error since i had two copies of the same class.

Hope this helps,
Eric

PJ Deghaim

unread,
May 23, 2014, 7:51:01 PM5/23/14
to google-adm...@googlegroups.com
Thank you so much Eric, I finally got my ads working :'D.

The comment about the Google Play Services Lib and the DEX error really helped me as I decided that nothing was better than clean.
In the past I was advised to delete the ads folder in the Google Play Services Jar, for people reading later on, do not do this.
I decided to easily delete the whole plugins folder, the whole Google Mobile Ads folder and the whole Google Play Games folder, then I reimported them manually and now everything is clean and working.

Again thanks,
PJ

Eric Leichtenschlag

unread,
May 23, 2014, 8:04:39 PM5/23/14
to google-adm...@googlegroups.com
If you have the Google Play games folder, then when you run that magic "setup google play games android" command, it imports the library for you. If you then integrated AdMob and pulled in a second copy of this library somewhere, then kabloom there are your dex errors for having two copies of google play services! Both of these plugins reference the same library, so you only need to include it once.

Cheers,
Eric
Message has been deleted

PJ Deghaim

unread,
May 23, 2014, 8:13:12 PM5/23/14
to google-adm...@googlegroups.com
Yeah, so glad I figured this out. I actually only saw it doing that last second aha.

The new APK for my game is out now... with ads!

Thanks,
PJ

PJ Deghaim

unread,
May 23, 2014, 8:13:40 PM5/23/14
to google-adm...@googlegroups.com
well not necessarily now as it takes a few hours but still

Diggie9

unread,
May 25, 2014, 2:39:23 PM5/25/14
to google-adm...@googlegroups.com
Thanks Eric, i was stupid enough to paste an extra folder in there.
Message has been deleted

Marnielle Lloyd Estrada

unread,
Jul 9, 2014, 1:45:43 AM7/9/14
to google-adm...@googlegroups.com
Sorry for reviving the thread. I'm already scratching my head the whole day yesterday with this. I think I've done all the preparation, the AndroidManifest, copying google-play-services_lib to Plugins/Android. I even checked in the StagingArea after building if it really was included. I still get AndroidJavaException: java.lang.
ClassNotFoundException: com.google.android.gms.ads.AdSize.

Tried reimporting the whole Plugins folder, same thing. I'm only trying out a minimal BannerView usage:

using System;
using System.Collections;
using System.Collections.Generic;

using UnityEngine;

using GoogleMobileAds.Api;

using Common.Logger;

public class GoogleAdsTest : MonoBehaviour {


   
private BannerView bannerView;

   
void Start() {

       
try {
           
InitBannerView();
       
} catch(Exception e) {
           
Log(e.Message);
           
Log(e.StackTrace);
       
}
   
}

   
private void InitBannerView() {

       
// Create a 320x50 banner at the top of the screen.

       
this.bannerView = new BannerView("ca-app-pub-xxxxxxxxxxxxxxxxxxxxxx", AdSize.Banner, AdPosition.Top);
       
       
// callbacks
       
this.bannerView.AdLoaded += OnAdLoaded;
       
this.bannerView.AdFailedToLoad += OnAdLoaded;
       
       
// Create an empty ad request.

       
AdRequest request = new AdRequest.Builder().Build();

       
       
// Load the banner with the request.
        bannerView
.LoadAd(request);
        bannerView
.Show();
       
       
Log("Ad Banner View shown");
   
}

   
private void OnAdLoaded(object sender, EventArgs args) {
       
Log("Ad loaded");
   
}

   
private void OnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args) {
       
Log("Failed to load: " + args.Message);
   
}

   
private void Log(string message) {
       
Logger.GetInstance().Log(message);
       
this.logs.Insert(0, message);
   
}

   
private List<string> logs = new List<string>();

   
private int ELEMENT_HEIGHT = (int)(Screen.height * 0.05f);

   
void OnGUI() {
       
GUILayout.BeginVertical();
       
GUILayout.Label("Test Ad Mob", GUILayout.Height(ELEMENT_HEIGHT));

       
foreach(string log in this.logs) {
           
GUILayout.Label(log, GUILayout.Height(ELEMENT_HEIGHT));
       
}
       
GUILayout.EndVertical();
   
}
   
}





Marnielle Lloyd Estrada

unread,
Jul 9, 2014, 2:41:04 AM7/9/14
to google-adm...@googlegroups.com
Tried it in a separate project that only contains the Google Mobile Ads because I thought other plugins might be causing it. I still get AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.ads.AdSize

Eric Leichtenschlag

unread,
Jul 9, 2014, 5:14:10 PM7/9/14
to google-adm...@googlegroups.com
Could you share your separate project that only contains ads? My guess is that google-play-services_lib/ isn't included properly, and Android can't find the library at runtmie.

Thanks,
Eric

Marnielle Lloyd Estrada

unread,
Jul 12, 2014, 2:41:11 AM7/12/14
to google-adm...@googlegroups.com
Please check attached zipped file. Sorry, it took so long to reply.
AdsTestLean.zip

Marnielle Lloyd Estrada

unread,
Jul 12, 2014, 4:05:45 AM7/12/14
to google-adm...@googlegroups.com
Please check attached zipped file. Sorry, it took so long to reply.

On Thursday, July 10, 2014 5:14:10 AM UTC+8, Eric Leichtenschlag wrote:
AdsTestLean.zip

Eric Leichtenschlag

unread,
Jul 14, 2014, 7:43:32 PM7/14/14
to google-adm...@googlegroups.com
Hmm, I deployed your app and got the ad back.

Which device/OS are you running this on? is it higher than API 9?

Thanks,
Eric

Marnielle Lloyd Estrada

unread,
Jul 15, 2014, 2:37:03 AM7/15/14
to google-adm...@googlegroups.com
Really? It's a Samsung S3 running Android 4.1.2. What device did you run it on? The Google Play Services Library is revision 18. Which Minimum API Level did you set it on? I set mine at API Level 13.

Eric Leichtenschlag

unread,
Jul 15, 2014, 1:14:14 PM7/15/14
to google-adm...@googlegroups.com
I got it working on Nexus 5 running 4.4.3, Samsung Galaxy S4 running 4.3, and Samsung Galaxy S2 running 4.0.3. I didn't change Minimum API level from what your sample had.

What version of Google Play services does your S3 have on the device?
Message has been deleted

Marnielle Lloyd Estrada

unread,
Jul 21, 2014, 8:35:07 AM7/21/14
to google-adm...@googlegroups.com
It's Version 5.0.84 (12559630-036)

Eric Leichtenschlag

unread,
Jul 21, 2014, 5:55:02 PM7/21/14
to google-adm...@googlegroups.com
5.0.84 is the latest version, so it's not a version mixup on the device...I'm running out of ideas for you.

ax...@richmediamanila.com

unread,
Aug 4, 2014, 12:32:00 AM8/4/14
to google-adm...@googlegroups.com
Hello! I apologize for posting on this thread but this is the only thread that mentions my current my issue. I've followed all the instructions but i'm still getting this error:

AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.ads.Adsize

It seems that it really can't find the classes inside com.google.android.gms.ads

Is there some way to know if the lib files are not being imported in the project? I checked the staging folder and the google play services lib is inside android-libraries.

Thanks!
Axel

Eric Leichtenschlag

unread,
Aug 4, 2014, 1:38:11 PM8/4/14
to google-adm...@googlegroups.com
What's the size of your apk when you build the HelloWorld  sample project? I got 11.9 MB after including Google Play services. I tried to take it out and recompile to test the size without play services, but it wouldn't even compile since the manifest has a reference to @integer/google_play_services_version which requires Google Play services. So if your app compiled you must have had play services in the right place.

What version of Unity are you using? Maybe they changed how they build Android apps. I'm currently on 4.3.4.

Martin Z

unread,
Sep 15, 2014, 7:12:57 AM9/15/14
to google-adm...@googlegroups.com
A bit too late probably but maybe it is gonna help someone...
I had the same problem and in my case it was caused by two different android sdk installs - one was standard android sdk install and the other was Android Studio, which has android sdk inside.

I used Android Studio SDK manager to download components to Android Studio path while unity was using the other (obviously wrong) path.
Changing the path to Android Studio solved the problem, now I can see ads!
Reply all
Reply to author
Forward
0 new messages