Getting Started
You're 3 steps away from adding great in-app support to your Cocos2dx Game.
Requirements
- Xcode 12.0 and above.
- Supported iOS versions - iOS 13 and above
- Supported Android versions - API level 24 and above i.e Android OS 7 Nougat and above.
- Cocos2dx 3.x and above
- Update (August 2023): SDK X 10.2.x is functional only above API Level 24 i.e Android OS 7 Nougat and above.
- SDK 10.3.0 functions and is supported on Android 7 and above (API level 24 and above). You can still compile your app using a minimum API level of 16, but the support starts for API level 24 and above. For details regarding Helpshift SDK's Android OS support policy, please refer to this article.
Step 1 - Download the Cocos2d-x plugin for Helpshift
The Helpshift SDK X Cocos package contains the following files:
android/Classes | Plugin files specific to android platform |
android/proj.android | Android build support files |
android/proj.android-studio | Android SDK X Package |
android/src/com/helpshift | Android Proxy classes |
ios/Classes | Plugin files specific to iOS platform |
iOS/sdk | iOS SDK X Framework |
Step 2 - Add Helpshift Plugin to your Cocos2dx project
- Android
- iOS
Copy the
android/src/com/helpshift
folder to thesrc/com/
folder of Android project of your Cococs2dx game.Copy the contents of the
android/Classes
folder to theClasses
folder of your Cocos2dx game.
Add Helpshift dependencies in your project
If you are on SDK X or migrating to SDK X please note the following requirements:
- SDK X is functional only above API Level 24 i.e Android OS 7 Nougat and above.
- The
minSDKVersion
in code is kept as API Level 16 to allow importing the SDK and compiling in apps that allow installation till API Level 16 i.e Android 4.4 Jelly Bean. - If your app is installed on a device below API level 24 (i.e below Android OS 7 Nougat) then you can choose to have a different medium for providing support. For example, Email, Web etc. We throw an
UnsupportedOSVersionException
if the SDK is initialized below API Level 24. Please catch and use this exception according to your needs. Refer: Initializing the SDK.
Copy the
Helpshift.aar
file from theandroid/proj.android-studio/libs
present inside plugin folder to thelibs
directory of your android project.Add dependency to Helpshift SDK in your
app/build.gradle
file.
- 10.3.X
- Below 10.2.0
repositories {
//your other repositories
flatDir { dirs 'libs' }
}
dependencies {
// your other dependencies
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation(name: 'Helpshift', ext:'aar')
}
repositories {
//your other repositories
flatDir { dirs 'libs' }
}
dependencies {
// your other dependencies
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation(name: 'Helpshift', ext:'aar')
}
- Link Helpshift files in your project as source depending on your build system.
- Using CMake
- Using ndk-build
# Add Helpshift files to CMakeLists.txt, under the Android dependency
if(ANDROID)
list(APPEND GAME_SOURCE
<other dependency files>
Classes/HelpshiftCocos2dx.cpp
Classes/HelpshiftUtil.cpp
Classes/HelpshiftLog.cpp
)
list(APPEND GAME_HEADER
<other dependency files>
Classes/HelpshiftCocos2dx.h
Classes/HelpshiftUtil.h
Classes/HelpshiftLog.h
Classes/HelpshiftEvent.h
)
endif()
# Add Helpshift files to makefile (Android.mk), under the LOCAL_SRC_FILES rule
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../../Classes/HelpshiftCocos2dx.cpp \
../../../Classes/HelpshiftUtil.cpp \
../../../Classes/HelpshiftLog.cpp \
- Unzip the package and add the contents of the
ios/Classes
folder into your Xcode project. - From
ios/sdk
folder, drag & dropHelpshift.xcframework
into the "Frameworks, Libraries and Embedded content" in the General section of your Xcode project. - If your game does not contain any swift code, set
Always Embed Swift Standard Libaries
underBuild Settings
to YES. - In the Build Settings of your Xcode project, add
-fmodules
and-fcxx-modules
flags under theOther C Flags
section in both Debug and Release. Be careful while adding these flags in Debug and Release, because if you override the default flags you might face build errors. TheOther C Flags
section would look this after adding mentioned flags: - In the Build Settings of your Xcode project, add
-fmodules
and-fcxx-modules
flags under theOther C++ Flags
section in both Debug and Release. Be careful while adding these flags in Debug and Release, because if you override the default flags you might face build errors.
Add NSPhotoLibraryUsageDescription
key in your application's info.plist file
If your game does not use this permission, you would need to add this key as well as description for the same. Not adding this key-description pair might cause game rejection.
NSPhotoLibraryUsageDescription Description text: "We need to access photos library to allow users manually pick images meant to be sent as attachment for help and support reasons."
Step 3 - Initialize Helpshift in your game
First, create a game on the Helpshift Dashboard
Create a game with Android and iOS as a selected
Platform
Helpshift uniquely identifies each registered game with a combination of 2 tokens:
Platform ID | Your Games's unique App Id (Games's App Id on dashboard is your platform Id) |
Domain Name | Your Helpshift domain. E.g. happyapps.helpshift.com |
To obtain these values:
- Go to your Helpshift dashboard
- Navigate to
Settings
>SDKs (for Developers)
- Select your Game and from the dropdowns
- Copy the two tokens present in the "Android" table
- Android
- iOS
Initialize Helpshift by importing com.helpshift.HelpshiftCocosBridge
and
calling the HelpshiftCocosBridge.install
in the onCreate
of your Cocos2dxActivity
:
import com.helpshift.HelpshiftCocosBridge;
public class MyActivity extends Cocos2dxActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Add install configs in the config map
Map<String, Object> config = new HashMap<>();
//...
// Install call
HelpshiftCocosBridge.install(
this,
"<App Id from the Helpshift Dashboard>",
"<Domain name from the Helpshift Dashboard>",
config);
}
}
Initialize Helpshift by including HelpshiftCocos2dx.h
and
calling HelpshiftCocos2dx::install
in the AppDelegate::applicationDidFinishLaunching()
function of your AppDelegate.cpp
:
#include "HelpshiftCocos2dx.h"
...
bool AppDelegate::applicationDidFinishLaunching() {
cocos2d::ValueMap config;
// Add install configs in the config map
HelpshiftCocos2dx::install( "<App Id from the Helpshift Dashboard>",
"<Domain name from the Helpshift Dashboard>",
config);
...
}
Initializing Helpshift in your game for China
A special install config key, isForChina
, should be used for integrating Helphift SDK for China region.
This config key accepts a boolean value. Pass true
if you are integrating the SDK in an game for China region. The value defaults to false
if left unspecified.
- Android
- iOS
import com.helpshift.HelpshiftCocosBridge;
public class MyActivity extends Cocos2dxActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Map<String, Object> config = new HashMap<>();
config.put("isForChina", true);
// Install call
HelpshiftCocosBridge.install(
this,
"<App Id from the Helpshift Dashboard>",
"<Domain name from the Helpshift Dashboard>",
config);
}
}
Placing the install call
Use HelpshiftCocosBridge.install(...); with the required arguments immediately after the super.onCreate() of your Cocos2dx Activity. Placing it elsewhere might cause unexpected runtime problems.
HelpshiftInitializationException
Calling any API before the install call would throw an unchecked HelpshiftInitializationException
in debug mode.
UnsupportedOSVersionException
Calling install()
below Android SDK version 24 will throw this checked exception. All the APIs will be non operable.
#include "HelpshiftCocos2dx.h"
...
bool AppDelegate::applicationDidFinishLaunching() {
ValueMap config;
config["isForChina"] = Value("yes");
HelpshiftCocos2dx::install( "<App Id from the Helpshift Dashboard>",
"<Domain name from the Helpshift Dashboard>",
config);
...
}
Placing the install call
You should not place the install call anywhere other than AppDelegate::applicationDidFinishLaunching
Placing it elsewhere might cause unexpected runtime problems.
Helpshift install call will throw InstallException
in case the validation of the SDK keys fail.