This topic describes how to use Android Studio to integrate an Android SDK.
Prerequisites
- You can obtain an SDK and AccessKey pair for Android from the GameShield console.
For more information, see Obtain an SDK package and AccessKey pair.
- You can obtain the following information from the GameShield console.
- GroupName: indicates a node group ID. Log on to the GameShield console, open the game
management page, and view the target node group ID on the Basic Settings tab.

- Protection Target ID. Log on to the GameShield console, open the Games page, and view
a protection target ID on the Protection Target Settings tab.

Background information
Key methods include initEx and getProxyTcpDomain. For more information, see Introduction to core methods.
You can contact GameShield Technical Support to obtain demo applications.
Procedure
- Open Android Studio.
- Create a project and use the default settings to complete creation. Name the project
yxd_sdk_test.
The following figure shows the structure of the new project directory.
Note Before proceeding to subsequent operations, you must make sure that the new project
is working as expected.

- Add dependencies
- Copy the yunceng.jar file from the Android SDK to the libs directory. You can drag and drop the file to the libs directory.

- Open Android Studio, choose , click app, and click the Dependencies tab.

- Click the plus sign (+), select jardependency, and specify yunceng.jar.

- Click OK to complete the configuration.
- Add the .so file. Under the directory, create a subdirectory named jniLibs, and copy the libyunceng.so file to the jniLibs directory.

- Configure access permissions. Open the AndroidManifest.xml file, and add the following statement to the file as shown in the following figure.
<uses-permission android:name="android.permission.INTERNET" />

- Add the following code to obtain the IP address of a protection target. The following
shows the sample code.
// Initialize the SDK. One successful initialization for the SDK is required.
int len = 0;
ret = YunCeng.initEx(getResources().getString(R.string.appkey), "token");if (0 ! = ret) {
msg_show.setText("sdk init failed " + Integer.toString(ret));
return;
}msg_show.setText("sdk init success ");
return;
// Use core methods to obtain the IP address of a protection target
ret = YunCeng.getProxyTcpByDomain("Player ID","GroupName", "Protection target ID","Port number of the origin server", ip, port);
if (0 == ret) {
msg_show.setText("get next ip success: " + Integer.toString(ret) + "\nip : " + ip + "port :
" + port);
} else {
msg_show.setText("get next ip failed. : " + Integer.toString(ret));
}
- Optional: Configure ProGuard. If you use ProGuard to perform obfuscation, you must add the following
statement to the ProGuard configuration file.
-keep class com.aliyun.security.yunceng. ** {*;}