Cocos2d-x SDK integration guide

The Adjust Android SDK enables you to record attribution, events, and more in your Cocos2d-x app. Follow the steps in this guide to set up your app to work with the Adjust SDK.

1. Get the Adjust SDK

To use the Adjust SDK in your Cocos2d-x app, you need to add it to your project. You can download the latest version from the GitHub releases page. Extract the archive into a directory of your choosing.

2. Add the SDK to your project

To add the SDK to your project:

  1. Extract the Adjust SDK archive

  2. Copy the C++ files from the dist directory and add them to your Cocos2d-x project

  3. (Android only): add the paths of the C++ files to the LOCAL_SRC_FILES section of your file.
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustConfig2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustAttribution2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustProxy2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustEvent2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/Adjust2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustEventFailure2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustEventSuccess2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustSessionFailure2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustSessionSuccess2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustAppStoreSubscription2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustPlayStoreSubscription2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustThirdPartySharing2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustAppStorePurchase2dx.cpp \
    $(LOCAL_PATH)/../../../Classes/Adjust/AdjustPlayStorePurchase2dx.cpp \

3. Update your project settings

To enable the Adjust SDK to work in your project, you need to update your project settings. Follow the instructions in this section to

Android settings

SDK JAR library

The Java Archive (JAR) library is required for Cocos2d-x apps that target Android. To integrate the JAR library into your app, copy the adjust-android.jar library from your extracted archive to your project’s libs folder.

Add permissions

To give the Adjust SDK access to device information, you need to declare which permissions your app requires. To do this, add permissions to your AndroidManifest.xml file.

Add the following permissions to get access to online features:

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

If your app doesn’t target the Google Play Store, add the following permission to access the device’s network state:

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

The Adjust SDK includes the permission by default. If you need to make your app Children’s Online Privacy Protection Act (COPPA) compliant or if your app doesn’t target the Google Play Store, you must remove this permission using a remove directive.

<uses-permission android:name="" tools:node="remove"/>

Set up Proguard

If you’re using Proguard to optimize your app, you must add rules to prevent Proguard from removing classes.
-keep class com.adjust.sdk.** { *; }
-keep class {
-keep class {$Info getAdvertisingIdInfo(android.content.Context);
-keep class$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
-keep public class** { *; }

If you’re not publishing your app in the Google Play Store, add the following rule:
-keep public class com.adjust.sdk.** { *; }

Set up install referrer

An install referrer is a unique identifier used to attribute an install to a source. The Adjust SDK requires this information to perform attribution. Use one of the following methods to retrieve the install referrer information:

Google Play Referrer API

The Google Play Referrer API is available to apps that target the Google Play Store.

To support the Google Play Referrer API, add the following to your build.gradle file:

dependencies {
implementation ''

If you’re using Proguard, remember to add a rule to prevent the dependency from being removed.
-keep public class** { *; }
Huawei Referrer API

The Huawei Referrer API is available to apps that target Huawei devices. The Adjust SDK can record installs on Huawei devices using Huawei App Gallery v10.4 and later. You don’t need to make any changes to support this API.

Meta install referrer

The Adjust SDK supports the Meta Install Referrer in v4.37.0 and above. To enable this feature:

  1. Find your Meta app ID in your App Dashboard. See Meta’s App Dashboard documentation for more information.

  2. Add the Meta apps to your AndroidManifest.xml file.

    <package android:name="com.facebook.katana" />
    <package android:name="" />
  3. Pass your App ID as a string argument to the AdjustConfig2dx.setFbAppId method.

    AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment, false);

iOS settings

The Adjust SDK is able to get extra information when you include certain iOS frameworks in your app. These frameworks enable certain SDK features, but they’re not mandatory for the SDK to work normally. You can add the frameworks and then mark them as optional in Project Settings —> Build Phases —> Link Binary With Libraries.

Add linker flags

To support categories from AdjustSdk.framework, you need to add a linker flag. To do this:

  1. Navigate to Project Settings —> Build Settings
  2. Select Other Linker Flags.
  3. Add the -ObjC flag.

Copy additional source files

To complete iOS setup, you must copy all Objective-C++ (.h and .mm) files to your Xcode project alongside the Cocos2d-x C++ files. Ensure that all .mm files are listed in the Build Phases —> Compile Sources section.

4. Integrate the Adjust SDK

Once you’ve updated your project settings, you can integrate the Adjust SDK into your app. To do this:

  1. Find your application delegate file in the Project Navigator and open it.
  2. Include the Adjust/Adjust2dx.h class at the top of the file.
  3. Instantiate an AdjustConfig2dx object inside the applicationDidFinishLaunching method with the following arguments:
    • appToken: Your Adjust app token
    • environment: AdjustEnvironmentSandbox2dx
  4. Optionally adjust your logging level to adjust the verbosity of your logging.
  5. Call the Adjust2dx::start method and pass your AdjustConfig2dx instance as an argument.
#include "Adjust/Adjust2dx.h"
bool AppDelegate::applicationDidFinishLaunching() {
std::string appToken = "{YourAppToken}";
std::string environment = AdjustEnvironmentSandbox2dx;
AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment);

5. Configure session sending (Android only)

To ensure the Adjust SDK can send session information on Android devices, you must call certain Adjust methods when your app is sent to the background or brought to the foreground. To configure this:

  1. Find your application delegate file in the Project Navigator and open it.

  2. Add a call to the onResume method in the applicationWillEnterForeground method.

  3. Add a call to the onPause method in the applicationDidEnterBackground method.

    #include "Adjust/Adjust2dx.h"
    void AppDelegate::applicationDidEnterBackground() {
    void AppDelegate::applicationWillEnterForeground() {

6. Build your app

Well done! You should now be able to build and run your Cocos2d-x app. Enable logging to check for any issues. Check your logs to see the Install tracked message.

You are ready to start attributing your users with the Adjust SDK.