‹ Appodeal Doc Home

Appodeal Integration Guide

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

SDK Version

Prerequisites

Certain SDKBOX plugins do not work together. If you use Appodeal, then you cannot also use the Flurry Analytics and Chartboost services, in the same project.

NOTE: Please note that Appodeal only supports iOS 8.0+

Integration

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

$ sdkbox import appodeal

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.

Add this key in Info.plist , if you use this function in your app

<key>NSBluetoothPeripheralUsageDescription</key>
<string>Advertising</string>
<key>NSCalendarsUsageDescription</key>
<string>Advertising</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Advertising</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Advertising</string>

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 Appodeal configuration, you need to replace <app_key> items with your specific Appodeal Key account information.

"Appodeal":{
    "app_key":"2cfc9cc638980eb7f5ff35d6eb63dbe404503151ccc451ed"
}

Usage

Initialize Appodeal

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 "PluginAppodeal/PluginAppodeal.h"
AppDelegate::applicationDidFinishLaunching()
{
     sdkbox::PluginAppodeal::init();
}

Using Appodeal

After initialization you can begin to use the Appodeal functionality:

// set user id
sdkbox::PluginAppodeal::setUserVkId("user id");
// cache all type ad
sdkbox::PluginAppodeal::cacheAd(sdkbox::PluginAppodeal::AdType::AppodealAdTypeAll);
//show interstitial ad
sdkbox::PluginAppodeal::showAd(sdkbox::PluginAppodeal::ShowStyle::AppodealShowStyleInterstitial);

Catch Appodeal events (optional)

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

#include "PluginAppodeal/PluginAppodeal.h"
class ADListener : public sdkbox::AppodealListener {
public:
    virtual void onBannerDidLoadAd();
    virtual void onBannerDidFailToLoadAd();
    virtual void onBannerDidClick();
    virtual void onBannerPresent();

    virtual void onInterstitialDidLoadAd();
    virtual void onInterstitialDidFailToLoadAd();
    virtual void onInterstitialWillPresent();
    virtual void onInterstitialDidDismiss();
    virtual void onInterstitialDidClick();

    virtual void onVideoDidLoadAd();
    virtual void onVideoDidFailToLoadAd();
    virtual void onVideoDidPresent();
    virtual void onVideoWillDismiss();
    virtual void onVideoDidFinish();
};
sdkbox::PluginAppodeal::setListener(this);

API Reference

Methods

static bool init ( AdType adType = AdType::AppodealAdTypeAll ) ;

initialize the plugin instance.

static void setListener ( AppodealListener * listener ) ;

Set listener to listen for appodeal events

static AppodealListener * getListener ( ) ;

Get the listener

static void removeListener ( ) ;

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

static std::string getSDKVersion ( ) ;
static void disableNetworkForAdType ( AdType adType ,
                                      const std::string & networkName ) ;

deprecated

static void disableLocationPermissionCheck ( ) ;
static void setAutocache ( bool autocache , AdType types ) ;
static bool isAutocacheEnabled ( AdType types ) ;
static void confirmUsage ( AdType adTypes ) ;
static void setDebugEnabled ( bool debugEnabled ) ;
static bool showAd ( ShowStyle style ) ;
static void cacheAd ( AdType type ) ;
static void hideBanner ( ) ;
static bool isReadyForShowWithStyle ( ShowStyle showStyle ) ;
static void setSmartBannersEnabled ( bool smartBannerEnabled ) ;
static void setBannerBackgroundVisible ( bool bannerBackgroundVisible ) ;
static void setBannerAnimationEnabled ( bool bannerAnimationEnabled ) ;
static void setUserVkId ( const std::string & vkId ) ;
static void setUserFacebookId ( const std::string & facebookId ) ;
static void setUserEmail ( const std::string & email ) ;
static void setUserBirthday ( const std::string & birthday ) ;
static void setUserAge ( int age ) ;
static void setUserGender ( Gender gender ) ;
static void setUserOccupation ( Occupation occupation ) ;
static void setUserRelationship ( Relationship relationship ) ;
static void setUserSmokingAttitude ( SmokingAttitude smokingAttitude ) ;
static void setUserAlcoholAttitude ( AlcoholAttitude alcoholAttitude ) ;
static void setUserInterests ( const std::string & interests ) ;

Listeners

void onBannerDidLoadAd ( ) 

trigger when banner ad load

void onBannerDidFailToLoadAd ( ) 

trigger when banner ad fail to load

void onBannerDidClick ( ) 

trigger when banner ad clicked

void onBannerPresent ( ) 

trigger when banner ad present

void onInterstitialDidLoadAd ( ) 

trigger when interstitial ad load

void onInterstitialDidFailToLoadAd ( ) 

trigger when interstitial ad fail to load

void onInterstitialWillPresent ( ) 

trigger when interstitial ad present

void onInterstitialDidDismiss ( ) 

trigger when interstitial dismiss

void onInterstitialDidClick ( ) 

trigger when interstitial ad clicked

void onInterstitialDidFailToPresent ( ) 

trigger when interstitial ad fail to present

void onVideoDidLoadAd ( ) 

trigger when video load deprecated

void onVideoDidFailToLoadAd ( ) 

trigger when video fail to load deprecated

void onVideoDidPresent ( ) 

trigger when video present deprecated

void onVideoWillDismiss ( ) 

trigger when video dismiss deprecated

void onVideoDidFinish ( ) 

trigger when video finish deprecated

void onRewardVideoDidLoadAd ( ) 

trigger when reward video load

void onRewardVideoDidFailToLoadAd ( ) 

trigger when reward video fail to load

void onRewardVideoDidPresent ( ) 

trigger when reward video present

void onRewardVideoWillDismiss ( ) 

trigger when reward video dismiss

void onRewardVideoDidFinish ( int amount , const std::string & name ) 

trigger when reward video finish

void onRewardVideoDidFailToPresent ( ) 

trigger when reward video fail to present

void onSkippableVideoDidLoadAd ( ) 

trigger when skippable video load

void onSkippableVideoDidFailToLoadAd ( ) 

trigger when skippable video fial to load

void onSkippableVideoDidPresent ( ) 

trigger when skippable video present

void onSkippableVideoWillDismiss ( ) 

trigger when skippable video dismiss

void onSkippableVideoDidFinish ( ) 

trigger when skippable video finish

void onSkippableVideoDidClick ( ) 

trigger when skippable video click

void onNonSkippableVideoDidLoadAd ( ) 

trigger when nonskippable video load

void onNonSkippableVideoDidFailToLoadAd ( ) 

trigger when nonskippable video fial to load

void onNonSkippableVideoDidPresent ( ) 

trigger when nonskippable video present

void onNonSkippableVideoWillDismiss ( ) 

trigger when nonskippable video dismiss

void onNonSkippableVideoDidFinish ( ) 

trigger when nonskippable video finish

void onNonSkippableVideoDidClick ( ) 

trigger when nonskippable video click

void onNonSkippableVideoDidFailToPresent ( ) 

trigger when nonskippable video fail to present

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

sdkbox.framework

PluginAppodeal.framework

Appodeal.framework

plugin_appodeal_res_bundle

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

AdSupport.framework

AudioToolbox.framework

AVFoundation.framework

CFNetwork.framework

CoreFoundation.framework

CoreGraphics.framework

CoreImage.framework

CoreLocation.framework

CoreMedia.framework

CoreMotion.framework

CoreTelephony.framework

EventKit.framework

EventKitUI.framework

libc++.tbd

libsqlite3.tbd

libxml2.2.tbd

libz.tbd

MediaPlayer.framework

MessageUI.framework

MobileCoreServices.framework

QuartzCore.framework

Security.framework

Social.framework

StoreKit.framework

SystemConfiguration.framework

Twitter.framework

UIKit.framework

WebKit.framework

GameController.framework

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.

PluginAppodeal.jar

sdkbox.jar

android-support-v4-22.2.1.jar

applovin-sdk-6.0.1.jar

appodeal-1.13.1.jar

chartboost-5.2.0.jar

my-target-4.0.13.jar

unity-ads-1.4.7.jar

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.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

There are also necessary meta-data and activity tags that also need to be added:

<meta-data android:name="com.appodeal.framework" android:value="sdkbox" />
<activity android:name="com.appodeal.ads.InterstitialActivity"
        android:configChanges="orientation|screenSize"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity android:name="com.appodeal.ads.VideoActivity"
        android:configChanges="orientation|screenSize"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />

<activity android:name="com.appodeal.ads.LoaderActivity"
        android:configChanges="orientation|screenSize"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

<activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />

<activity android:name="com.chartboost.sdk.CBImpressionActivity"
        android:theme="@android:style/Theme.Translucent"
        android:excludeFromRecents="true" />

<activity android:name="com.applovin.adview.AppLovinInterstitialActivity"
        android:theme="@android:style/Theme.Translucent" />

<activity android:name="com.mopub.mobileads.MoPubActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:theme="@android:style/Theme.Translucent" />
<activity android:name="com.mopub.common.MoPubBrowser"
        android:configChanges="keyboardHidden|orientation|screenSize" />
<activity android:name="com.mopub.mobileads.MraidActivity"
        android:configChanges="keyboardHidden|orientation|screenSize" />
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity"
        android:configChanges="keyboardHidden|orientation|screenSize" />

<activity android:name="org.nexage.sourcekit.mraid.MRAIDBrowser"
        android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
        android:theme="@android:style/Theme.Translucent" />

<activity android:name="com.amazon.device.ads.AdActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"/>

<activity android:name="com.unity3d.ads.android.view.UnityAdsFullscreenActivity"
        android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:hardwareAccelerated="true" />

<activity android:name="ru.mail.android.mytarget.ads.MyTargetActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

<activity android:name="org.nexage.sourcekit.vast.activity.VASTActivity"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />

<activity android:name="com.facebook.ads.InterstitialAdActivity"
        android:configChanges="keyboardHidden|orientation|screenSize" />

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

<activity android:name="com.vungle.publisher.FullScreenAdActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

Edit Android.mk

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

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:

LOCAL_WHOLE_STATIC_LIBRARIES += PluginAppodeal
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, ./pluginappodeal)

This means that your ordering should look similar to this:

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

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 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
# appodeal

-keep class com.appodeal.** { *; }
-keep class com.amazon.** { *; }
-keep class com.mopub.** { *; }
-keep class org.nexage.** { *; }
-keep class com.applovin.** { *; }
-keep class com.chartboost.** { *; }
-keep class com.unity3d.ads.** { *; }
-keep class com.applifier.** { *; }
-keep class com.yandex.** { *; }
-keep class com.inmobi.** { *; }
-keep class ru.mail.android.mytarget.** { *; }
-keep class com.google.android.gms.ads.** { *; }
-keep class com.google.android.gms.common.GooglePlayServicesUtil { *; }
-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;
}
-dontwarn com.facebook.ads.**
-dontwarn com.jirbo.adcolony.**
-dontwarn com.vungle.**
-dontwarn com.startapp.**
-dontwarn com.yandex.**
-dontwarn com.inmobi.**
-keep class android.support.v4.app.Fragment { *; }
-keep class android.support.v4.app.FragmentActivity { *; }
-keep class android.support.v4.app.FragmentManager { *; }
-keep class android.support.v4.app.FragmentTransaction { *; }
-keep class android.support.v4.content.LocalBroadcastManager { *; }
-keep class android.support.v4.util.LruCache { *; }
-keep class android.support.v4.view.PagerAdapter { *; }
-keep class android.support.v4.view.ViewPager { *; }

-dontwarn com.appodeal.**
-dontwarn ru.mail.android.mytarget.**


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