Admob interstial ads in cocos2d-js

How to integrate Admob interstial ads in cocos2d-js? i was able to integrate admob and show banner ads, however interstial ads could not be displayed as they are not currently implemented into the plugin that i’m using.

Does anybody have an updated version of this plugin that support interstial Admob ads?

@pandamicro do you have any idea please ??
Most forum topics are not answered, I’m feeling that i’m talking to myself :smile:

I got Admob interstial ads working using AnySDK with cocos2d-JS v3.3

Shared a working solution using Google Play Services SDK on Android.

In Cocos2d-JS you can call the native Java code thru reflection

i.e.
jsb.reflection.callStaticMethod(“org/cocos2dx/cpp/AdmobPlugin”, “showInterstitial”, “()V”);

@festival @victor88888 wow, this sound great, i’m new to cocos2d and even for mobile development (but i have strong development skills), for that i used to choose cocos2d-js to avoid long learning sessions.

Currently i’m exploring cocos2d-js, and thanks for your suggestions, but it would be great if you could make a step by step tutorial that show how to implement those solutions for beginners just like me :smile: .

Thanks again.

@victor88888 i’m really interested to integrate anySDK with cocs2d-js v3.3 as if i’m not wrong it could allow us not only to integrate admob ads but many other plugins and even push notification.

Could you please share how did you integrated the anySDK with cocos2d-js ? did you tried to use other plugins with anySDK? i.e push notification or analytics or any other plugin.

i’ve founf the following tutorial anySDK cocos2d-JS integration (chinese), but as mentioned, it is in Chinese and could not understand all steps, does anyone know if there an english version of it???

@festival i downloaded you attached solution / code, but how could i integrate it in my existing project ?? please help.

@ckh Soory. Can’t make a detailed blog post now. But you will find the code useful when you have more knowledge of the Cocos2d-x architecture.

ok thanks anyway, but do you have any suggestion or some useful links / tutorials to help me understand more the structure to be able to know how to integrate your code with coco2d-x architecture?

@ckh I only used AdMob, but I don’t think it would be difficult to use other plugins; AdMob was ridiculously easy to use after the initial AnySDK/cocos2d-JS integration. I don’t mind writing a basic English version of the integration instructions, but have you already downloaded AnySDK, got an account and then downloaded the appropriate Framework files from within AnySDK?

@victor88888 On the english version of anySDK website, i downloaded “AnySDK for Windows X64.zip” file which was the only available link to download with the MAC os version as well.

However the files architecture are really different from those in the tutorial anySDK cocos2d-JS integration (chinese).

is that what i should download?

i wasn’t able to find the register page, only login was present, however i will use google translate in order to register on the chinese website and create a new account.

please advise what are the next steps.

@chk I assume you ran the binary (AnySDK_EN\bin\AnySDK.exe) and the clicked on the Sign Up button to get an account. Yes you can just use google translate to get yourself through the registration… it’s pretty standard stuff. After you’ve logged into the AnySDK program you’ll need to download the framework files for integration with your cocos2d-JS project. Here’s how to do it:

  1. After you login to the AnySDK software, you need to create a “game” entry before doing anything else, by clicking on the big “+” icon in AnySDK and entering a game name/type.
  2. Now you’ll want to download the Framework files to integrate with your cocos2d-JS project.
    a) In AnySDK, click on the More button (top right) and then click on “category” (in the center).
    b) There is a menu on the left which is in Chinese. You need to select 框架 (which means Frameworks).
    c) After the various entries load, you’ll see JS(Android) amongst them (assuming you want android). Click on the 下载 button (it means download). When it has finished downloading, the button will turn green and say 打开 (means Open), and that will take you to the actual source files you’ll need to integrate with your Cocos2d-JS project; the files you saw being mentioned in the integration tutorial.
  3. While you’re at it, you can grab the AdMob plugin. Below the 框架 on that left menu there is a 插件 button (it means plugins). Click on it and when the icons have loaded, you’ll see AdMob. Click the green button to download and install it.

The next step is the AnySDK/cocos2d-JS integration which I’ll write a little later.

@victor88888 thanks very much, i will try your suggested steps and update you with the result.

update: did all your suggested steps, and now i have the files that i saw in the integration tutorial.

Really appreciate your help!!! thanks again!!!.

@victor88888 i tried to implement the anySDK using the following link anySDk with cocos2d-JS (cn) with help of anySDK Cpp tutorial (en).

And here are the steps that I followed:

1- download the anySDK framework

2- copy anysdkConst.js to src folder

3- update jslist on project.json to include the anysdkConst.js

"JsList"  : [
   "Src / resource.js" ,
   "Src / anysdkConst.js" ,
   "Src / app.js"
]

4- create a “protocols” directory @ my COCOS_PROJECT_HOME /frameworks / runtime-src / proj.android

5- copy android and include directories from anySDK framwork: AnySDK…\framework\protocols_gnustl_static to protocols_gnustl_static to the “protocols” directory that we recently created.

6- copy and merge anySDK res directory AnySDK…\framework\protocols_gnustl_static\res content into my project res directory.

7- copy the The AnySDK_Framework_JS / 3.x files into COCOS_PROJECT_HOME/frameworks / runtime-src /Classes

8- Edit COCOS_PROJECT_HOME/frameworks /proj.android/jni/Android.mk file
- add :

../../Classes/autoanysdkbindings.cpp \
../../Classes/manualanysdkbindings.cpp \

9- always in Android.mk add to LOCAL_C_INCLUDES:

$(LOCAL_PATH)/../protocols/android \	
$(LOCAL_PATH)/../protocols/include \

10- add LOCAL_WHOLE_STATIC_LIBRARIES += PluginProtocolStatic in Android.mk as well.

11- Add library path:below the last line of android.mk add: $(call import-module,protocols/android)

(i've got an error during compile for duplicates, as this was already loaded by admob, so i removed this line, don't know if this is the correct action, but after removing it the error disappeared)

12- modify COCOS_PROJECT_HOME/frameworks //runtime-src/proj.android/build-cfg.json
- modify Ndk_module_path, by adding “” at the end !!! strange, i’m not sure why …

13- copy AnySDK_Framework_JS / Framework / protocols_gnustl_static / Android libPluginProtocol.jar to COCOS_PROJECT_HOME\frameworks\runtime-src\proj.android\libs

14- edit PROJECT_HOME\frameworks\runtime-src\proj.android\jni\hellojavascript\main.cpp as following

15- edit and add the following permissions to PROJECT_HOME\frameworks\runtime-src\proj.android\AndroidManifest.xml
and remove those that was previously added, if any:

<Uses-permission Android: name = "android.permission.INTERNET"  />
<Uses-permission Android: name = "android.permission.ACCESS_NETWORK_STATE"  />
<Uses-permission Android: name = "android.permission.ACCESS_WIFI_STATE"  />
<Uses-permission Android: name = "android.permission.RESTART_PACKAGES"  />
<Uses-permission Android: name = "android.permission.KILL_BACKGROUND_PROCESSES"  />

16- Modify proj.android/src/org/cocos2dx/javascript/AppActivity.java file.
(add PluginWrapper.init ( this ); to the onCreate() function, and import anySDK plugin wrapper)

import com.anysdk.framework.PluginWrapper;

public  class  MainActivity extends Activity {
  protected  void  onCreate (Bundle savedState)
      {
          super.onCreate (savedState);
          PluginWrapper.init ( this );  
      }

17- also add to appActivity.java

  @Override
 protected void onDestroy () {
	 PluginWrapper.onDestroy ();
	 super.onDestroy ();
 }

 @Override
 protected void onPause () {
	 PluginWrapper.onPause ();
	 super.onPause ();
 }

 @Override
 protected void onResume () {
	 PluginWrapper.onResume ();
	 super.onResume ();
 }

 @Override
 protected void onActivityResult (int requestCode, int resultCode, Intent data) {
	 PluginWrapper.onActivityResult (requestCode, resultCode, data);
	 super.onActivityResult (requestCode, resultCode, data);
 }

 @Override
 protected void onNewIntent (Intent intent) {
	 PluginWrapper.onNewIntent (intent);
	 super.onNewIntent (intent);
 }

 @Override
 protected void onStop () {
	 PluginWrapper.onStop ();
	 super.onStop ();
 }

 @Override
 protected void onRestart () {
	 PluginWrapper.onRestart ();
	 super.onRestart ();
 }

18- Modify COCOS_PROJECT_HOME /frameworks/runtime-src/Classes AppDelegate.cpp document (for v3.x)
add:

 sc-> addRegisterCallback (register_all_autoanysdkbindings);
 sc-> addRegisterCallback (register_all_anysdk_manual);


 before #if (COCOS2D_DEBUG > 0 && CC_CODE_IDE_DEBUG_SUPPORT > 0)

19- add reference also to AppDelegate.cpp

#include "autoanysdkbindings.hpp"
#include "manualanysdkbindings.hpp"

20- load any sdk in js

// Note: This appKey, appSecret, privateKey, asked to replace the value inside their own packaging tools (login packing tools, the three parameters of the game management interface display).

var appKey = "CED525C0-8D41-F514-96D8-90092EB3899A";
 var appSecret = "a29b4f22aa63b8274f7f6e2dd5893d9b";
 var privateKey = "963C4B4DA71BC51C69EB11D24D0C7D49";
 var oauthLoginServer = "http://oauth.anysdk.com/api/OauthLoginDemo/Login.php";
 var agent = anysdk.AgentManager.getInstance ();
 // Init
 agent.init (appKey, appSecret, privateKey, oauthLoginServer);
 // Load
 agent.loadALLPlugin ();

after all those steps, i’m tryig now to compile the project, but i’m getting errors and trying to fix them. i’ll post them later if i wasn’t able to proceed.

Don’t know if this is the correct scenario, thanks if you could confirm.

the error that i’m getting till now during compile is:

    jni/../protocols/include/ProtocolIAP.h:108: error: undefined reference to 'anysd
    k::framework::ProtocolIAP::_paying'
    jni/../../Classes/autoanysdkbindings.cpp:211: error: undefined reference to 'any
    sdk::framework::PluginFactory::purgeFactory()'
    jni/../../Classes/autoanysdkbindings.cpp:222: error: undefined reference to 'any
    sdk::framework::PluginFactory::getInstance()'
    jni/../../Classes/autoanysdkbindings.cpp:316: error: undefined reference to 'any
    sdk::framework::PluginManager::unloadPlugin(char const*, int)'
    jni/../../Classes/autoanysdkbindings.cpp:326: error: undefined reference to 'any
    sdk::framework::PluginManager::unloadPlugin(char const*, int)'
    jni/../../Classes/autoanysdkbindings.cpp:348: error: undefined reference to 'any
    sdk::framework::PluginManager::loadPlugin(char const*, int)'
    jni/../../Classes/autoanysdkbindings.cpp:368: error: undefined reference to 'any
    sdk::framework::PluginManager::end()'
    jni/../../Classes/autoanysdkbindings.cpp:379: error: undefined reference to 'any
    sdk::framework::PluginManager::getInstance()'
    jni/../../Classes/autoanysdkbindings.cpp:1523: error: undefined reference to 'an
    ysdk::framework::AgentManager::unloadALLPlugin()'
    jni/../../Classes/autoanysdkbindings.cpp:1538: error: undefined reference to 'an
    ysdk::framework::AgentManager::loadALLPlugin()'
    jni/../../Classes/autoanysdkbindings.cpp:1553: error: undefined reference to 'an
    ysdk::framework::AgentManager::getCustomParam()'
    jni/../../Classes/autoanysdkbindings.cpp:1605: error: undefined reference to 'an
    ysdk::framework::AgentManager::init(std::string, std::string, std::string, std::
    string)'
    jni/../../Classes/autoanysdkbindings.cpp:1716: error: undefined reference to 'an
    ysdk::framework::AgentManager::getChannelId()'
    jni/../../Classes/autoanysdkbindings.cpp:1762: error: undefined reference to 'an
    ysdk::framework::AgentManager::end()'
    jni/../../Classes/autoanysdkbindings.cpp:1773: error: undefined reference to 'an
    ysdk::framework::AgentManager::getInstance()'
    C:\Users\user\Documents\cocos\CocosJSGame\frameworks\runtime-src\proj.android\..
    /../js-bindings/bindings/manual/spidermonkey_specifics.h:58: error: undefined re
    ference to 'typeinfo for anysdk::framework::PluginFactory'
    C:\Users\user\Documents\cocos\CocosJSGame\frameworks\runtime-src\proj.android\..
    /../js-bindings/bindings/manual/spidermonkey_specifics.h:58: error: undefined re
    ference to 'typeinfo for anysdk::framework::PluginManager'

.....
.....
.....

C:\Users\user\Documents\cocos\CocosJSGame\frameworks\runtime-src\proj.android\..
/../js-bindings/bindings/manual/cocos2d_specifics.hpp:82: error: undefined refer
ence to 'typeinfo for anysdk::framework::PluginParam'
jni/../../proj.android/jni/hellojavascript/main.cpp:22: error: undefined referen
ce to 'anysdk::framework::PluginJniHelper::setJavaVM(_JavaVM*)'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libcocos2djs.so] Error 1
make.exe: Leaving directory `C:/Users/user/Documents/cocos/CocosJSGame/framework
s/runtime-src/proj.android'
Ndk build failed!

@ckh Ok, in step 11 you said you got an error because it was already loaded by AdMod. You weren’t starting with a fresh project? To get this working, I highly recommend that you start with a fresh cocos2d-JS v3.3 project and do step 11 as per the instructions. And for step 10, unless you already have stuff assigned to that variable, I suggest you use the := operator instead of += as follows:

LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic 

Check the rest of your additions to the Android.mk file in a paranoid manner. e.g. For LOCAL_SRC_FILES and LOCAL_C_INCLUDES make sure you haven’t inadvertently added a trailing backslash (which may have happened if you directly pasted the additions at the end of each).

You may also like to check you have the following import in your AppActivity.java file:

import android.content.Intent;

It’s painful to get it working the first time, so I hope this helps.

@victor88888, thank you really very much, following your suggestion, i integrated anySDK on a fresh cocos2d-js v 3.3 project and i am now able to compile it without errors!!!

i faced an error regarding anySDK is not defined but solved after build runtime.

now what’s next :smile: , how to integrate the Admob? how to add my admob account parameter to link them to anySDk when calling showAds function…?

Thank you again!!!

@ckh glad to hear you got it to build! at this point, you should be able to see placeholder ads when you run the code. To get it to show your actual ads, you need to use the publishing feature of the AnySDK software. Basically, you add your AdMob details into the AnySDK software, point it to your APK, and it’ll generate a new APK with all the AdMob stuff. To avoid problems, it’s best to do it step-by-step the first time, as follows:

Open the AnySDK software and go into your game, then select “Config” at the top (should already be selected).

  1. Enter your Keystore stuff and other info in the “Game Manager”
  2. Click Next and it’ll take you to the Store Manager tab. You’ll see a list on the right where you need to select “Google Play”
  3. Click Next and you’ll arrive at SDK Manager. If there’s nothing in your “Google Play SDK List”, take a look at the “SDK List” on the right, select the “Ad” tab, and then you’ll be able to select the AdMob stuff.
  4. Click Next and it’ll take you what they call Paramate Config :slight_smile: In the middle, you’ll see “AdMob -Interstitial” which you need to click on, and then you can add your AdMob UnitId in the SDK Parameters part on the right.
  5. Click next and it’ll take you to the icon manager…
  6. Press “Done” and now the “Publishing” heading will be highlighted. In “Store List” on the left you can check the “GooglePlay” checkbox.
  7. Use the browse button to select your APK and then press start. When it’s finished you can hit the Open Dir button and there’s your new APK.
1 Like

@victor88888 first thanks for the detailed and step by step guide :wink: , but i was able to do all steps from 1 to 4, However in step 4, i wasn’t able to find the “interstitial Ad” item, i remember that it was displayed once but later it disappeared maybe after an update i don’t know really.

i’m locked at this step, can’t find how enter my admob units details. strange. i’ll try to uninstall/re-install the anySDK software.

@chk In step 3, when you’re in SDK Manager and you see the “SDK List” on the right, make sure that not only AdMob is ticked, but also “Interstitial” is ticked in the dropdown below AdMob. If you have done this, then perhaps it’s your antivirus software. As we speak, my antivirus software just detected some of the AnySDK stuff as Adware and tried disable it (I believe it’s a false detection), so disabling Antivirus software and re-doing the AnySDK stuff may also do the trick.

@victor88888 A fresh install of anySDk did the trick i think ( i tried all solutions combined :smile:) , and i selected and configured the Interstitial and banner ad successfully, but after apk selection (step 7), the anySDK app hang and force close each time and now i can’t find the Interstitial and banner options again :smiley: , but i think i could manage that, i’ll try, hope so.

what i’m really interested to know, is a quick recap:

  • in order to integrate anySDK, i need to package my game to apk (after including all calls to anysdk ad API) and after that proceed with the previous steps (1 to 7) in order to activate anySDK calls?

i called my interstatial Ad with ads_plugin.showAds(1); is that the correct way?

var agent = anysdk.AgentManager.getInstance();
      agent.init(appKey,appSecret,privateKey,oauthLoginServer);
      agent.loadALLPlugin();

     var ads_plugin   = agent.getAdsPlugin(); 
      ads_plugin.showAds(1);