‹ Appnext Doc Home

Appnext Integration Guide

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

SDK Version

Integration

Account Registration

you must sign up for Appnext and setup your app. make sure you have following items before proceeding to SDK integration

Appnext Account & ID

You must register for an Appnext Account in order to integrate the Appnext plugin. Log in to your Appnext account. If you do not have an Appnext account, copy the following URL to the browser: https://www.appnext.com and sign up.

Placement ID

A unique ID called a "Placement ID" is required for all inbound requests. A Placement ID is a 32-character string generated by Appnext for every registered app.

Get a Unique ID

To get started - add a new App via the Appnext Self-Service Platform, then copy the Placement ID, which can be found in your account at: Apps -> Settings Icon-> Settings & Placements -> Placement ID If you plan to show ads for both iOS and Android users, you will need to add a separate App for Android and a separate App for iOS and copy the Placement ID of each app.

Plugin Integration

Open a terminal and use the following command to install the SDKBOX Appnext plugin.

$ sdkbox import appnext

Extra steps

  1. For portrait iOS games with landscape video ad:

1.1 Edit RootViewController.mm file

```
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
    return UIInterfaceOrientationMaskPortrait; // only portrait here
#endif
}
- (BOOL) shouldAutorotate {
    return YES;
}
```

1.2 Add Landscape orientations support

For Full-Screen/Rewarded Ad: Landscape orientations (Landscape left/Landscape Right). Click on your project in the 'Project navigator'->'General'->'Device Orientation' and add the required orientations for both iPhone/iPad devices.

1.3 set "orientation":"landscape" in sdkbox_config.json

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 sdkbox_config.json, that you have to modify it before you can use it for your own app

options

more information:

Example:


{
    "ios": {
        "Appnext":{
            "debug":true,
            "ads": {
                "default": {
                    // Please replace this placement id with your own placement id from appnext
                    "id":"please_replace_with_your_placement_id",
                    "type":"interstitial",

                    "button_text":"Button Text",
                    "button_color":"#6AB344",
                    "categories":"Action,Puzzle",
                    "postback":"postback",

                    "skip_text":"Skip Text",
                    "mute":false,
                    "autoplay":true,
                    "creative_type":"managed"
                },
                "fullscreen": {
                    // Please replace this placement id with your own placement id from appnext
                    "id":"please_replace_with_your_placement_id",
                    "type":"fullscreen",

                    "button_text":"Button Text",
                    "button_color":"#6AB344",
                    "categories":"Action,Puzzle",
                    "postback":"postback",

                    "progress_type":"clock",
                    "progress_color":"#ffffff",
                    "show_close_button":true,
                    "video_lenght":"short",
                    "close_delay":5.0,
                    "orientation":"automatic"
                },
                "reward": {
                    // Please replace this placement id with your own placement id from appnext
                    "id":"please_replace_with_your_placement_id",
                    "type":"reward",

                    "button_text":"Button Text",
                    "button_color":"#6AB344",
                    "categories":"Action,Puzzle",
                    "postback":"postback",

                    "progress_type":"bar",
                    "progress_color":"#ffff00",
                    "show_close_button":true,
                    "video_lenght":"long",
                    "close_delay":5.0,
                    "orientation":"automatic"
                }
            }
        }
    },
    "android": {
        "Appnext":{
            "debug":true,
            "ads": {
                "default": {
                    // Please replace this placement id with your own placement id from appnext
                    "id":"please_replace_with_your_placement_id",
                    "type":"interstitial",

                    "button_text":"Button Text",
                    "button_color":"#6AB344",
                    "categories":"Action,Puzzle",
                    "postback":"postback",
                    "can_close":false,

                    "skip_text":"Skip Text",
                    "mute":false,
                    "autoplay":true,
                    "creative_type":"managed"
                },
                "fullscreen": {
                    // Please replace this placement id with your own placement id from appnext
                    "id":"please_replace_with_your_placement_id",
                    "type": "fullscreen",

                    "button_text":"Button Text",
                    "button_color":"#6AB344",
                    "categories":"Action,Puzzle",
                    "postback":"postback",
                    "can_close":false,

                    "progress_type":"clock",
                    "progress_color":"#ffffff",
                    "show_close_button":true,
                    "video_lenght":"short",
                    "orientation":"automatic"
                },
                "reward": {
                    // Please replace this placement id with your own placement id from appnext
                    "id":"please_replace_with_your_placement_id",
                    "type": "reward",

                    "button_text":"Button Text",
                    "button_color":"#6AB344",
                    "categories":"Action,Puzzle",
                    "postback":"postback",
                    "can_close":false,

                    "progress_type":"bar",
                    "progress_color":"#ffff00",
                    "show_close_button":false,
                    "video_lenght":"long",
                    "orientation":"automatic"
                }
            }
        }
    }
}

Usage

Initialize Appnext

sdkbox.PluginAppnext:init()

cache ad/video

sdkbox.PluginAppnext:cacheAd("default")
sdkbox.PluginAppnext:cacheVideo("fullscreen")

NOTE : Appnext ads needs to be cached before use, auto-caching is not available with this plugin. It might take couple of minutes to cache ads, once cached you would be able to see the ads. While caching, ads are not available.

refresh ad/video

sdkbox.PluginAppnext:refreshAds()
sdkbox.PluginAppnext:refreshVideo("fullscreen")

NOTE : refresh ad or video after it is closed.

show ad/video

sdkbox.PluginAppnext:showAd("default")
sdkbox.PluginAppnext:showVideo("fullscreen")

hide ad

sdkbox.PluginAppnext:hideAd()

check ad/video available

sdkbox.PluginAppnext:isAdReady()
sdkbox.PluginAppnext:isVideoReady("fullscreen")

Implement AppnextListner


sdkbox.PluginAppnext.setListener(function(args)
    local event = args.event
    if "onAdError" == event then
    elif "onAdLoaded" == event then
    elif "onAdOpened" == event then -- not support on android
    elif "onAdClosed" == event then
    elif "onAdClicked" == event then

    elif "onVideoLoaded" == event then
    elif "onVideoClicked" == event then
    elif "onVideoClosed" == event then
    elif "onVideoEnded" == event then   -- not support on ios
    elif "onVideoError" == event then
    end
end)

API Reference

Methods

sdkbox.PluginAppnext:init()

initialize the plugin instance.

sdkbox.PluginAppnext:setListener(listener)

Set listener to listen for appnext events

sdkbox.PluginAppnext:hideAd()

Hide advertisement

sdkbox.PluginAppnext:showAd()

Show advertisement

sdkbox.PluginAppnext:refreshAds()

Refresh advertisement

sdkbox.PluginAppnext:cacheAd(name)

Cache advertisement

sdkbox.PluginAppnext:isAdReady()

Check if advertisement is ready

sdkbox.PluginAppnext:cacheVideo(name)

Cache video with @name

sdkbox.PluginAppnext:showVideo(name)

show video with @name

sdkbox.PluginAppnext:refreshVideo(name)

Refresh video with @name

sdkbox.PluginAppnext:isVideoReady(name)

Check if video is ready with @name

sdkbox.PluginAppnext:setRewardsTransactionId(transactionId)

Set reward video transaction id

sdkbox.PluginAppnext:setRewardsUserId(userId)

Set reward video user id

sdkbox.PluginAppnext:setRewardsRewardTypeCurrency(currency)

Set type of reward, such as life / credit / points.

sdkbox.PluginAppnext:setRewardsAmountRewarded(amount)

Set the amount of currency that was rewarded.

sdkbox.PluginAppnext:setRewardsCustomParameter(parameter)

Set reward video custom parameter.

Listeners

onAdError(msg)
onAdLoaded()
onAdOpened()
onAdClosed()
onAdClicked()
onVideoLoaded(name)
onVideoClicked(name)
onVideoClosed(name)
onVideoEnded(name)
onVideoError(name, msg)

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

sdkbox.framework

PluginAppnext.framework

You also need to add the following system frameworks, if you don't already have them:

AdSupport.framework

SystemConfiguration.framework

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 everything 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.

Edit AndroidManifest.xml

Include the following permissions above the application tag:

<service android:name="com.appnext.core.DownloadService" />
<activity android:name="com.appnext.ads.interstitial.InterstitialActivity"
  android:hardwareAccelerated="true" android:configChanges="keyboardHidden|orientation|screenSize"
  android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
<activity android:name="com.appnext.ads.fullscreen.FullscreenActivity"
  android:hardwareAccelerated="true" android:configChanges="keyboardHidden|orientation|screenSize"
  android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />

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

Edit Android.mk

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

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:

LOCAL_WHOLE_STATIC_LIBRARIES += PluginAppnext
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, ./pluginappnext)

This means that your ordering should look similar to this:

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

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=proguard.cfg
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

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

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

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