‹ InMobi Doc Home

InMobi Integration Guide

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

SDK Version

Integration

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 to make the plugin work well.

Disable App Transport Security

Adding the following entry to the info.plist file:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

It should look 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 setting 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.

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

Usage

Initialize InMobi

Modify your Lua code to init() the plugin. This can be done anyplace, however it must be done before trying to use the plugin's features.

sdkbox.PluginInMobi:init()

Show interstitial

After initialization you can begin to use the InMobi functionality:

local plugin = sdkbox.PluginInMobi
plugin:setListener(function(args)
    local event = args.event
    dump(args, "inmobi listener info:")
end)
plugin:init()

-- Manually Loading Ads
-- plugin:loadInterstitial();

-- show intestitial
if plugin:isInterstitialReady() then
    print('inmobi interstitial ad is ready');
    plugin:showInterstitial();
else
    print('inmobi interstitial ad is not ready');
end

Set Log level

You can set log level with follow function

plugin:setLogLevel(sdkbox.PluginInMobi.SBIMSDKLogLevel.kIMSDKLogLevelDebug);

Set user data

You can use following functions to set user data

-- setting if need
print("inmobi plugin version:" .. plugin:getVersion());
plugin:setLogLevel(sdkbox.PluginInMobi.SBIMSDKLogLevel.kIMSDKLogLevelDebug);
plugin:addIdForType("test", sdkbox.PluginInMobi.SBIMSDKIdType.kIMSDKIdTypeLogin);
plugin:removeIdType(sdkbox.PluginInMobi.SBIMSDKIdType.kIMSDKIdTypeLogin);
plugin:setAge(18);
plugin:setAreaCode("area code");
plugin:setAgeGroup(sdkbox.PluginInMobi.SBIMSDKAgeGroup.kIMSDKAgeGroupBetween18And20);
plugin:setYearOfBirth(1989);
plugin:setEducation(sdkbox.PluginInMobi.SBIMSDKEducation.kIMSDKEducationHighSchoolOrLess);
plugin:setEthnicity(sdkbox.PluginInMobi.SBIMSDKEthnicity.kIMSDKEthnicityHispanic);
plugin:setGender(sdkbox.PluginInMobi.SBIMSDKGender.kIMSDKGenderMale);
plugin:setHouseholdIncome(sdkbox.PluginInMobi.SBIMSDKHouseholdIncome.kIMSDKHouseholdIncomeBelow5kUSD);
plugin:setIncome(4500);
plugin:setInterests("game");
plugin:setLanguage("zh-cn");
plugin:setLocation("cd", "sc", "usa");
plugin:setLocation(102, 348);
plugin:setNationality("nationality");
plugin:setPostalCode("618000");

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:

local plugin = sdkbox.PluginInMobi
plugin:setListener(function(args)
    local event = args.event -- event same with function name of InMobiListener
    dump(args, "inmobi listener info:")
end)
plugin:init()

API Reference

Methods

sdkbox.PluginInMobi:init()

initialize the plugin instance.

sdkbox.PluginInMobi:setListener(listener)

Set listener to listen for inmobi events

sdkbox.PluginInMobi:getVersion()

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

sdkbox.PluginInMobi:setLogLevel(desiredLogLevel)

Set the log level for SDK's logs

sdkbox.PluginInMobi:addIdForType(identifier, type)

Register a user specific id with the SDK

sdkbox.PluginInMobi:removeIdType(type)

Deregister a particular set of Ids

sdkbox.PluginInMobi:setAge(age)

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

sdkbox.PluginInMobi:setAreaCode(areaCode)

Provide the user's area code to the SDK for targeting purposes.

sdkbox.PluginInMobi:setAgeGroup(ageGroup)

Provide the user's age group to the SDK for targeting purposes.

sdkbox.PluginInMobi:setYearOfBirth(yearOfBirth)

Provide a user's date of birth to the SDK for targeting purposes.

sdkbox.PluginInMobi:setEducation(education)

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

sdkbox.PluginInMobi:setEthnicity(ethnicity)

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

sdkbox.PluginInMobi:setGender(gender)

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

sdkbox.PluginInMobi:setHouseholdIncome(income)

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

sdkbox.PluginInMobi:setIncome(income)

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

sdkbox.PluginInMobi:setInterests(interests)

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

sdkbox.PluginInMobi:setLanguage(language)

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

sdkbox.PluginInMobi:setLocation(city, state, country)

Provide the user's location to the SDK for targeting purposes.

sdkbox.PluginInMobi:setLocation(latitude, longitude)

Provide the user's location to the SDK for targeting purposes.

sdkbox.PluginInMobi:setNationality(nationality)

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

sdkbox.PluginInMobi:setPostalCode(postalcode)

Provide the user's postal code to the SDK for targeting purposes.

sdkbox.PluginInMobi:shouldAutoRefresh(refresh)

Control if the banner should auto-refresh ad content.

sdkbox.PluginInMobi:setRefreshInterval(interval)

Specify the refresh interval for the banner ad.

sdkbox.PluginInMobi:loadBanner()

Submit a request to load banner ad content.

sdkbox.PluginInMobi:disableHardwareAccelerationForBanner()

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

sdkbox.PluginInMobi:setBannerAnimationType(animationType)

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

sdkbox.PluginInMobi:setBannerKeywords(keywords)

Set comma delimited keywords for targeting purpose

sdkbox.PluginInMobi:hideBanner()

Hide Banner

sdkbox.PluginInMobi:loadInterstitial(ad)

Submit a request to load interstitial ad content.

sdkbox.PluginInMobi:isInterstitialReady(ad)

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

sdkbox.PluginInMobi:showInterstitial(ad)

Displays the interstitial on the screen

sdkbox.PluginInMobi:showInterstitial(type, ad)

Displays the interstitial on the screen valid on ios

sdkbox.PluginInMobi:showInterstitial(enterAnimationResourcedId,
                                      exitAnimationResourceId,
                                      ad)

Displays the interstitial on the screen valid on android

sdkbox.PluginInMobi:disableHardwareAccelerationForInterstitial(ad)

Disable hardware acceleration on the underlying views. valid on android

sdkbox.PluginInMobi:setInterstitialKeywords(keywords, ad)

Set comma delimited keywords for targeting purpose

Listeners

bannerDidFinishLoading()

Notifies the delegate that the banner has finished loading

bannerDidFailToLoadWithError(code, description)

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

bannerDidInteractWithParams(params)

Notifies the delegate that the banner was interacted with.

userWillLeaveApplicationFromBanner()

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

bannerWillPresentScreen()

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

bannerDidPresentScreen()

Notifies the delegate that the banner has finished presenting screen.

bannerWillDismissScreen()

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

bannerDidDismissScreen()

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

bannerRewardActionCompletedWithRewards(rewards)

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

interstitialDidFinishLoading()

Notifies the delegate that the interstitial has finished loading

interstitialDidFailToLoadWithError(code, description)

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

interstitialWillPresent()

Notifies the delegate that the interstitial would be presented.

interstitialDidPresent()

Notifies the delegate that the interstitial has been presented.

interstitialDidFailToPresentWithError(code, description)

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

interstitialWillDismiss()

Notifies the delegate that the interstitial will be dismissed.

interstitialDidDismiss()

Notifies the delegate that the interstitial has been dismissed.

interstitialDidInteractWithParams(params)

Notifies the delegate that the interstitial has been interacted with.

interstitialRewardActionCompletedWithRewards(rewards)

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

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:

sdkbox.framework

PluginInMobi.framework

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

AdSupport.framework

AudioToolbox.framework

AVFoundation.framework

CoreLocation.framework

CoreTelephony.framework

EventKit.framework

EventKitUI.framework

MediaPlayer.framework

MessageUI.framework

Security.framework

Social.framework

StoreKit.framework

SystemConfiguration.framework

UIKit.framework

SafariServices.framework

GameController.framework

libsqlite3.0.tbd

libc++.tbd

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

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.

InMobiLib.jar

PluginInMobi.jar

sdkbox.jar

Copy jni libs

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

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:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:hardwareAccelerated="true" />


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

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

<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"
            android:value="@integer/google_play_services_version"/>

Edit Android.mk

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

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:

LOCAL_WHOLE_STATIC_LIBRARIES += PluginInMobi
LOCAL_WHOLE_STATIC_LIBRARIES += sdkbox

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

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

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 \
                                ../../Classes/NewSourceFile.cpp

Modify AppActivity.java

Plugin >= 2.4.0.3

  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:

cpp
  - 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)

lua
  - 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)

js
  - 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 < 2.4.0.3

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:

../../cocos2d-x/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java
import android.content.Intent;
import com.sdkbox.plugin.SDKBox;
onLoadNativeLibraries();
SDKBox.init(this);
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if(!SDKBox.onActivityResult(requestCode, resultCode, data)) {
            super.onActivityResult(requestCode, resultCode, data);
          }
    }
    @Override
    protected void onStart() {
          super.onStart();
          SDKBox.onStart();
    }
    @Override
    protected void onStop() {
          super.onStop();
          SDKBox.onStop();
    }
    @Override
    protected void onResume() {
          super.onResume();
          SDKBox.onResume();
    }
    @Override
    protected void onPause() {
          super.onPause();
          SDKBox.onPause();
    }
    @Override
    public void onBackPressed() {
          if(!SDKBox.onBackPressed()) {
            super.onBackPressed();
          }
    }

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

Suggestion

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:

android.library.reference.1=
../android/sdk.latest/extras/google/google_play_services/libproject/
google-play-services_lib

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
android.library.reference.2=../cocos2d/cocos/platform/android/java/libs/gps/

# Or
# For framework project
android.library.reference.1=libs/gps/

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.
 target=android-14
+android.library.reference.1=../cocos2d/cocos/platform/android/java/libs/gps/
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)

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# 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 com.google.protobuf.** { *; }
-dontwarn com.google.protobuf.**

-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;
}

#sdkbox
-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.