[Cocos3.0 Tutorial] Integrate Admob ( google play services ) with Cocos2d-x v3.0 Final

The tutorial is excellent, I’m successed to add a banner AD in my project, but there is little comments in the appactivity.java, could anyone provide some explaination for that. And also how to use a interstitial AD?

@ ljl_888 the biggest part of it is just backwards compatibility for older android versions
http://stackoverflow.com/questions/10439033/getsize-not-supported-on-older-android-os-versions-getwidth-getheight-d

MfG Alex

Hi, thanks for the instructions. Followed them and got the ads displaying. There is one thing that do not know how to do (new to android) which is: The application is landscape and the ad banner is displaying at the top of the screen, how to get the ad banner located at the bottom? The cocos2dx code is only triggering the display and/or hide of ad so I am guessing it needs to be in the AppActivity java file but no idea what to do.

@alxlozano please read my tutorial http://cocos2d-x.org/forums/6/topics/53945

@jjorae wrote:

I tried step by step using this tutorial.

But my game didn’t show ads.

Log is OK. (Native function call and refresh AdMob OK.)

What is the problem? Help me plz…T^T

Got the same problem.

Device: HTC Sensation XE
Android version: 4.1.2
Language: English and Russian

The test application runs but there is no banner.
What can be the problem?

UPD I found out that I had not connect my device to the internet. Banner works.

@dex
ad blocker deactivated?

Hello, I’m trying to follow this instructions, and I compiled app, but after I run app on my device I have strange error.

05-22 08:43:38.477: E/AndroidRuntime(1493): FATAL EXCEPTION: main
05-22 08:43:38.477: E/AndroidRuntime(1493): java.lang.UnsatisfiedLinkError: Native method not found: org.cocos2dx.lib.Cocos2dxHelper.nativeSetApkPath:(Ljava/lang/String;)V
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at org.cocos2dx.lib.Cocos2dxHelper.nativeSetApkPath(Native Method)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at org.cocos2dx.lib.Cocos2dxHelper.init(Cocos2dxHelper.java:71)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:68)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at com.newhope.barman.barman.onCreate(barman.java:99)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at android.app.Activity.performCreate(Activity.java:5133)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at android.os.Looper.loop(Looper.java:137)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at android.app.ActivityThread.main(ActivityThread.java:5103)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at java.lang.reflect.Method.invokeNative(Native Method)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at java.lang.reflect.Method.invoke(Method.java:525)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-22 08:43:38.477: E/AndroidRuntime(1493): 	at dalvik.system.NativeStart.main(Native Method)

Tell me please, what I do wrong? Thanks for your help!

I’m having the same issue =/

@manelizzard
@den1812

Hi,
can you run the test app in the android simulator? AVD?
Can you specify Cocos2d-x, NDK and SDK versions, etc.

Make sure you have >= NDK Toolchain version 4.7, r8e

@victory144
Hi, I run my app in the android simulator (AVD). What means “test app”?
I use cocos2d-x-2.2.0, android-ndk-r9, SDK 22.6.3
without admob my app run well

Thank you.

I just fixed my issue.

Just ensure you are loading the library. Check these two things:

  1. Android.mk contains these lines (I moved them to a custom module, and it was causing the error)

$(call import-module,2d)
$(call import-module,audio/android)
$(call import-module,Box2D)

  1. In your AndroidManifest.xml, the metadata informing with the library name must be outside the tag, but inside the tag.

That worked for me =)

Hope it helps!

@manelizzard
Unfortunately this decision didn’t help me. I understand that the library isn’t loaded, but I don’t understand why.

Yeah, I solved my problem. The problem was in distinction between 3.0 and 2.0 versions cocos2d-x. For version 2.0 at .java file has to be the following code

static 
    {
        System.loadLibrary("cocos2dcpp");
    }     

@den1812
“test app” I meant, this tutorial project.
I am sorry, this tutorial was made for Cocos2d-x 3.x in mind.

But I glad that you have making this to work with Cocos2d-x 2.x based version.
If you can explain this in details, it will be great, thus it can be linked to first thread.

Thanks.

@manelizzard

Thanks for the information.

@victory144
I use cocos2d-x version 2.2.0. I have no file AppActivity.java, but I have file %my_project_name%.java. I do next things:

  1. In %my_project_name%.java file I change package name from package org.cocos2dx.cpp; to %my_project_package_name% for example: package com.MyCompany.AwesomeGame;

  2. In %my_project_name%.java file added next code

public class %my_project_name% extends Cocos2dxActivity
{
      ...
all code from your instructions
      ...
    static 
    {
        System.loadLibrary("cocos2dcpp");
    }     
}
  1. In AdmobHelper.cpp I change path for classname
//In cocos2d-x version 3.0
const char* AppActivityClassName = "org/cocos2dx/cpp/AppActivity";
//In cocos2d-x version 2.2.0
const char* AppActivityClassName = "%my_project_package_name%";

That’s all, I hope it will be helpful for somebody.

@victory144
It will be cool, if you add in your instructions how to change addmob baner placement (to bottom for example).

1 Like

Very nice tutorial. How can we achieve this through plugin folder provided in cocos2d-x 3.0 folder?

Is it possible to show the Ad with sliding effect?
For instance, the Ad is hidden by default. After player wins the game, it will slide to correct position by calling showAd method.

Sample App: Unblock Me Free

Sorry! I did not realized you were using version 2.2… my fault! :frowning:

Good job all guys!

@den1812 wrote:

@manelizzard
Unfortunately this decision didn’t help me. I understand that the library isn’t loaded, but I don’t understand why.

Yeah, I solved my problem. The problem was in distinction between 3.0 and 2.0 versions cocos2d-x. For version 2.0 at .java file has to be the following code

static 
    {
        System.loadLibrary("cocos2dcpp");
    }     

This tutorial would be helpful

Thanks :slight_smile:

this didn’t work for me. Using Latest cocos build. Latest SDK/NDK. Followed instructions step by step but app crashing.

EDIT :

I just added this to AppActivity nd its worked

static 
{
    System.loadLibrary("cocos2dcpp");
} 

Hi victory144, I feel I am very close to solve this problem and this is thanks to you. I have implemented everything exactly as the tutorial shows, except for the AdHelper.cpp which has some modifications in my case, so I can handle ads on iOS also.

Well, my app is running but ads are not showing in android devices.

The problem I am struggling with now is that my LogCat shows, each X seconds (ad refresh time), this error msg:

06-26 15:30:12.203: I/Ads(14010): Starting ad request.

06-26 15:30:12.223: D/webkit(14010): Firewall not null
06-26 15:30:12.223: D/webkit(14010): euler: isUrlBlocked = false
06-26 15:30:12.233: I/GATE(14010): DEV_ACTION_COMPLETED

06-26 15:30:12.273: W/GooglePlayServicesUtil(14010): Google Play services is missing.
06-26 15:30:12.273: E/GooglePlayServicesUtil(14010): GooglePlayServices not available due to error 1

06-26 15:30:12.363: I/webclipboard(14010): clipservice: android.sec.clipboard.ClipboardExManager@417b9d68
06-26 15:30:12.383: V/(14010): NotificationPresenterImpl::setSettingsValue 0
06-26 15:30:12.383: V/(14010): NotificationPresenterImpl::setSettingsValue 0
06-26 15:30:12.413: V/(14010): NotificationPresenterImpl::setSettingsValue 0
06-26 15:30:12.413: V/(14010): NotificationPresenterImpl::setSettingsValue 0
06-26 15:30:12.413: D/webkit(14010): Firewall not null
06-26 15:30:12.423: D/webkit(14010): euler: isUrlBlocked = false
06-26 15:30:12.423: D/WML_SISO(14010): InitPasteboardJni

06-26 15:30:12.463: W/Ads(14010): AdWebView unable to handle URL: https://10.1.5.254:1003/fgtauth?00001157a94a73f4

It would be awesome if you could give me a hand with this. Thanks!