This topic describes how to add dependencies and connect to the Remote Log Service using Maven integration.
You can add dependencies for the Android software development kit (SDK) for the Remote Log Service using either Maven integration or local integration. We recommend using Maven integration because it simplifies the integration process.
To add dependencies using local integration, see Android SDK integration (local).
Prerequisites
You have created a project and an application. For more information, see Quick Start.
Limits
Supports only Android 4.2 and later.
Supports only the armeabi-v7a, arm64-v8a, x86, and x86_64 architectures.
Logs are stored on the mobile device for a maximum of 7 days.
Integration overview
Add dependencies: Use Maven integration.
Connect to the service: Add a custom Application and initialization code, configure the ABI, and set the log pull level.
Print logs: Import the header file and print log information in the code.
Configure obfuscation: If your app obfuscates code, modify the obfuscation configuration file.
Add dependencies
1. In the repositories node of your project's build.gradle file, add the Alibaba Cloud Maven repository URL.
repositories {
maven { url "http://maven.aliyun.com/nexus/content/repositories/releases" }
}
2. In the dependencies node of the project's build.gradle file, add the dependencies.
implementation 'com.aliyun.ams:alicloud-android-ha-adapter:1.2.4.0-open'
implementation 'com.aliyun.ams:alicloud-android-tlog:1.1.8.0-open'
3. In the defaultConfig node of the build.gradle file, configure the ABI as needed.
ndk {
abiFilters 'arm64-v8a' // Configuration item. Available values: armeabi-v7a, arm64-v8a, x86, x86_64
}
The Remote Log Service supports only the armeabi-v7a, arm64-v8a, x86, and x86_64 architectures.
Service access
Pre-initialize the SDK.
Pre-initialize the SDK in the `Application.onCreate` method.
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AliHaAdapter.getInstance().preStart(this);
}
}
Obtain the key information from the EMAS console.
Enable Remote Log Access.
Enable Remote Log Access after the user agrees to the privacy policy.
private void startHa() {
AliHaConfig config = new AliHaConfig();
config.appKey = "xxxxxxxx"; // Configuration item: appkey
config.appVersion = "x.xx"; // Configuration item: The version number of the application.
config.appSecret = "xxxxxxxxxxxx"; // Configuration item: appsecret
config.channel = "mqc_test"; // Configuration item: The channel ID of the application. This is a custom value.
config.userNick = null; // Configuration item: The nickname of the user.
config.application = this; // Configuration item: The application pointer.
config.context = getApplicationContext(); // Configuration item: The application context.
config.isAliyunos = false; // Configuration item: Specifies whether the OS is YunOS.
config.rsaPublicKey = "xxxxxxx"; // Configuration item: The tlog public key, which corresponds to AppRsaSecret in the console.
AliHaAdapter.getInstance().addPlugin(Plugin.tlog);
AliHaAdapter.getInstance().start(config);
TLogService.updateLogLevel(TLogLevel.XXXXXX); // Configuration item: The log level that can be pulled from the console.
}
The configuration is as follows:
Parameter |
Description |
config.appKey |
Specifies the AppKey of the app. Data type: String For more information, see Step 1 in Access Service. Required: Yes Can be empty: No Default value: None |
config.appVersion |
Sets the version number of the app. Data type: String Format: Custom Value range: Any length.
Note
This parameter value is displayed as a drop-down list option in the console. Keep the value short and concise. Required: Yes Can be empty: No Default value: None Case-sensitive: Yes. For example, `vx.x` and `Vx.x` are different versions. Character type: Uppercase and lowercase English letters, and digits.
Note
This parameter does not support Chinese characters or special characters. |
config.appSecret |
Specifies the AppSecret of the app. Data type: String For more information about obtaining access, see Step 1 in Access Service. Required: Yes Can be empty: No Default value: None |
config.channel |
Sets the channel ID. The ID is reported to the server to distinguish between channels. Data type: String Value range: Any length Required: No Can be empty: Yes Default value: None Character type: Uppercase and lowercase English letters, and digits.
Note
This parameter does not support Chinese characters or special characters. |
config.userNick |
Sets the user nickname. The nickname is reported to the server to distinguish between users. This parameter may be used for data retrieval later. Data type: String Value range: Any length Required: No Can be empty: Yes Default value: None Character type: Uppercase and lowercase English letters, and digits.
Note
This parameter does not support Chinese characters or special characters. Naming convention: Custom |
config.application |
Specifies the current application.
Important
Do not point to other applications. Data type: Object Required: Yes Can be empty: No Default value: None |
config.context |
Specifies the context object of the app. Set it to Data type: Object Required: Yes Can be empty: No Default value: None |
config.isAliyunos |
Specifies whether the app is running on YunOS. Data type: Boolean Valid values: `false` and `true` Required: No Can be empty: Yes Default value: `false` |
config.rsaPublicKey |
Specifies the public key for Remote Log Access. Data type: String For more information, see Step 1 in Access Service. Required: Yes Can be empty: No Default value: None |
TLogLevel.XXXXXX |
Globally sets the level of logs that can be pulled from the console. Data type: Enumeration Valid values:
Required: Yes Default value: `ERROR` Configuration notes:
|
Data collection.
Configure data collection settings as early as possible while ensuring compliance. By default, device information, system info, and the network type are collected.
AliHaConfig config = new AliHaConfig();
// You can disable the collection of device, system, and network information based on compliance requirements.
config.noCollectionDataType = AliHaConfig.NO_DEVICE_DATA | AliHaConfig.NO_OS_DATA | AliHaConfig.NO_NETWORK_DATA;
Data collection parameters:
Sensitive data type |
Description |
Field details |
NO_DEVICE_DATA |
Do not collect device information |
Includes: Brand (Build.BRAND), model (Build.MODEL), screen resolution, CPU information (Build.CPU_ABI), and hardware name (Build.HARDWARE) |
NO_OS_DATA |
Do not collect system info |
Includes: Language, OS version (Build.VERSION.RELEASE, Build.VERSION.SDK_INT), and unique OS build ID (Build.FINGERPRINT) |
NO_NETWORK_DATA |
No network information is collected. |
Includes: Carrier, access point information, and network type |
In
AndroidManifest.xml, add a code segment to register theApplication.
<application
android:name=".MyApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
...
</application>
Print logs
1. If your business process triggers log output, import the header file.
import com.alibaba.ha.adapter.service.tlog.TLogService;
2. Add code in the appropriate location to print log information. The following is sample code:
TLogService.logv("MODEL","TAG","MESSAGE");
TLogService.logd("MODEL","TAG","MESSAGE");
TLogService.logi("MODEL","TAG","MESSAGE");
TLogService.logw("MODEL","TAG","MESSAGE");
TLogService.loge("MODEL","TAG","MESSAGE");
Function: TLogService.<LogLevel>(<MODEL>, <TAG>, <MESSAGE>);
Description: Prints log information for a specified level.
Parameter |
Description |
LogLevel |
Specifies the log level to pull. For more information about log levels, see Basic Concepts. Data type: Enumeration Valid values:
Configuration notes: Whether the printed logs can be pulled by the console depends on the parameter settings of the |
MODEL |
Sets the feature module for the log content. This helps you filter logs by source later. Data type: String Character type: Uppercase and lowercase English letters, Chinese characters, digits, and special characters Required: Yes Case-sensitive: No Example: "Push feature module" |
TAG |
Sets keywords for the log. This helps you filter logs by tag later. Data type: String Character type: Uppercase and lowercase English letters, Chinese characters, digits, and special characters Required: Yes Case-sensitive: No Example: "The push feature module received a push message (Push.receive), The push feature module clicked a push message (Push.click)" |
MESSAGE |
The log information to print. Data type: String Character type: Uppercase and lowercase English letters, Chinese characters, digits, and special characters Required: Yes |
Obfuscation configuration
If your app obfuscates code, add the following code segment to the obfuscation configuration file:
-keep class com.taobao.tao.log.**{*;}
-keep public class * extends com.taobao.android.tlog.protocol.model.request.base.FileInfo{*;}
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
Compile
If you use other Alibaba Cloud products at the same time, a UTDID conflict in the dependencies may cause the compilation to fail. For more information about how to resolve this issue, see Solutions to UTDID conflicts in the SDK.
Sample code
For a sample project that shows how to integrate the Android SDK for the Remote Log Service, see the Demo project.