Update time: 2021/09/25 21:50:29
The CommsEase dynamic library stores libs directory of specific platforms. The nim directory contains the interface header files that CommsEase SDK provides. CommsEase SDK provides C and C++ interface files. C interface files are stored in the nim/c directory, and C++ interface files are in the nim/cpp directory. We recommend using C++ interface in developing cocos-2dx games for its higher efficiency. Based on the functional modules, store interfaces in specific directories:
The nim directory stores interface files related to Instant Messages. The nim_audio directory stores interfaces files related to audio features. The nim_audio directory stores interface files related to the chat room.
Quick access to SDK
Download and import the SDK
Download the CommsEase cocos-2dx SDK package. Currently, developers can only use C and C++ to access the cocos-2dx SDK.
Create a Cocos2d-x project
Use the cocos command to create the project
cocos new -p <package name\> -l cpp <project name\>and the directory, such as
cocos new -p org.cocos2dx.nim_cocos2d -l cpp nim_cocos2d.
Import the SDK
Decompress the CommsEase SDK package and copy it to the created cocos project.
Open proj.android-studio directory of the created cocos project by using Android Studio.
Import the jar package
nim_sdk.jar and nim_audio.jar are under the directory of libs and Android of the SDK directory. nim_sdk.jar is required for the CommsEase SDK. Therefore, ensure to import the jar to the cocos project. nim_audio.jar is required when enabling the audio feature.
CommsEase SDK requires the following permissions:
<!-- Enable internet for app!!!. --> <uses-permission android:name="android.permission.INTERNET" /> <!-- Getting the state of internet for app!!!. --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- write or read user data file for app!!!. --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_LOGS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
Make sure that these permissions have been configured in AndroidManifest.xml.
Compile the link
Update Android.mk contained in the Android Studio project directory and import CommsEase SDK to the project. Assume that the SDK directory is nim_cocos2d-x_sdk.
Add the pre-compiled dynamic library:
#import nim c library include $(CLEAR_VARS) include $(MY_ROOT_PATH)/nim_cocos2d-x_sdk/libs/Android/Android.mk
Compile CommsEase SDK C++ code:
# _NIM_CPP_LIBRARY_BEGIN include $(CLEAR_VARS) include $(MY_ROOT_PATH)/nim_cocos2d-x_sdk/nim/cpp/third_party/jsoncpp/Android.mk include $(CLEAR_VARS) include $(MY_ROOT_PATH)/nim_cocos2d-x_sdk/nim/cpp/nim/Android.mk include $(CLEAR_VARS) include $(MY_ROOT_PATH)/nim_cocos2d-x_sdk/nim/cpp/nim_chatroom/Android.mk include $(CLEAR_VARS) include $(MY_ROOT_PATH)/nim_cocos2d-x_sdk/nim/cpp/nim_audio/Android.mk # _NIM_CPP_LIBRARY_END
LOCAL_STATIC_LIBRARIES += jsoncpp LOCAL_SHARED_LIBRARIES += nim LOCAL_SHARED_LIBRARIES += nim_chatroom LOCAL_SHARED_LIBRARIES += nim_audio LOCAL_SHARED_LIBRARIES += fjni_wrapper LOCAL_STATIC_LIBRARIES += nim_cpp nim_chatroom_cpp nim_audio_cpp
The above codes contain such modules as instant messaging, chat room, and audio. Users can remove unnecessary SDK features as needed. During the development process, you need to include
LOCAL_C_INCLUDESto add the correct header file path.
Proguard obfuscation configuration
Do not obfuscate CommsEase IM SDK. If the code obfuscation is configured in a project, add the following configuration to the proguard-rules.pro of the Proguard obfuscation file:
Initialization before calling the SDK:
Before using the CommsEase IM SDK to modify an AppActivity.java file, call the NIMSDK.init initialization interface contained in the nim_sdk.jar package to implement initialization. For details, see the following description.
Import CommsEase SDK C++ project
Add the project files of each functional module contained in the nim\cpp directory of the cocos project, and add references to these projects to the cocos main project.
Configure the correct include directory of the header file
When running the app, copy dll files in the SDK directory libs\Windows\x86 to the execution directory of the program. You can copy according to specific feature modules as needed.
SDK only supports Xcode 7.x. And versions of iOS 7.0 and later are supported.
- After decompressing the package, copy the directory nim_cocos2d-x_sdk to the corresponding Cocos2d-x project directory, find ~/nim_cocos2d-x_sdk/libs/iOS and copy it into the FrameWorks of the project. At the same time, add the system library: libz.tbd (or libz.dylib) and find the required Xcode project under each subfolder (nim, nim_audio, nim_chatroom) of ~/nim_cocos2d_sdk/nim/cpp, and copy them into Cocos Workspace. If you do not need features related to audio and chat room, do not add into the specific project.
Link the cocos project with the corresponding library.
- Set the corresponding Header Search Paths, as shown in the figure:
- Set the corresponding Library Search Paths, as shown in the figure:
The integration is completed when the compilation is successful.
- SDK components
- Quick access to SDK