Integration Steps for Cocos2d-x Android using C++


Integrate Chocolate Platform SDK into your Cocos2dx project using C++


Chocolate Platform SDK Cocos2dx plugin supports the following ad units:

• Full Screen Interstitial

• Rewarded Video


Integration Steps

The easiest way is by cloning our working sample:


Step 1:

git clone

cocos2dx-cpp-android-sample/  is the Android Studio project folder that was created/exported using the Cocos2dx tools.  We are assuming you are familiar with Cocos2dx environment and C++.


Briefly examine the following github folder and return to this documentation page:


VdopiaAdNativeAPI.h – Notice our bridge header that declares our interstitial and rewarded methods.

We place a copy of VdopiaAdNative.h to your local cocos2dx-cpp-android-sample/Classes  folder.


Briefly examine the following github folder and return to this documentation page:

Based on your requirements, you only need to use ONE of the following:

VdopiaJNI_Interstitial_Reward.cpp – Implementation of BOTH interstitial and rewarded ads.

• VdopiaJNI_Interstitial.cpp – Implementation of ONLY interstitial ads.

• VdopiaJNI_Rewarded.cpp – Implementation of ONLY rewarded ads.

We placed a copy of these files to cocos2dx-cpp-android-sample/  folder.

We EDIT cocos2dx-cpp-android-sample/ and include the cpp file you need:

LOCAL_SRC_FILES := hellocpp/main.cpp \
../../../Classes/AppDelegate.cpp \


Step 2:

Open this folder:

HelloWorldScene.cpp – simple screen that shows how to initialize Chocolate ads and show them, including how to prefetch.  We will edit

HelloWorldScene.h and HelloWorldScene.cpp.

The following link explains what callbacks to declare and implement in HelloWorldScene.h/.cpp


Show Interstitial Ads

Please refer to HelloWorldScene.cpp:

loadInterstitialAd("API KEY");

When interstitial ad is ready or failed:

void HelloWorld::interstitialAdLoaded() {
  this->setButtonVisible(true, ShowInterestialAdButtonTag);
  this->setButtonVisible(false, LoadInterestialAdButtonTag);

void HelloWorld::interstitialAdFailed() {
  this->setButtonVisible(false, ShowInterestialAdButtonTag);
  this->setButtonVisible(true, LoadInterestialAdButtonTag);

To show the interstitial ad that is now ready:



 Show Rewarded Ads
loadRewardedAd("API KEY");

When rewarded ad is ready or failed:

void HelloWorld::rewardedAdLoaded() {
  this->setButtonVisible(true, ShowRewardedAdButtonTag);
  this->setButtonVisible(false, LoadRewardedAdButtonTag);

void HelloWorld::rewardedAdFailed() {
  this->setButtonVisible(false, ShowRewardedAdButtonTag);
  this->setButtonVisible(true, LoadRewardedAdButtonTag);

To show the rewarded ad that is now ready:


You can prefetch interstitial and/or rewarded ads very easily:


prefetchInterstitialAd("API KEY");

prefetchRewardedAd("API KEY");

A recommended place to prefetch is right after you make the call to show an ad:

//prefetch next ad, while user watching ad.  Your next load will fetch quickly, if prefetch is successful.
prefetchRewardedAd("API KEY");


Step 3:

Please make sure your Android Studio is setup with NDK, which allows Android Studio to build C/C++ and integrate those functionalities into the Android project.  As you know, Android applications are fundamentally written in Java or Kotlin.

Now, look at build.gradle and AndroidManifest.xml

build.gradle is the Android equivalent to the makefile in C++.  Just much easier and more powerful than makefile.

AndroidManifest.xml is the application manifest which contains definitions, declarations, and permissions.

These files are already setup per the steps outlined in our Android project setup document:


There is a small section where it talks about including our Cocos2dx plugin.


That’s it.  You can build and run the new Android app to a physical device.   If you run on emulator, make sure the backed cpu is armeabi-7a.


How to turn on ads on your ad unit

Please send us your sample app with the integrated code. We will help you validate the SDK setup and turn on the demand.

You can contact us via email: