‹ InMobi Doc Home

InMobi Integration Guide

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


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

$ sdkbox import inmobi

Important Notice

Please make sure the following settings in your project for plugin to function correctly.

Disable App Transport Security

Adding the following entry to the info.plist file:


It should look something like this:

Disable Bitcode support

You have to turn off Bitcode support. If you don't cocos2d-x will fail to build.

Set your game requires full screen

If your game doesn't support all screen orientations you will need to check Requires full screen in Xcode. If you do not, your app will fail Apple's submission process.

Whitelist canOpenURL function

This depends on what plugins are in your project. You may need to add the required entry to the info.plist, under LSApplicationQueriesSchemes.

JSON Configuration

SDKBOX Installer will automatically inject a sample configuration to your res/sdkbox_config.json, that you have to modify it before you can use it for your own app

Here is an example of the InMobi configuration, you need to replace <account_id> item with your specific InMobi account information.

    "interstitial_placement_id": "1449919424310",       //interstitial id
    "account_id": "922cc696d9fa475097651b5cad78567d", 
    "banner_h": 50,                                     //banner height
    "banner_placement_id": "1447081423897"              //remove if needn't


Initialize InMobi

Initialize the plugin where appropriate in your code. We recommend to do this in the AppDelegate::applicationDidFinishLaunching() or AppController:didFinishLaunchingWithOptions(). Make sure to include the appropriate headers:

#include "PluginInMobi/PluginInMobi.h"

Show interstitial

After initialization you can begin to use the InMobi functionality:

// Manually Loading Ads

if (sdkbox::PluginInMobi::isInterstitialReady()) {
    CCLOG("Plugin InMobi interstitial ad is ready");
} else {
    CCLOG("Plugin InMobi interstitial ad is not ready");

Set Log level

You can set log level with follow function


Set user data

You can use following functions to set user data

sdkbox::PluginInMobi::addIdForType("test", sdkbox::PluginInMobi::SBIMSDKIdType::kIMSDKIdTypeLogin);
sdkbox::PluginInMobi::setLocation("cd", "sc", "usa");
sdkbox::PluginInMobi::setLocation(102, 348);

Catch InMobi events (optional)

This allows you to catch the InMobi events so that you can perform operations based upon responses. A simple example might look like this:

#include "PluginInMobi/PluginInMobi.h"
class MyClass : public sdkbox::InMobiListener {
    void bannerDidFinishLoading() {
    void bannerDidFailToLoadWithError(sdkbox::PluginInMobi::SBIMStatusCode code, const std::string& description) {
        CCLOG("bannerDidFailToLoadWithError status:%d, desc:%s", code, description.c_str());

    void bannerDidInteractWithParams(const std::map<std::string, std::string>& params) {

    void userWillLeaveApplicationFromBanner() {

    void bannerWillPresentScreen() {

    void bannerDidPresentScreen() {

    void bannerWillDismissScreen() {

    void bannerDidDismissScreen() {

    void bannerRewardActionCompletedWithRewards(const std::map<std::string, std::string>& rewards) {

    void interstitialDidFinishLoading() {

    void interstitialDidFailToLoadWithError(sdkbox::PluginInMobi::SBIMStatusCode code, const std::string& description) {
        CCLOG("interstitialDidFailToLoadWithError status:%d, desc:%s", code, description.c_str());

    void interstitialWillPresent() {

    void interstitialDidPresent() {

    void interstitialDidFailToPresentWithError(sdkbox::PluginInMobi::SBIMStatusCode code, const std::string& description) {

    void interstitialWillDismiss() {

    void interstitialDidDismiss() {

    void interstitialDidInteractWithParams(const std::map<std::string, std::string>& params) {

    void interstitialRewardActionCompletedWithRewards(const std::map<std::string, std::string>& rewards) {

    void userWillLeaveApplicationFromInterstitial() {

API Reference


static bool init ( ) ;

initialize the plugin instance.

static void setListener ( InMobiListener * listener ) ;

Set listener to listen for inmobi events

static InMobiListener * getListener ( ) ;

Get the listener

static void removeListener ( ) ;

Remove the listener, and can't listen to events anymore

static std::string getVersion ( ) ;

Use this to get the version of the SDK. @return The version of the SDK.

static void setLogLevel ( SBIMSDKLogLevel desiredLogLevel ) ;

Set the log level for SDK's logs @param desiredLogLevel The desired level of logs.

static void addIdForType ( const std::string & identifier ,
                           SBIMSDKIdType type ) ;

Register a user specific id with the SDK @param identifier The user Id. @param type The user Id type.

static void removeIdType ( SBIMSDKIdType type ) ;

Deregister a particular set of Ids @param type The user Id type.

static void setAge ( int age ) ;

Provide the user's age to the SDK for targeting purposes. @param age The user's age.

static void setAreaCode ( const std::string & areaCode ) ;

Provide the user's area code to the SDK for targeting purposes. @param areaCode The user's area code.

static void setAgeGroup ( SBIMSDKAgeGroup ageGroup ) ;

Provide the user's age group to the SDK for targeting purposes. @param ageGroup The user's age group.

static void setYearOfBirth ( int yearOfBirth ) ;

Provide a user's date of birth to the SDK for targeting purposes. @param dateOfBirth The user's date of birth.

static void setEducation ( SBIMSDKEducation education ) ;

Provide the user's education status to the SDK for targeting purposes. @param education The user's education status.

static void setEthnicity ( SBIMSDKEthnicity ethnicity ) ;

Provide the user's ethnicity to the SDK for targeting purposes. @param ethnicity The user's ethnicity.

static void setGender ( SBIMSDKGender gender ) ;

Provide the user's gender to the SDK for targeting purposes. @param gender The user's gender.

static void setHouseholdIncome ( SBIMSDKHouseholdIncome income ) ;

Provide the user's household income to the SDK for targeting purposes. @param income The user's household income.

static void setIncome ( unsigned int income ) ;

Provide the user's income to the SDK for targeting purposes. @param income The user's income.

static void setInterests ( const std::string & interests ) ;

Provide the user's interests to the SDK for targeting purposes. @param interests The user's interests.

static void setLanguage ( const std::string & language ) ;

Provide the user's preferred language to the SDK for targeting purposes. @param language The user's language.

static void setLocation ( const std::string & city ,
                          const std::string & state ,
                          const std::string & country ) ;

Provide the user's location to the SDK for targeting purposes. @param city The user's city. @param state The user's state. @param country The user's country.

static void setLocation ( double latitude , double longitude ) ;

Provide the user's location to the SDK for targeting purposes. @param location: The location of the user

static void setNationality ( const std::string & nationality ) ;

Provide the user's nationality to the SDK for targeting purposes. @param nationality The user's nationality.

static void setPostalCode ( const std::string & postalcode ) ;

Provide the user's postal code to the SDK for targeting purposes. @param postalcode The user's postalcode.

static void shouldAutoRefresh ( bool refresh ) ;

Control if the banner should auto-refresh ad content.

static void setRefreshInterval ( int interval ) ;

Specify the refresh interval for the banner ad.

static void loadBanner ( ) ;

Submit a request to load banner ad content.

static void disableHardwareAccelerationForBanner ( ) ;

Turn off hardware acceleration on the underlying views. vaild on android

static void setBannerAnimationType ( SBIMBannerAnimationType animationType ) ;

Set the animation preference on the banner views during ad refresh.

static void setBannerExtras ( const std::map <std::string ,
                              std::string> & extras ) ;

Set any additional custom parameters that will be sent in the ad request.

static void setBannerKeywords ( const std::string & keywords ) ;

Set comma delimited keywords for targeting purpose

static void loadInterstitial ( ) ;

Submit a request to load interstitial ad content.

static bool isInterstitialReady ( ) ;

Returns true if the interstitial was loaded successfully and in ready to be shown.

static void showInterstitial ( ) ;

Displays the interstitial on the screen

static void showInterstitial ( SBIMInterstitialAnimationType type ) ;

Displays the interstitial on the screen valid on ios

static void showInterstitial ( int enterAnimationResourcedId ,
                               int exitAnimationResourceId ) ;

Displays the interstitial on the screen valid on android

static void disableHardwareAccelerationForInterstitial ( ) ;

Disable hardware acceleration on the underlying views. valid on android

static void setInterstitialExtras ( const std::map <std::string ,
                                    std::string> & extras ) ;

Set any additional custom parameters that will be sent in the ad request.

static void setInterstitialKeywords ( const std::string & keywords ) ;

Set comma delimited keywords for targeting purpose


void bannerDidFinishLoading ( ) {

Notifies the delegate that the banner has finished loading

void bannerDidFailToLoadWithError ( PluginInMobi::SBIMStatusCode code ,
                                    const std::string & description ) {

Notifies the delegate that the banner has failed to load with some error.

void bannerDidInteractWithParams ( const std::map <std::string ,
                                   std::string> & params ) {

Notifies the delegate that the banner was interacted with.

void userWillLeaveApplicationFromBanner ( ) {

Notifies the delegate that the user would be taken out of the application context.

void bannerWillPresentScreen ( ) {

Notifies the delegate that the banner would be presenting a full screen content.

void bannerDidPresentScreen ( ) {

Notifies the delegate that the banner has finished presenting screen.

void bannerWillDismissScreen ( ) {

Notifies the delegate that the banner will start dismissing the presented screen.

void bannerDidDismissScreen ( ) {

Notifies the delegate that the banner has dismissed the presented screen.

void bannerRewardActionCompletedWithRewards ( const std::map <std::string ,
                                              std::string> & rewards );

Notifies the delegate that the user has completed the action to be incentivised with.

void interstitialDidFinishLoading ( ) {

Notifies the delegate that the interstitial has finished loading

void interstitialDidFailToLoadWithError ( PluginInMobi::SBIMStatusCode code ,
                                          const std::string & description ) {

Notifies the delegate that the interstitial has failed to load with some error.

void interstitialWillPresent ( ) {

Notifies the delegate that the interstitial would be presented.

void interstitialDidPresent ( ) {

Notifies the delegate that the interstitial has been presented.

void interstitialDidFailToPresentWithError ( PluginInMobi::SBIMStatusCode code ,
                                             const std::string & description ) {

Notifies the delegate that the interstitial has failed to present with some error.

void interstitialWillDismiss ( ) {

Notifies the delegate that the interstitial will be dismissed.

void interstitialDidDismiss ( ) {

Notifies the delegate that the interstitial has been dismissed.

void interstitialDidInteractWithParams ( const std::map <std::string ,
                                         std::string> & params ) {

Notifies the delegate that the interstitial has been interacted with.

void interstitialRewardActionCompletedWithRewards ( const std::map <std::string ,
                                                    std::string> & rewards );

Notifies the delegate that the user has performed the action to be incentivised with.

void userWillLeaveApplicationFromInterstitial ( ) {

Notifies the delegate that the user will leave application context.

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 InMobi bundle into your Xcode project, check Copy items if needed when adding frameworks:



add the following system frameworks, if you don't already have them:



















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 jni libs

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

Note: sdkbox link with gnustl by default, if your project link with c++static please replace the files in <project_root>/jni/<plugin_name>/libs with files in <project_root>/jni/<plugin_name>/libs_c++_static folder

Edit AndroidManifest.xml

<!--Mandatory permissions to receive ads-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<!--Recommended permissions to receive brand‐centric ads with interactive functionality for better eCPMs-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<!--Required Activity for rendering ads in the embedded browser-->
<activity android:name="com.inmobi.rendering.InMobiAdActivity"
            android:hardwareAccelerated="true" />

<!--Required Receiver for enhanced targeting for better ads.-->

<receiver android:name="com.inmobi.commons.core.utilities.uid.ImIdShareBroadCastReceiver"
            android:exported="true" >
       <action android:name="com.inmobi.share.id" />

<service android:enabled="true" android:name="com.inmobi.signals.activityrecognition.ActivityRecognitionManager" />

<!--Required for Google Play Services-->

<meta-data android:name="com.google.android.gms.version"

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, ./plugininmobi)

This means that your ordering should look similar to this:

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

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

Modify Cocos2dxActivity.java

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()) {

Manual Integration for Google Play Services SDK (dependent library only)


Please try the sdkbox installer first. It will do all the following step for you automatically.

$ sdkbox import googleplayservices

Modify project.properties

An Android Library Reference for Google Play Services is required. The path will be different depending upon your setup. Also, this is an additional download that does not come as part of a standard install. To install use the sdk installer and choose extras->google play services. Here is an example of what this line could look like:


Note: if you already have an android.library.reference.1 you can add another by incrementing the number as android.library.reference.2, etc.

Integration manually

We make a lite version of Google Play Services, the project repo is https://github.com/darkdukey/Google-Play-Service-Lite

Copy Files

Copy the gps folder from plugin folder of this bundle into your project’s /libs folder.

Modify files for Eclipse

  1. Modify project.properties
# For source project

# Or
# For framework project

Modify files for Android Studio

1. Modify cocos2d/cocos/platform/android/libcocos2dx/build.gradle
 dependencies {
+    compile project(':gps')
     compile fileTree(dir: '../java/libs', include: ['*.jar'])
2. Modify proj.android-studio/app/project.properties
 # Project target.
3. Modify proj.android-studio/settings.gradle
 project(':libcocos2dx').projectDir = new File(settingsDir, '../cocos2d/cocos/platform/android/libcocos2dx')
 include ':your_project_name'
 project(':your_project_name').projectDir = new File(settingsDir, 'app')
+include ':gps'
+project(':gps').projectDir = new File(settingsDir, '../cocos2d/cocos/platform/android/java/libs/gps')

Proguard (optional)

# inmobi
-keep class com.inmobi.** { *; }
-dontwarn com.inmobi.**

# cocos2d-x
-keep public class org.cocos2dx.** { *; }
-dontwarn org.cocos2dx.**
-keep public class com.chukong.** { *; }
-dontwarn com.chukong.**

# google play service
-keep public class com.google.android.gms.** { public *; }
-dontwarn com.google.android.gms.**

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;

-keep public class com.sdkbox.** { *; }
-dontwarn com.sdkbox.**

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