How can I use AddMob in Cocos2D-js project?

@Danilf16 Thanks for your help.

{
    "ndk_module_path" :[
        "../../js-bindings",
        "../../js-bindings/cocos2d-x",
        "../../js-bindings/cocos2d-x/cocos",
        "../../js-bindings/cocos2d-x/external",
        "../../js-bindings/cocos2d-x/plugin/publish"
    ],
    "copy_resources": [
        {
            "from": "../../../src",
            "to": "src"
        },
        {
            "from": "../../../res",
            "to": "res"
        },
        {
            "from": "../../../main.js",
            "to": ""
        },
        {
            "from": "../../js-bindings/cocos2d-x/plugin/jsbindings/script", 
            "to": ""
        },
        {
            "from": "../../js-bindings/cocos2d-x/plugin/protocols/proj.android/src", 
            "to": "../src"
        },
        {
            "from": "../../js-bindings/cocos2d-x/plugin/plugins/admob/proj.android/src", 
            "to": "../src"
        }, 
        {
            "from": "../../js-bindings/cocos2d-x/plugin/plugins/admob/proj.android/sdk", 
            "to": "../libs"
        }
    ],
    "must_copy_resources": [
        {
            "from": "../../js-bindings/bindings/script",
            "to": "script"
        },
        {
            "from": "../../../config.json",
            "to": ""
        },
        {
            "from": "../../../project.json",
            "to": ""
        } 
    ]
}

@abrac1980 Strangely… You say that you compile Facebook plugin. Is this plugin works in your project? And which software you use?

I use:
Android ndk: r9d
Apache ant: 1.9.4
Cocos2d-js: v3.0
Cocos IDE: V1.0.0 RC2
Python: 2.7
JDK: 1.7.0_67

I am using cocos2d-js 3.1 that must be the issue. I can’t downgrade my project now. so I wll keep trying to compile on 3.1 , I’m pretty sure the problem is in the android.mk files.
Thanks for the help anyway!.

Thank you, works great in my project :smile:
Any idea how to display interstitial ads? I managed to do it on iOS, I believe it is possible to do something similar on android as well…
Cheers!

There is a proj.android folder , import that project in to eclipse edit it the way you want just dont change the flow , edit the same way you did for interestitial ads on iOS set it up for android

Yeah well, that’s exactly what I had in mind… I thought maybe someone has already implemented it and I could avoid potential bugs…

I have implemented it and almost done with the sample project also but lil busy from last two weeks to finish off my blog , I have updated maximum plugin which were required for my project , one small thing is left had got bug in googleIAP plugin which I will be fixing this weekend

Does your implementation uses google play services, rather than the old google android sdk for interstitial ads?

Yes , Its working with the google play services and not with older libs

sounds good.
I’m currently checking other platforms for html5/js game development… I had a breakdown while dealing with facebook/admob/IAP integration for cocos2d-js :frowning: … seems like other platforms handing simpler methods to deal with this kind of stuff…

I think cocos2d-JS is the best one , where are you stuck ? Let me help you

I think cocos2D-JS is a great platform for developing games’ cores. in terms of plugins, I think it’s not there yet.
It lacks basic features of retrieving facebook profile pictures for example.
Integrating plugins and using them is difficult since you have to work your way through obj-c, java & c++ to make it work. I feel like I need to invest a lot of time preparing & integrating the plugins I need for my game, as first time user.
Also, documentation is rather poor. There are a lot of outdated manuals and tutorials and one need to go through a lot of work doing it alone.
It took me around two weeks to integrate facebook, just to face problems loading profile pictures on mobile platforms.
IAP on iOS doesn’t work (thread), no interstitial support for admob.
what about other platforms? chartboost, leadbolt, mopub and others?

Finally, I’m not sure performance is that important when creating simple 2d games. cocos2d would probably beat it contenders in this section but I truly believe the html canvas is just good enough for casual gaming. Other platforms are straight and easy to work with plugins and that is currently way more important for me.

Thank you!

After maticulously following your steps and double checking everything I am getting the following error when I try to debug my HelloWorld project:

JS: /data/data/org.cocos2dx.PrebuiltRuntimeJs/files/debugruntime/src/app.js:11:ReferenceError: plugin is not defined
Where my line 11 code is: var AdMob = plugin.PluginManager.getInstance.loadPlugin(“AdsAdmob”)

Thankyou for putting the time into writing a walkthrough

Hello, @Marteh . Please check your code. You must have this (pay attention to getInstance() but in your example you have getInstance without brackets):

var AdMob = plugin.PluginManager.getInstance().loadPlugin("AdsAdmob");

Hi Danilf, thanks for taking time to reply.

I tried getInstance with and without brackets with the same result. It appears cocos doesn’t know what object “plugin” is. The error that keeps stopping me is “plugin is not defined”.

Kind regards

@Marteh, Seems your project can’t find pluginx files. You can try to check some links and file copies.

By the way, which version of cocos2d-js you use? In my manual above I use cocos2d-js v3.0.

I am using js v3.2. I wish it could work on 3.2.

After checking where the problem may lie, I discovered it is in AppActivity.java when I call

 "import org.cocos2dx.plugin.PluginWrapper;"

I get the error:

[javac] C:\Android\workspace\Cashmeir\frameworks\runtime-src\proj.android\src\org\cocos2dx\javascript\AppActivity.java:31: error: package org.cocos2dx.plugin does not exist

Obviously it doesn’t know where to find the plugin. If you go to HELP - package org.cocos2dx.plugin does not exist you can see my 6 modified files.

I don’t know the framework well enough to come up with my own solution of how to import org.cocos2dx.plugin, maybe I need to use Android.mk to call my publish folder manually? Or the protocol folder? Hope you can give me a different insight

Try in Cocos2D-x 3.7, need to change some path.
Refer this link : http://chinchenghong.blogspot.com/2015/08/how-to-add-admob-to-cocos2d-x-37-js.html

what about iOS?

Hi every one, im new in cocos2d-x, i try every step to integrate admob to my game, and nothing work,
i use this link http://chinchenghong.blogspot.com/2015/08/how-to-add-admob-to-cocos2d-x-37-js.html,
can any one share a source code solution with cocos2d-x v3.7 or later integrated with admob?