‹ AdColony Doc Home

AdColony Integration Guide

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

Prerequisites

Certain SDKBOX plugins do not work together. If you use AdColony, then you cannot also use the Fyber and SOOMLA GROW services, in the same project.

Start from AdColony 3.0 it requires you to config your app to support all orientations, please read the details here

Integration

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

$ sdkbox import adcolony

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:

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

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 AdColony configuration, you need to replace <app id> and <zone id> items with your specific AdColony account information.

"AdColony":{
    "id":"<app id>",
    "debug":true,
    "ads":{
        "video":{
            "zone": "<zone id>",
            "v4vc": false
        },
        "v4vc":{
            "zone": "<zone id>",
            "v4vc": true,
            "pre_popup" : true,
            "post_popup": true
        }
    }
}

Usage

Initialize AdColony

#include "PluginAdColony/PluginAdColony.h"
AppDelegate::applicationDidFinishLaunching()
{
     sdkbox::PluginAdColony::init();
}

Showing Ads

Display an ad wherever you want from your code, by specifying ad type:

sdkbox::PluginAdColony::show("video");

or:

sdkbox::PluginAdColony::show("v4vc");

Catch AdColony events (optional)

This allows you to catch the AdColony events so that you can perform operations such as providing player rewards for watching the video.

#include "PluginAdColony/PluginAdColony.h"
class MyClass : public sdkbox::AdColonyListener
{
private:
  void onAdColonyChange(const sdkbox::AdColonyAdInfo& info, bool available);
  void onAdColonyReward(const sdkbox::AdColonyAdInfo& info,
        const std::string& currencyName, int amount, bool success);
  void onAdColonyStarted(const sdkbox::AdColonyAdInfo& info);
  void onAdColonyFinished(const sdkbox::AdColonyAdInfo& info);
};
sdkbox::PluginAdColony::setListener(this);

API Reference

Methods

static void init ( ) ;

initialize the plugin instance.

static void show ( const std::string & name ) ;

play video ad using provided name that was specified in sdkbox_config.json

static void setListener ( AdColonyListener * listener ) ;

Set listener to listen for adcolony events

static AdColonyListener * getListener ( ) ;

Get the listener

static void removeListener ( ) ;

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

static int zoneStatusForZone ( const std::string & zoneID ) ;

Returns the zone status for the specified zone.

static AdColonyAdStatus getStatus ( const std::string & name ) ;

Check the availability of the adcolony ads by name

static void setCustomID ( const std::string & customID ) ;

Assigns your own custom identifier to the current app user.

static std::string getCustomID ( ) ;

Returns the device's current custom identifier.

static std::string getUniqueDeviceID ( ) ;

Returns an AdColony-defined device identifier.

static std::string getAdvertisingIdentifier ( ) ;

Returns the device's advertising identifier.

static std::string getVendorIdentifier ( ) ;

Returns the device's vendor identifier.

static int getVideosPerReward ( const std::string & currencyName ) ;

Returns the number of ads that the user must play to earn the designated reward.

static int getVideoCreditBalance ( const std::string & currencyName ) ;

Returns the number of ads that the user has seen towards their next reward.

static void cancelAd ( ) ;

Cancels any full-screen ad that is currently playing and returns control to the app.

static bool videoAdCurrentlyRunning ( ) ;

Whether a full-screen AdColony ad is currently being played.

static void turnAllAdsOff ( ) ;

This method permanently turns off all AdColony ads for this app on the current device.

static void setUserMetadata ( const std::string & metadataType ,
                              const std::string & value ) ;

Provide AdColony with per-user non personally-identifiable information for ad targeting purposes.

static void userInterestedIn ( const std::string & topic ) ;

Provide AdColony with real-time feedback about what a user is interested in.

static void notifyIAPComplete ( const std::string & transactionID ,
                                const std::string & productID ,
                                int quantity ,
                                float price ,
                                const std::string & currencyCode ) ;

Call this method to report IAPs within your application. Note that this API can be leveraged to report standard IAPs as well as those triggered by AdColony’s IAP Promo (IAPP) advertisements and will improve overall ad targeting.

Listeners

void onAdColonyChange ( const AdColonyAdInfo & info , bool available );

called when AdColony is finished loading.

void onAdColonyReward ( const AdColonyAdInfo & info ,
                        const std::string & currencyName ,
                        int amount ,
                        bool success );

reward was received.

void onAdColonyStarted ( const AdColonyAdInfo & info );

showing an ad has started.

void onAdColonyFinished ( const AdColonyAdInfo & info );

showing an ad has finished.

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

sdkbox.framework

PluginAdColony.framework

AdColony.framework

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:

libz.1.2.5.dylib

AdSupport.framework (Set to Optional)

AudioToolbox.framework

AVFoundation.framework

CoreGraphics.framework

CoreMedia.framework

CoreTelephony.framework

EventKit.framework

EventKitUI.framework

MediaPlayer.framework

MessageUI.framework

QuartzCore.framework

Security.framework

GameController.framework

Social.framework (Set to Optional)

StoreKit.framework (Set to Optional)

SystemConfiguration.framework

WebKit.framework (Set to Optional)

Add two separate linker flags to: Target -> Build Settings -> Linking -> Other Linker Flags:

-ObjC

-fobjc-arc (this allows AdColony to use ARC even if your project does not)

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.

adcolony.jar

PluginAdColony.jar

sdkbox.jar

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

Include the following permissions above the application tag:

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

To enable hardware acceleration in your application tag. This tag is optional on newer SDK versions and doesn't work on version 2.3.3.

<android:hardwareAccelerated="true" />

Copy and paste the following three activity definitions just before the end of the application tags, near the bottom.

<activity android:name="com.jirbo.adcolony.AdColonyOverlay"
      android:configChanges="keyboardHidden|orientation"
      android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity android:name="com.jirbo.adcolony.AdColonyFullscreen"
      android:configChanges="keyboardHidden|orientation"
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
<activity android:name="com.jirbo.adcolony.AdColonyBrowser"
      android:configChanges="keyboardHidden|orientation"
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />

Note: if your application targets below API 13, you will likely need to remove screenSize from the configChanges property of the above activity tags.

Edit Android.mk

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

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:

LOCAL_WHOLE_STATIC_LIBRARIES += PluginAdColony
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, ./pluginadcolony)

This means that your ordering should look similar to this:

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

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:

../../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();
          }
    }

Proguard (optional)

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# adcolony
-dontwarn android.webkit.**

-dontwarn com.jirbo.adcolony.**
-keep public class com.jirbo.adcolony.** { 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 * 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.