‹ Fyber Doc Home

Fyber Integration Guide

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

Prerequisites

SDK Version

Integration

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

$ sdkbox import fyber

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.

Extra steps

The following step assuming you already registered as a Fyber Developer And created a new APP on Fyber

Setup iOS

Setup Android

Setup Mediation

If you want to setup fyber to use certain mediation network, please follow fyber's official integration guide

JSON Configuration

SDKBOX Installer will automatically create a sample configuration sdkbox_config.json for you

Here is an example of the Fyber configuration you can enable/disable debug mode for Fyber here

"Fyber":
{
    "debug":true,
    "appid":"12345",
    "token":"34a9643edf4d3052d2bc1928b2e34d00"
}

Usage

Register Javascript Functions

You need to register all the Fyber JS functions with cocos2d-x before using them.

To do this: * Modify ./frameworks/runtime-src/Classes/AppDelegate.cpp to include the following headers:

#include "PluginFyberJS.hpp"
#include "PluginFyberJSHelper.h"
sc->addRegisterCallback(register_all_PluginFyberJS);
sc->addRegisterCallback(register_all_PluginFyberJS_helper);

Initialize Fyber

Initialize the plugin by calling init() where appropriate in your code. We recommend to do this in the app.js. Example:

sdkbox.PluginFyber.init();

Using Fyber

Offer Wall

Displaying the Offer Wall with default placementId

sdkbox.PluginFyber.showOfferWall();

Displaying the Offer Wall with custom placementId

sdkbox.PluginFyber.showOfferWall("coins");

Request Coin

sdkbox.PluginFyber.requestDeltaOfCoins();
// sdkbox.PluginFyber.requestDeltaOfCoins("coins");

//
// **Best Practice Check**
//
// Some Offer Wall requests can take a few moments longer to load, so ensure that you've configured
// for a potential 5 second delay.

// Although we recommend you call the VCS when returning from the Offer Wall (after a short delay;
// recommended 5 seconds), you can also call when you're loading the screen that shows currency or
// after the user comes back from the Offer Wall.

Fyber iOS, Fyber Android

Rewarded Video

Queries the server for BrandEngage offers availability with default placementId.

sdkbox.PluginFyber.requestOffers();

Queries the server for BrandEngage offers availability with custom placementId.

sdkbox.PluginFyber.requestOffers("coins");

Display an available rewarded video, call requestOffers() first and then showOffers(). Developer can requestOffers() anytime, then showOffers() without any delay:

sdkbox.PluginFyber.requestOffers();
sdkbox.PluginFyber.showOffers();

Interstitials

Check if interstitial ads are available

sdkbox.PluginFyber.requestInterstitial();

Shows an interstitial ad. call requestInterstitial first.

sdkbox.PluginFyber.showInterstitial();

Fetches the amount of a given currency earned since the last time this method was invoked for the current user ID / app ID combination.

sdkbox.PluginFyber.requestDeltaOfCoins();

or

sdkbox.PluginFyber.requestDeltaOfCoins("currencyId")

Fyber events

This allows you to catch Fyber events so that you can perform operations after Fyber events have occurred.

sdkbox.PluginFyber.setListener({
    onVirtualCurrencyConnectorFailed: function(error, errorCode, errorMsg) {},
    onVirtualCurrencyConnectorSuccess: function(deltaOfCoins, currencyId, currencyName, transactionId) {},
    onCanShowInterstitial: function(canShowInterstitial) {},
    onInterstitialDidShow: function() {},
    onInterstitialDismiss: function(reason) {},
    onInterstitialFailed: function() {},
    onBrandEngageClientReceiveOffers: function(areOffersAvailable) {},
    onBrandEngageClientChangeStatus: function(status, msg) {},
    onOfferWallFinish: function(status) {}
});

API Reference

Methods

sdkbox.PluginFyber.init(userID, jsonconfig);

initialize the fyber plugin.

sdkbox.PluginFyber.showOfferWall(placementId);

Presents the Fyber Mobile OfferWall as a child view controller of your own view controller.

@placementId (deprecated)
sdkbox.PluginFyber.requestOffers(placementId);

Request the server for rewarded video availability.

sdkbox.PluginFyber.showOffers(placementId);

Show an available rewarded video.

@placementId (deprecated)
sdkbox.PluginFyber.requestInterstitial();

Check if interstitial ads are available

sdkbox.PluginFyber.showInterstitial();

Shows an interstitial ad. Check first that one is ready to be shown with requestInterstitial.

sdkbox.PluginFyber.requestDeltaOfCoins(currencyId);

Fetches the amount of a given currency earned since the last time this method was invoked for the current user ID / app ID combination.

sdkbox.PluginFyber.setAge(age);

Sets the user's age

 @param age Age of the user. Pass `FYBEntryIgnore` if value needs to be ignored or to be removed, if already exists
sdkbox.PluginFyber.setBirthdate(data);

Sets the user's date of birth, format (yyyy-MM-dd)

 @param date Date of birth of the user. Pass `""` if value needs to be ignored or to be removed, if already exists
sdkbox.PluginFyber.setGender(gender);

Sets the user's gender

 @param gender Gender of the user. Pass FYB_UserGenderUndefined if value needs to be ignored or to be removed, if already exists
sdkbox.PluginFyber.setSexualOrientation(sexualOrientation);

Sets the user's sexual orientation

 @param sexualOrientation Sexual orientation of the user. Pass FYB_UserSexualOrientationUndefined if value needs to be ignored or to be removed, if already exists.
sdkbox.PluginFyber.setEthnicity(ethnicity);

Sets the user's ethnicity

 @param ethnicity Ethnicity of the user. Pass FYB_UserEthnicityUndefined if value needs to be ignored or to be removed, if already exists
sdkbox.PluginFyber.setLocation(latitude, longitude);

Set the user's location

sdkbox.PluginFyber.cleanLocation();

Clean the user's location

sdkbox.PluginFyber.setMaritalStatus(status);

Sets the user's marital status

 @param status Marital status of the user. Pass FYB_UserMaritalStatusUndefined if value needs to be ignored or to be removed if already exists
sdkbox.PluginFyber.setNumberOfChildren(numberOfChildren);

Sets the user's number of children

 @param numberOfChildren The number of children
sdkbox.PluginFyber.setAnnualHouseholdIncome(income);

Sets the user's annual household income

 @param income Annual household income of the user. Pass `FYB_EntryIgnore` if value needs to be ignored or to be removed, if already exists
sdkbox.PluginFyber.setEducation(education);

Sets the user's educational background

 @param education Education of the user. Pass FYB_UserEducationUndefined if value needs to be ignored or to be removed, if already exists
sdkbox.PluginFyber.setZipcode(zipcode);

Sets the user's zipcode

 @param zipcode Zipcode of the current living place of the user. Pass `""` if value needs to be ignored or to be removed, if already exists
sdkbox.PluginFyber.setInterests(interests);

Set the user's list of interests

 @param interests List of interests of the user. Pass `{}` if value needs to be ignored or to be removed, if already exists
sdkbox.PluginFyber.setIap(flag);

Sets if in-app purchases are enabled.

 @param flag Sets if in-app purchases are enabled
sdkbox.PluginFyber.setIapAmount(amount);

Sets the amount that the user has already spent on in-app purchases

 @param amount The amount of money that the user has spent
sdkbox.PluginFyber.setNumberOfSessions(numberOfSessions);

Sets the number of sessions

 @param numberOfSessions The number of sessions that has already been started
sdkbox.PluginFyber.setPsTime(timestamp);

Sets the time spent on the current session

 @param timestamp The time spent on the current session
sdkbox.PluginFyber.setLastSession(session);

Sets the duration of the last session

 @param session The duration of the last session
sdkbox.PluginFyber.setConnectionType(connectionType);

Sets the connection type used by the user

 @param connectionType The connection type used by the user
sdkbox.PluginFyber.setDevice(device);

Sets the device used by the user

 @param device The device used by the user
sdkbox.PluginFyber.setVersion(version);

Sets the app version

 @param version The version of the app currently executed
sdkbox.PluginFyber.cleanCustomParameters();

Clean custom parameters, iOS only

sdkbox.PluginFyber.addCustomParameters(key, value);

Sets custom parameters to be sent along with the standard parameters

 @param parameters The custom parameters that must be set

Listeners

onVirtualCurrencyConnectorFailed(error, errorCode, errorMsg);
onVirtualCurrencyConnectorSuccess(deltaOfCoins,
                                   currencyId,
                                   currencyName,
                                   transactionId);
onCanShowInterstitial(canShowInterstitial);
onInterstitialDidShow();
onInterstitialDismiss(reason);
onInterstitialFailed();
onBrandEngageClientReceiveOffers(areOffersAvailable);
onBrandEngageClientChangeStatus(status, msg);
onOfferWallFinish(status);

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

sdkbox.framework

PluginFyber.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:

AdSupport.framework

CoreGraphics.framework

CoreLocation.framework

CoreTelephony.framework

MediaPlayer.framework

QuartzCore.framework

StoreKit.framework

SystemConfiguration.framework

Security.framework

CFNetwork.framework

GameController.framework

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

-ObjC

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

NOTE: plugin/jsbindings/jsb2 for creator 1.7.

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.

PluginFyber.jar

sdkbox.jar

Copy jni libs

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

Copy the fyber_lib directories from plugin/android/libs to your <project_root>/libs/ directory.

Edit AndroidManifest.xml

Include the following permissions above the application tag:

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

There are also a few necessary meta-data tags that also need to be added:

<activity
    android:name="com.fyber.ads.ofw.OfferWallActivity"
    android:configChanges="screenSize|orientation" />
<activity
    android:name="com.fyber.ads.videos.RewardedVideoActivity"
    android:configChanges="screenSize|orientation"
    android:hardwareAccelerated="true"
  android:theme="@android:style/Theme.Translucent" />
<activity
    android:name="com.fyber.ads.interstitials.InterstitialActivity"
    android:configChanges="screenSize|orientation"
    android:theme="@android:style/Theme.Translucent" />
<activity
    android:configChanges="screenSize|orientation"
    android:name="com.fyber.cache.CacheVideoDownloadService"
    android:hardwareAccelerated="true"/>
<service android:name="com.fyber.cache.CacheVideoDownloadService" android:exported="false" />

Edit Android.mk

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

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:

LOCAL_WHOLE_STATIC_LIBRARIES += PluginFyber
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, ./pluginfyber)

This means that your ordering should look similar to this:

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

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

Add APP_PATFORM version requirements:

APP_PLATFORM := android-14

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

NOTE: plugin/jsbindings/jsb2 for creator 1.7.

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

-keep class com.fyber.** { *; }
-dontwarn com.fyber.**
-keep class com.sponsorpay.mediation.** { *;}
-keepattributes JavascriptInterface
-keep class com.sponsorpay.publisher.mbe.mediation.SPBrandEngageMediationJSInterface {
    void setValue(java.lang.String);
}
-keep class android.webkit.JavascriptInterface


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

# google play service
-keep class com.google.android.gms.** { *; }
-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 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.