Developers Manual > Cocos2d-x > Advanced Features > Third Party SDK Integration > Plugin-X > Plugin-X Integration Guide for Android

(!) Plugin-X is obsoleted.

(/) Please check out SDKBOX for helps with your service SDK integration.

Plugin-X Integration Guide for Android


Environment Requirement

  1. python 2.7.
  2. Apache Ant build tool.
  3. If your OS is Windows, you should have Cygwin environment.

Compiling the Plugin-X Project

  1. Run the script which is in the path plugin-x/tools/ This script has been well tested on both Mac OSX Mountain Lion v10.8.2 and Cygwin on Windows 7. At this script’s first run, it will ask you to input some parameters for setting up environment, like this

On Windows, the path you input should be Linux style. For example : You can input C:/adt-bundle-windows/sdk, but not C:\adt-bundle-windows\sdk

  1. After the compilation finishes, a directory named publish will be generated in the root directory of the plugin-x projet. If your publish directory looks like this, it means that your compilation is successful.

  1. The files in publish directory involves:
  2. plugin header files (**.h)
  3. C++ static libs
  4. java libs
  5. makefiles for android
  6. android projects needed by some plugins

Modify the game project before using plugin

What we need to do?

Plugin-x wrapper C/C++ interfaces for the third party android SDKs. So we should modify the game project configuration to use it:

  • Modify the .mk files( & to link the static libs built by plugin-x.
  • Modify the android project configuration to link the libs built by plugin-x & third party SDK libs. (.jar files)
  • Modify the AndroidManifest.xml, add the declaration of activities, and user permissions for game.
  • For some particular plugins, we need to add external configuration and resource files.

Game developer guide tool

Now we have a script named which is in the path plugin-x/tools/
It will help you modify your game project.

  1. Run the script in terminal (On Windows, you should run it in Cygwin). The UI will be shown like this:

Input android project path of your game into the edit-box. Please keep the path have no spaces. Then click ‘Next’ button.

  1. Select the plugins you needed. The UI looks like:

After select plugins, click ‘Finish’ button. The script will modify some configuration files of your android project.
The follow configuration files will be modified:

  • ————— Add C++ libs dependence for game
  • ———— Add parameter for ndk build
  • .project —————— Link the publish directory to the game project as extern resource
  • .classpath ————— Add java libs dependence for game
  • AndroidManifest.xml —— Add activity declaration & user permission needed by plugins for game

Manual modified

  1. Modify the ndk-build command parameter : add the publish directory into parameter NDK_MODULE_PATH , such as : NDK_MODULE_PATH=${PLUGIN_ROOT}/publish
  2. Add code into the method JNI_OnLoad, like this :
#include “PluginJniHelper.h”
jint JNI_OnLoad
 PluginJniHelper::setJavaVM; // for plugins
 return JNI_VERSION_1_4;
  1. Invoke method PluginWrapper.init() when the main activity of the game is created :
import org.cocos2dx.plugin.PluginWrapper;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
public class HelloIAP extends Cocos2dxActivity{
 protected void onCreate{
 PluginWrapper.init(); // for plugins
 // If you want your callback function can be invoked in GL thread, add this line:
 static {
  1. Particular modifications for special plugin If your game use the following plugins, you need some particular modifications. We have plan to add these modifications into the developer guide tool.
  • For nd91
    Import the android project 91SDK_LibProject_complete into eclipse. The path of this project is plugin-x/publish/nd91/andriod/DependProject.
    Make your game project depend on the project 91SDK_LibProject_complete, like this:

Using plugin-x in your C++ code

load and unload plugin

All plugins are managed by class PluginManager . You can load/unload one plugin by it’s class name , sample code :

    // load plugin AnalyticsFlurry
    s_pFlurry = dynamic_cast

    // unload plugin AnalyticsFlurry
    s_pFlurry = NULL;

Suggestion : Load the plugin when the game begin, and unload it when the game end.

using plugin

You can directly invoke the methods declared in protocols. Sample code:

    // enable the debug mode

    // log an event

    // log an event with params
    LogEventParamMap paramMap;
    paramMap.insert(LogEventParamPair("type", "popular"));
    paramMap.insert(LogEventParamPair("artist", "JJLin"));
    s_pFlurry->logEvent("music", ¶mMap);

Some plugins have custom methods. We implement a simple reflection in plugin-x.
You can invoke the custom methods by name. Like this:

    // invoke setAge() method in plugin Flurry
    PluginParam pParam3(20);
    s_pFlurry->callFuncWithParam("setAge", &pParam3, NULL);

    // invoke logTimedEventBeginWithParams() method in plugin Flurry
    PluginParam event3("music-kv");
    LogEventParamMap paramMap;
    paramMap.insert(LogEventParamPair("type", "popular"));
    paramMap.insert(LogEventParamPair("artist", "JJLin"));
    PluginParam mapValue(paramMap);
    s_pFlurry->callFuncWithParam("logTimedEventBeginWithParams", &event3, &mapValue, NULL);

Also, there are some interfaces defined for reflection to return basic-type values. Methods List:

    // return string value for developers
    const char* callStringFuncWithParam(const char* funcName, PluginParam* param, ...);

    // return int value for developers
    int callIntFuncWithParam(const char* funcName, PluginParam* param, ...);

    // return bool value for developers
    bool callBoolFuncWithParam(const char* funcName, PluginParam* param, ...);

    // return float value for developers
    float callFloatFuncWithParam(const char* funcName, PluginParam* param, ...);


  • You can pass parameters to methods, the parameters must be pointer of PluginParam.
  • The parameters must be passed in the plugin required order.
  • If the method can’t be found in plugin, nothing will happen.


  1. The screenshots and sample codes come from plugin-x’s sample project HelloIAP
  2. If you have any question, please don’t hesitate to add comments on this wiki page, or create issues on project.

plugin-x-guide-UI.jpg (23 kB), 2013-03-06 06:42

plugin-x-guide-UI2.jpg (17 kB), 2013-03-06 06:42

plugin-x-nd91-depend.jpg (125.5 kB), 2013-03-06 06:42

plugin-x-setting-environment.jpg (95.8 kB), 2013-03-08 01:29

plugin-x-publish-folder.jpg (12.5 kB), 2013-04-27 07:25

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.