Bee7 Integration Guide
For the C++ version of cocos2d-x v3.x - (all other versions)
Intro
1.Before you start integrating the SDKBOX Bee7 plugin, you need to register with Bee7:
a) Create an account on Bee7's dashboard
b) Register your apps in Bee7 using the dashboard account
2.The API key and Scheme name values that you will bee needing in the code can be found in the dashboard, under your app's details.
3.Once the integration of the SDKBOX Bee7 plugin is complete, contact Bee7 Support to activate your app for production.
Prerequisites
-
For Android, Bee7 requires a minimum version of 4.0.3. This version is newer than what the other SDKBOX plugins require.
-
For iOS, Bee7's game wall currently supports only portrait orientation.
SDK Version
- ios: 2.11.6
- android: 2.3.9
Integration
Open a terminal and use the following command to install the SDKBOX Bee7 plugin. Make sure you setup the SDKBOX installer correctly.
$ sdkbox import bee7
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 create a sample configuration sdkbox_config.json
for you
Here is an example of the Bee7 configuration you can enable/disable debug mode for Bee7 here
"Bee7":
{
"debug":true,
"key":"FE74A9C4-1288-4F6F-8D6E-C365699F2C72"
}
Usage
Extra steps
The following step assumes you already registered at Bee7, created a new APP, and activated TEST state.
Setup iOS
-
Modify
Info.plist
, add URL Schemes:Target -> Info -> URL Types:
- click "+"
- fill "URL Schemes" with "your bee7 scheme". For testing, you can try "bee7orgcocos2dxbee7sample".
Setup Android
- Open
AndroidManifest.xml
and replace_replace_with_your_bee7_scheme_
with yourbee7 scheme
- Open
project.properties
and change target totarget=android-21
Initialize Bee7
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 "PluginBee7/PluginBee7.h"
AppDelegate::applicationDidFinishLaunching()
{
sdkbox::PluginBee7::init();
}
Using Bee7
Show Game Wall
sdkbox::PluginBee7::showGameWall();
Bee7 events
This allows you to catch Bee7
events so that you can perform operations after Bee7 events have occurred.
- Allow your class to extend
sdkbox::Bee7Listener
and override the functions listed:
#include "PluginBee7/PluginBee7.h"
class MyClass : public sdkbox::Bee7Listener
{
void onAvailableChange(bool available) = 0;
void onVisibleChange(bool available) = 0;
void onGameWallWillClose() = 0;
void onGiveReward(long bee7Points,
long virtualCurrencyAmount,
const std::string& appId,
bool cappedReward,
long campaignId,
bool videoReward) = 0;
};
- Create a listener that handles callbacks:
sdkbox::PluginBee7::setListener(this);
API Reference
Methods
static void init ( ) ;
initialize the plugin instance.
static void setListener ( Bee7Listener * listener ) ;
Set listener to listen for bee7 events
static Bee7Listener * getListener ( ) ;
Get the listener
static void removeListener ( ) ;
Remove the listener, and can't listen to events anymore
static void showGameWall ( ) ;
Listeners
void onAvailableChange ( bool available );
void onVisibleChange ( bool available );
void onGameWallWillClose ( );
void onGiveReward ( long bee7Points ,
long virtualCurrencyAmount ,
const std::string & appId ,
bool cappedReward ,
long campaignId ,
bool videoReward );
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
theBee7
bundle into your Xcode project, check Copy items if needed
when adding frameworks:
sdkbox.framework
PluginBee7.framework
Bee7GWResources.bundle
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:
MessageUI.framework
CoreMedia.framework
SystemConfiguration.framework
StoreKit.framework
AdSupport.framework
libsqlite3.dylib
CoreText.framework
GameController.framework
MediaPlayer.framework
Add separate linker flags to: Target -> Build Settings -> Linking -> Other Linker Flags:
-ObjC
Manual Integration For Android
SDKBOX supports three different kinds of Android projects command-line, eclipse and Android Studio.
proj.android
will be used as our<project_root>
for command-line and eclipse projectproj.android-studio
will be used as our<project_root>
for Android Studio project.
Copy Files
Copy the following jar files from plugin/android/libs
folder of this
bundle into your project's
PluginBee7.jar
sdkbox.jar
-
If you're using cocos2d-x from source copy the jar files to:
Android command-line:
cocos2d/cocos/platform/android/java/libs
Android Studio:
cocos2d/cocos/platform/android/java/libs cocos2d/cocos/platform/android/libcocos2dx/libs
-
If you're using cocos2d-js or lua copy the jar files to:
Android command-line:
frameworks/cocos2d-x/cocos/platform/android/java/libs
Android Studio:
frameworks/cocos2d-x/cocos/platform/android/java/libs frameworks/cocos2d-x/cocos/platform/android/libcocos2dx/libs
-
If you're using prebuilt cocos2d-x copy the jar files to:
Android command-line:
proj.android/libs
Copy jni libs
Copy and overwrite all the folders from plugin/android/jni
to your <project_root>/jni/
directory.
Copy the bee7-android-sdk-gamewall
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.ACCESS_NETWORK_STATE" />
Make sure that you have one of the two settings below, for proper function of the game wall's video component:
-
<uses-sdk>
with targetSdkVersion set to the latest Android SDK version available, for example:xml <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" .../>
-
The flag
android:hardwareAccelerated
set totrue
for your application (or for the activity that will display the game wall – that is a custom main activity):xml <application android:label="@string/app_name" android:icon="@drawable/icon" android:hardwareAccelerated="true"> </application>
There are also a few necessary meta-data tags that also need to be added:
<activity>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="your_bee7_scheme" android:host="publisher"/>
</intent-filter>
</activity>
<service
android:name="com.bee7.sdk.service.RewardingService"
android:process=":rewardingservice"
android:enabled="true">
</service>
<receiver android:name="com.bee7.sdk.publisher.RewardReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.bee7.action.REWARD" />
</intent-filter>
</receiver>
<receiver
android:name="com.bee7.sdk.service.RewardingServiceReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
Edit Android.mk
Edit <project_root>/jni/Android.mk
to:
Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:
LOCAL_WHOLE_STATIC_LIBRARIES += PluginBee7
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, ./pluginbee7)
This means that your ordering should look similar to this:
$(call import-add-path,$(LOCAL_PATH))
$(call import-module, ./sdkbox)
$(call import-module, ./pluginbee7)
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-21
Edit project.property
android.library.reference.1=./libs/bee7-android-sdk-gamewall
Modify AppActivity.java
Plugin >= 2.4.0.3
- Find the AppActivity.java
find . -name "AppActivity.java"
- Replace
extends Cocos2dxActivity
withextends 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
-
If you're using cocos2d-x from source, assuming you are in the proj.android directory, Cocos2dxActivity.java is located:
../../cocos2d-x/cocos/platform/android/java/src/org/cocos2dx/ lib/Cocos2dxActivity.java
-
If you're using the prebuilt cocos2d-x libraries assuming you are in the
proj.android
directory, Cocos2dxActivity.java is located:./src/org/cocos2dx/lib/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
- Modify Cocos2dxActivity.java to add the following imports:
import android.content.Intent;
import com.sdkbox.plugin.SDKBox;
- Second, modify Cocos2dxActivity.java to edit the
onCreate(final Bundle savedInstanceState)
function to add a call toSDKBox.init(this);
. The placement of this call is important. It must be done after the call toonLoadNativeLibraries();
. Example:
onLoadNativeLibraries();
SDKBox.init(this);
-
Last, we need to insert the proper overrides code. There are a few rules here.
-
If the method listed has not been defined, add it.
-
If the method listed has been defined, add the calls to
SDKBox
in the same existing function.
-
@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
-
If you're using cocos2d-x from source copy the
gps
folder to:Android command-line:
cocos2d/cocos/platform/android/java/libs
Android Studio:
cocos2d/cocos/platform/android/libcocos2dx/libs
-
If you're using cocos2d-js or lua copy the
gps
folder to:Android command-line:
frameworks/cocos2d-x/cocos/platform/android/java/libs
Android Studio:
frameworks/cocos2d-x/cocos/platform/android/libcocos2dx/libs
-
If you're using prebuilt cocos2d-x copy the
gps
folder to:Android command-line:
<project_root>/libs
Modify files for Eclipse
- 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)
- Edit
project.properties
to specify aProguard
configuration file. Example:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
- Edit the file you specified to include the following:
# bee7
-keep public class com.bee7.** { *; }
-dontwarn com.bee7.**
# 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 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.