‹ SdkboxAds Doc Home

SdkboxAds Integration Guide

For the Javascript version of cocos2d-x v3.x - (all other versions)



Open a terminal and use the following command to install the SDKBOX SdkboxAds plugin. Make sure you setup the SDKBOX installer correctly.

$ sdkbox import sdkboxadsplus

JSON Configuration

SDKBOX Installer will automatically create a sample configuration sdkbox_config.json for you

Here is an example of the SdkboxAds configuration:

    "SdkboxAds": {
        "units": [
        "placements": [
                "id" : "placement-1",
                "strategy" : "round-robin",
                "units" : [
                      "unit": "AdColony",
                      "name": "video"
                      "unit": "Chartboost",
                      "name": "Default"
                "id" : "placement-2",
                "strategy" : "round-robin",
                "units" : [
                      "unit": "Vungle",
                      "name": "reward"
                      "unit": "AdColony",
                      "name": "v4vc"
                      "unit": "Chartboost",
                      "name": "Next Level"


Register Javascript Functions

You need to register all the SdkboxAds JS functions with cocos2d-x before using them.

To do this: * Modify ./frameworks/runtime-src/Classes/AppDelegate.cpp to include the following headers:

#include "PluginSdkboxAdsJS.hpp"
#include "PluginSdkboxAdsJSHelper.h"

Initialize SdkboxAds

Initialize the plugin by calling init() where appropriate in your code. We recommend to do this in the app.js. Example:


Using SdkboxAds

To request a default Ad for the default AdUnit and have a fast integration test:


To request Ads in the Default AdUnit:

sdkbox.PluginSdkboxAds.play( zone_place_location, params );

// params is an object with string keys and values.

Note: the params are defined per AdUnit, and should be checked in each AdUnit's documentation.

To request Ads for an specific AdUnit:

sdkbox.PluginSdkboxAds.play( ad_unit_name, zone_place_location, params );

To request ads for a placement defined in the sdkbox_config.json file:

sdkbox.PluginSdkboxAds.placement( placement_name );

To have fine grained cache control (for AdUnits that expose it):

sdkbox.PluginSdkboxAds.cacheControl( ad_unit, cacheOpts );

// cacheOpts is an object with keys and values as strings. 

Cache options are AdUnit specific and must be checked in each AdUnit's documentation.

SdkboxAds events

This allows you to catch SdkboxAds events.

    onAdAction : function( ad_unit_id, zone_location_place_you_name_it, action_type),
    onRewardAction : function( ad_unit_id, zone_id, reward_amount, reward_succeed )

refer to the cpp documentation for action_type values.

API Reference



Initialize the plugin instance. The plugin initializes from the sdkbox_config.json file and reads configuration of the form:

   "SdkboxAds": {
       "units": [ "AdColony", "Fyber" ],
       "placements": [ {} ]
The "units" array references other plugins' configuration. Sdkboxads mediates between other plugins
and/or simplifies interaction with them.
The "placements" block will be of the form:
         "id" : "placement_id",
         "strategy" : "round-robin", // only value by now.
         "units" : [
and each UnitDefinition as:
         "Unit" : string, // result_of_AdUnit.getId(),
         "name" : string, // a zone, place, or location from AdUnit's lugin config
         "params" : json_object
For a sample Sdkboxads config, check the example at Sdkbox github public repository.
The "params" configuration block will allow to pass in specific information to play ads
like location, position, etc.
Check each AdUnit's documentation to find specifics on its configuration.

Set Sdkboxads' plugin listener. This listener will expose for each registered AdUnits, events related to Ads and Rewards. In SdkboxAds, an Ad refers generally to VIDEO, INTERSTITIAL and BANNER. Note that some ad units may have only Ads.


A placement is a collection of mediated AdUnits. When you want to invoke a placement, just call this method. If the placement does not exist, the call will just be ignored. A placement will take care of AdUnit’s cache control, so if the current AdUnit has no cached content, or the AdUnit fails to load an ad, the next adUnit will be used.

The placement will cycle throughout all the AdUnits it references, in a round robin fashion.
In the short term, new placement strategies will be added.
sdkbox.PluginSdkboxAds.cache(ad_unit, ad_name);

Cache AdUnits' ad Example: sdkbox::PluginSdkboxAds::cache("AdMob", "reward")


check if placement available


hide placement

sdkbox.PluginSdkboxAds.hideAd(ad_unit, zone_place_location);


Manual Integration

If the SDKBOX Installer fails to complete successfully, it is possible to integrate SDKBOX manually. If the installer complete successfully, please do not complete anymore of this document. It is not necessary.

These steps are listed last in this document on purpose as they are seldom needed. If you find yourself using these steps, please, after completing, double back and re-read the steps above for other integration items.

Manual Integration For iOS

Drag and drop the following frameworks from the plugins/ios folder of the SdkboxAds bundle into your Xcode project, check Copy items if needed when adding frameworks:



The above frameworks depend upon a large number of other frameworks. You also need to add the following system frameworks, if you don't already have them:



Also, all frameworks needed by each AdUnit you will be adding to SdkboxAds.

Copy all source and header files from plugin/jsbindings/ to your projects Classes folder.

NOTE: plugin/jsbindings/jsb2 for creator 1.7.

Add these same files, that you just copied, to Xcode by either dragging and dropping them into Xcode or by using File -> Add files to....

Manual Integration For Android

SDKBOX supports three different kinds of Android projects command-line, eclipse and Android Studio.

Copy Files

Copy the following jar files from plugin/android/libs folder of this bundle into your project's /libs folder.



Copy the sdkboxads_lib directories from plugin/android/libs to your <project_root>/libs/ directory.

Copy jni libs

Copy and overwrite all the folders from plugin/android/jni to your <project_root>/jni/ directory.

Edit AndroidManifest.xml

Include the following permissions above the application tag:

  <uses-permission android:name="android.permission.INTERNET" />

Edit Android.mk

Edit <project_root>/jni/Android.mk to:

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:


Add a call to:

$(call import-add-path,$(LOCAL_PATH))

before any import-module statements.

Add additional import-module statements at the end:

$(call import-module, ./sdkbox)
$(call import-module, ./pluginsdkboxads)

This means that your ordering should look similar to this:

$(call import-add-path,$(LOCAL_PATH))
$(call import-module, ./sdkbox)
$(call import-module, ./pluginsdkboxads)

Note: It is important to make sure these statements are above the existing $(call import-module,./prebuilt-mk) statement, if you are using the pre-built libraries.

Modify Application.mk (Cocos2d-x v3.0 to v3.2 only)

Edit <project_root>/jni/Application.mk to make sure APP_STL is defined correctly. If Application.mk contains APP_STL := c++_static, it should be changed to:

APP_STL := gnustl_static


For each AdUnit, you have to add:


All AdUnit's JNI library contents.


All changes needed by each AdUnit's plugin.


Jar files necessary for included AdUnits. Basically all jar files present in the Plugin's lib folder.

LOCAL_WHOLE_STATIC_LIBRARIES the module references for each of them, e.g.:


Android.mk import-module:

$(call import-module, ./pluginadcolony)
$(call import-module, ./pluginvungle)

Copy all source and header files from plugin/jsbindings/ to your projects Classes folder.

NOTE: plugin/jsbindings/jsb2 for creator 1.7.

Add all .cpp files, that you just copied, to Android.mk in the LOCAL_SRC_FILES section. Example

LOCAL_SRC_FILES := hellocpp/main.cpp \
                  ../../Classes/AppDelegate.cpp \
                  ../../Classes/HelloWorldScene.cpp \

Modify AppActivity.java

Plugin >=

  1. Find the AppActivity.java
find . -name "AppActivity.java"
  1. Replace extends Cocos2dxActivity with extends com.sdkbox.plugin.SDKBoxActivity

Example of the directory where the AppActivity.java file is located:

  - proj.android/src/org/cocos2dx/cpp/AppActivity.java
  - proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java
  - proj.android/app/src/org/cocos2dx/cpp/AppActivity.java ( from cocos2d-x 3.17)

  - frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java
  - frameworks/runtime-src/proj.android-studio/app/src/org/cocos2dx/lua/AppActivity.java
  - frameworks/runtime-src/proj.android/app/src/org/cocos2dx/lua/AppActivity.java (from cocos2d-x 3.17)

  - frameworks/runtime-src/proj.android/src/org/cocos2dx/javascript/AppActivity.java
  - frameworks/runtime-src/proj.android/app/src/org/cocos2dx/javascript/AppActivity.java ( from cocos2d-x 3.17)

Plugin <

Note: When using Cocos2d-x from source, different versions have Cocos2dxActivity.java in a different location. One way to find the location is to look in proj.android/project.properties. Example: android.library.reference.1=../../cocos2d-x/cocos/platform/android/java

In this case, Cocos2dxActivity.java should be located at:

import android.content.Intent;
import com.sdkbox.plugin.SDKBox;
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if(!SDKBox.onActivityResult(requestCode, resultCode, data)) {
            super.onActivityResult(requestCode, resultCode, data);
    protected void onStart() {
    protected void onStop() {
    protected void onResume() {
    protected void onPause() {
    public void onBackPressed() {
          if(!SDKBox.onBackPressed()) {

Proguard (optional)


Note: Proguard only works with Release builds (i.e cocos run -m release) debug builds do not invoke Proguard rules.