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:
-
Extract the Adjust SDK archive
-
Copy the C++ files from the
dist
directory and add them to your Cocos2d-x project -
(Android only): add the paths of the C++ files to the
LOCAL_SRC_FILES
section of yourAndroid.mk
file.
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:
If your app doesn’t target the Google Play Store, add the following permission to access the device’s network state:
The Adjust SDK includes the com.google.android.gms.AD_ID
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.
Set up Proguard
If you’re using Proguard to optimize your app, you must add rules to prevent Proguard from removing classes.
If you’re not publishing your app in the Google Play Store, add the following rule:
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:
If you’re using Proguard, remember to add a rule to prevent the dependency from being removed.
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:
-
Find your Meta app ID in your App Dashboard. See Meta’s App Dashboard documentation for more information.
-
Pass your App ID as a string argument to the
AdjustConfig2dx.setFbAppId
method.
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.
Framework | Description | Notes |
---|---|---|
AdSupport.framework | Enables access to the device’s IDFA. Also enables access to LAT information on devices running iOS 14 or earlier | Don’t add this framework if your app targets the “Kids” category |
AdServices.framework | Handles Apple Search Ads attribution | |
StoreKit.framework | Enables access to the SKAdNetwork framework | Required to allow the Adjust SDK to handle communication with SKAdNetwork on devices running iOS 14 or later |
AppTrackingTransparency.framework | Required to allow the Adjust SDK to wrap user tracking consent dialog and access consent responses on devices running iOS 14 or later | Don’t add this framework if your app targets the “Kids” category |
Add linker flags
To support categories from AdjustSdk.framework
, you need to add a linker flag. To do this:
- Navigate to Project Settings —> Build Settings
- Select Other Linker Flags.
- 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:
- Find your application delegate file in the Project Navigator and open it.
- Include the
Adjust/Adjust2dx.h
class at the top of the file. - Instantiate an
AdjustConfig2dx
object inside theapplicationDidFinishLaunching
method with the following arguments:appToken
: Your Adjust app tokenenvironment
:AdjustEnvironmentSandbox2dx
- Optionally adjust your logging level to adjust the verbosity of your logging.
- Call the
Adjust2dx::start
method and pass yourAdjustConfig2dx
instance as an argument.
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:
-
Find your application delegate file in the Project Navigator and open it.
-
Add a call to the
onResume
method in theapplicationWillEnterForeground
method. -
Add a call to the
onPause
method in theapplicationDidEnterBackground
method.
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.