‹ PhunwareMessaging Doc Home

Phunware Integration Guide(Messaging)

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


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

$ sdkbox import phunwaremessaging

Configure your app for push notifications (iOS)

  1. Go to Apple developer portal and create a push notification certificate. (See Push notification tutorial for detailed instructions)

  2. Once it's created, download the push production certificate and add it to Keychain Access. Then, from Keychain Access, export both the certificate and key. (Right click to view the Export option) as a .p12 and set a password.

  3. Now, log on to the Maas Portal, navigate to the app created for your application and update the following.

    • Certificate (.p12): Click the grey ellipses button to upload the Production Push Certificate you created on developer.apple.com.
    • Password: The password you setup for the push certificate.
    • Environment: Use Sandbox for debug builds. Use Production environment for production apps and Production Ad-Hoc build.

Android Configuration

  1. Phunware messaging currently only supports Android-Studio
  2. Create a new Android application in MAAS-portal
  3. In strings.xml (under Sample/src/main/res/values), replace the appId, accessKey and signatureKey with values for this application in MAAS portal.
  4. Set up Google Cloud Messaging
  5. Create a project on Firebase console
  6. Choose 'Add Firebase to Android app'
  7. In the Firebase console, the package name should be the same as application id in build.grade (under Sample directory)
  8. In the MAAS portal, for the newly created Android app, replace the API Key and sender id with the values for ServerKey and SenderId on the Firebase console (under CloudMessaging section)
  9. The Firebase console creates a google-services.json file and downloads it to your default Downloads folder.
  10. Replace the default google-service.json file (under Sample directory) the sample app with the dowloaded google-service.json from Firebase console
  11. Add the google-services gradle plugin to you applications gradle file apply plugin: 'com.google.gms.google-services'

Configure your app for push notifications (Android)

NOTE: PhunwareMessaing don't support Eclipse/Ant project

  1. Set up GCM at https://developers.google.com/cloud-messaging/android/client

  2. Create a project on Firebase console

    • Choose 'Add Firebase to Android app'
    • In the Firebase console, the package name should be the same as application id in build.grade
    • The Firebase console creates a google-services.json file and downloads it to your default Downloads folder.
    • Put the google-services.json file to proj.android-studio/app/ folder

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:


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

Here is an example of the PhunwareMessaging configuration.

    "ios": {
    "android": {


Register Javascript Functions

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

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

#include "PluginPhunwareMessagingJS.hpp"
#include "PluginPhunwareMessagingJSHelper.h"

Initialize PhunwareMessaging

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


Read message


Remove message


Get all messages


Catch PhunwareMessaging events (optional)

This allows you to catch the PhunwareMessaging events so that you can perform operations such as providing player rewards for viewing ads.

    init : function(success, message) {},
    error : function(message) {},

API Reference



initialize the plugin instance.


Set listener to listen for phunwaremessaging events



init(success, message);

Notifies the delegate that the module has finished loading


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 PhunwareAds bundle into your Xcode project

check Copy items if needed when adding frameworks:





The above frameworks depend upon other frameworks. You also need to add the following system frameworks

if you don't already have them:









Copy all source and header files from plugin/jsbindings/ 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.

NOTE: not support eclipse project right now

Copy Files

Copy the following jar files 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.

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" />

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" />

Edit Android.mk

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

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:


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, ./pluginphunwaremessaging)

This means that your ordering should look similar to this:

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

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-16

Edit AndroidManifest.xml

Edit manifest. Example:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:ns1="http://schemas.android.com/tools" <!-- ADD THIS LINE -->
          android:installLocation="auto" android:versionCode="1"

Edit application. Example:

<application android:icon="@drawable/icon"
             ns1:replace="android:label" <!-- ADD THIS LINE -->
             android:label="@string/app_name" >

    <!-- ADD START-->
    <activity android:name=".AppActivity">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="locationmessaging/message" />
    <!-- ADD END-->


Edit build.gradle

Edit cocos2d/cocos/platform/android/libcocos2dx/build.gradle. Example:

android {
    compileSdkVersion 23                    # THIS LINE
    buildToolsVersion "23.0.3"              # THIS LINE
    useLibrary  'org.apache.http.legacy'    # THIS LINE

    defaultConfig {
        minSdkVersion 16                    # THIS LINE
        targetSdkVersion 22                 # THIS LINE
        versionCode 1
        versionName "1.0"


Edit proj.android-studio/app/build.gradle

android {
+    compileSdkVersion 23
+    buildToolsVersion "23.0.3"
+    useLibrary  'org.apache.http.legacy'

     defaultConfig {
         applicationId "org.cocos2dx.cpp3141"   <!-- MUST SAME WITH google-services.json -->
+        minSdkVersion 16
         targetSdkVersion 22
         versionCode 1
         versionName "1.0"


     buildTypes {
+        debug {
+            ndk {
+                abiFilters = ["armeabi"]
+            }
+        }
         release {
+            ndk {
+                abiFilters = ["armeabi"]
+            }
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
             if (project.hasProperty("RELEASE_STORE_FILE")) {


 dependencies {
+    compile 'com.google.android.gms:play-services-maps:9.6.1'
+    compile 'com.android.support:appcompat-v7:23.3.0'
+    compile 'com.phunware.messaging:messaging:3.0.4'
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile project(':libcocos2dx')

 clean.dependsOn cleanAssets
 preBuild.dependsOn copyAssets
+apply plugin: 'com.google.gms.google-services'

Edit proj.android-studio/build.gradle

         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
+        classpath 'com.google.gms:google-services:3.0.0'

 allprojects {
     repositories {
+        maven {
+            url "https://nexus.phunware.com/content/groups/public/"
+        }

Copy all source and header files from plugin/jsbindings/ 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 \

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:

import android.content.Intent;
import com.sdkbox.plugin.SDKBox;
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if(!SDKBox.onActivityResult(requestCode, resultCode, data)) {
            super.onActivityResult(requestCode, resultCode, data);
    protected void onStart() {
    protected void onStop() {
    protected void onResume() {
    protected void onPause() {
    public void onBackPressed() {
          if(!SDKBox.onBackPressed()) {

Proguard (optional)

# phunwaremessaging
-keep class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
-dontwarn okio.**
-dontwarn okhttp3.**

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

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


SDKBox PhunwareMessaging v3.5.1+ android Required:

  1. Build SDK Version - 23
  2. Compile SDK Version - 23

if you get miss HttpClient error when set build sdk to 23:

  1. if use android studio, add this to your gradle:
android {
    useLibrary 'org.apache.http.legacy'