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

Its even embarrassing to say but turns out that it was a problem with my internet connection. -.-

Oh mine, really thank you!. I finally solved the problem. It depends on the package name in src folder of the project., so (with cocos2d-x version 2.x.x )AppActivityClassName should be ā€œcom/someName/SomeName/projectNameā€. It took me almost a day!!

Love it! Thanks!

Works a treat in v2.2.x thanks for the good work! Check out my Cocos2d-x release on play store: Micro Gyro :smile:

nice oneā€¦ Thanks :smile:

Thanks for the great tutorial!

Iā€™m pretty much using exactly this code, but it has the following problem:
If you click and ad and then go back to the game, clicking the back button closes the game.
I think itā€™s because the webview is catching the key input, instead of it being passed to cocos (key listener).

Do you guys have this issue to?

Thanks for this! :smile:

Iā€™m not able to get the ads to display. I get the following error messages:

Google Play services is missing
There was a problem getting an ad response. ErrorCode: 0
Failed to load ad: 0

Any have any ideas what might be wrong? Testing on 4.4.2 emulator.

Thanks

I followed the tutorial found on the Cocos2d-x wiki (http://www.cocos2d-x.org/wiki/User_Tutorial-Integrate_AdMob) that looks like the same content as this post. I got it working, so I can confirm that the tutorial is valid for this system/software config:
ā€” Cocos2d-x rev. 3.2
ā€” Google Play Services rev. 21
ā€” Android 4.4.2 (API 19)
ā€” Eclipse Luna Release (4.4.0)
ā€” MacBook Pro 10.9.4
ā€” Google Nexus 4 w/ Android 4.4.2

I encountered several speed bumps as I tried to get this to work. I hope this report saves someone a bit of aggravation. This is based on the wiki tutorial.

Documentation error:
http://www.cocos2d-x.org/wiki/User_Tutorial-Integrate_AdMob

The following line in section 2.1 uses the wrong kind of hyphen/dash for one or more of the parameters. If you copy/paste from the tutorial at this location you will get an error when attempting to create your new project.

error:
cocos new admobTest ā€“p com.test.admobTest ā€“l cpp ā€“d PROJECT_LOCATION

corrected:
cocos new admobTest -p com.test.admobTest -l cpp -d PROJECT_LOCATION

resulting error when compiling with build_native.py:
cocos new: error: argument -l/ā€“language is required

Once I added the Google Play Services lib I got an error when building from Eclipse. I did a web search for whatever the error was and found instructions on changing the eclipse.ini settings to allocate a more memory to Eclipse.

  1. After wrestling with the instructions for orienting ads at the bottom of the screen I pasted my final code into the thread on that topic. There are 2 possible solutions:
    http://cocos2d-x.org/forums/6/topics/53945

I encountered some kind of error when building from Eclipse that suggested that there was a conflict between the AndroidManifest.xml file located in the main project and the AndroidManifest.xml file in the Google Play Services lib. That problem eventually went away after I made several changes to Eclipse, but Iā€™m not sure what ultimately fixed it:
ā€” I updated a few of the item sin the Android SDK Manager
ā€” I rebuilt the whole project from zero

  1. I copied AdMobHelper.h/.cpp wholesale from the GigHub repository, but otherwise I tried to leave the default project unchanged and make only the necessary changes to the other files (HelloWorldScene.cpp, AppActivity.java, etc.)

I successfully integrated with com.google.android.gms.ads.*.
Ads works fine.
But I have a problem.

  • touch on the ads from admob, and then drag move to normal area of game screen, now pressing the back key will cause the app dissmiss(going to background?)

  • click on the ads and the view is switched to google play website, press the back key will return the game screen, now in the game screen press the back key again will also cause the app going to background

In both cases, when relaunch app, it crashes.
Does anyone suffer this?

@hzlov: I encountered this as well, you can fix it yourself by giving the cocos activity the focus onResume.

@MFHSchoonbrood Thanks for the tip.

Actually Iā€™m trying to use AdSize.SMART_BANNER.
This smart banner doesnā€™t open any web site or something at the first touch.
Therefore, first touch Ads with smart banner case doesnā€™t fire onPause or onResume.

So, I tried to modify Cocos2dxGlSurfaceView.java to catch losing focus and set focus to surface view again.
The modified code worked what I expected - catch losing focus & set focus again -,
but unfortunately It didnā€™t fix my problem though fixed focus issue :frowning:

@hzlov You could add the same check to dispatchKeyEvent.

Iā€™ll try what youā€™re doing later, but it sounds like this should catch it always:

@Override
public boolean dispatchKeyEvent(final KeyEvent pKeyEvent)
{
Ā Ā  Ā if (Cocos2dxGLSurfaceView.getInstance() != null && this.getCurrentFocus() != Cocos2dxGLSurfaceView.getInstance())Ā Ā  Ā { Cocos2dxGLSurfaceView.getInstance().requestFocus(); }
Ā Ā  Ā return super.dispatchKeyEvent(pKeyEvent);
}

Kind regards,
Michaƫl

Our Cocos Helper provides integration help with AdMob and other services https://github.com/SonarSystems/Sonar-Cocos-Helper