This topic describes how to add dependencies and connect to Remote Log Access using local integration.
You can add dependencies for the Android SDK for Remote Log Access using either Maven integration or local integration. Maven integration is recommended to simplify the connection process.
To add dependencies using Maven integration, see Connect to the Android SDK (Maven integration).
Prerequisites
A project and an application have been created. For more information, see Quick Start.
The configuration file has been downloaded, and the AppKey and AppSecret have been obtained. For more information, see Download the configuration file.
The SDK has been downloaded. For more information, see Download the SDK.
The public key for Remote Log Access has been obtained. This is the value of the
appmonitor.tlog.rsaSecretfield in the configuration file.
Limits
Only Android 4.2 and later are supported.
Only the armeabi-v7a, arm64-v8a, x86, and x86_64 architectures are supported.
Logs are stored on the mobile device for a maximum of 7 days.
Overview
Add dependencies: Use local integration.
Connect to the service: Add a custom Application class and initialization code. Configure the ABI. Set the log level for pulling logs.
Log printing: Import the header file. Print log messages in your code.
Configure obfuscation: If your app obfuscates code, modify the obfuscation configuration file.
Add dependencies
1. Copy all files from the SDK package to the libs folder of your project.
2. In the project's build.gradle file, add the path to the local SDK file directory.
repositories {
flatDir {
dirs 'libs'
}
}3. In the dependencies{} code segment of the project's build.gradle file, add the SDK dependencies.
// 1. Import local JAR libraries
compile fileTree(include the following:['*.jar'],dir:'libs')
// 2. Public libraries
compile(name:'alicloud-android-ha-adapter-1.2.4.0-open',ext:'aar')
compile(name:'alicloud-android-ha-core-1.1.0.7-open',ext:'aar')
compile(name:'alicloud-android-ha-protocol-1.1.5.0-open',ext:'aar')
compile(name:'alicloud-android-rest-1.7.8-open',ext:'aar')
compile(name:'alicloud-android-tool-1.1.0',ext:'aar')
compile(name:'alicloud-android-utdid-2.6.0',ext:'jar')
compile(name:'fastjson-1.1.73.android',ext:'jar')
compile(name:'alicloud-android-settingservice-1.2.0',ext:'aar')
compile(name:'alicloud-android-logger-1.2.0',ext:'aar')
// 3. Mobile logs. Comment this out if you do not connect to this service.
compile(name:'alicloud-android-tlog-1.1.8.0-open',ext:'aar')
compile(name:'alicloud-android-ha-tlog-message-rpc-1.1.3.2-open',ext:'aar')
compile(name:'alicloud-android-ha-tlog-uploader-oss-1.1.0.9-open',ext:'aar')
compile(name:'alicloud-android-ha-tlog-protocol-1.1.1.0-open',ext:'aar')
compile(name:'alicloud-android-ha-tlog-native-1.1.2.0-open',ext:'aar')
compile(name:'alicloud-android-cpp-shared-1.1.0',ext:'aar')
compile(name:'oss-android-sdk-2.9.15',ext:'aar')
compile(name:'okhttp-3.11.0',ext:'jar')
compile(name:'okio-1.14.0',ext:'jar') Connect to the service
Pre-initialize the SDK
You can pre-initialize the SDK in the Application.onCreate function.
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AliHaAdapter.getInstance().preStart(this);
}
}Enable Remote Log Access
After the user agrees to the privacy policy, you can enable Remote Log Access.
private void startHa() {
AliHaConfig config = new AliHaConfig();
config.appKey = "xxxxxxxx"; // Configuration item: appkey
config.appVersion = "x.xx"; // Configuration item: Application version number
config.appSecret = "xxxxxxxxxxxx"; // Configuration item: appsecret
config.channel = "mqc_test"; // Configuration item: Application channel ID. This is a custom value.
config.userNick = null; // Configuration item: User nickname
config.application = this; // Configuration item: Application pointer
config.context = getApplicationContext(); // Configuration item: Application context
config.isAliyunos = false; // Configuration item: Specifies whether the OS is YunOS
config.rsaPublicKey = "xxxxxxx"; // Configuration item: tlog public key
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 parameters are described as follows:
Parameter | Description |
config.appKey | Specifies the AppKey of the application. Data type: string For more information, see Step 1. Required: Yes Can be empty: No Default value: None |
config.appVersion | Sets the version number of the application. Data type: string Format: Custom Value range: Any length. Note This parameter value is displayed as an option in a drop-down list in the console. Use a short and concise value. 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 letters, and digits. Note This parameter does not support Chinese characters or special characters. |
config.appSecret | Specifies the AppSecret of the application. Data type: string For more information, see Step 1. 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 different channels. Data type: string Value range: Any length Required: No Can be empty: Yes Default value: None Character type: Uppercase and lowercase 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 can be used for data retrieval. Data type: string Value range: Any length Required: No Can be empty: Yes Default value: None Character type: Uppercase and lowercase letters, and digits. Note This parameter does not support Chinese characters or special characters. Naming conventions: Custom |
config.application | Specifies the current application. Important It cannot point to other applications. Data type: object Required: Yes Can be empty: No Default value: None |
config.context | Specifies the context object of the application. Set it to Data type: object Required: Yes Can be empty: No Default value: None |
config.isAliyunos | Specifies whether the application is running on YunOS. Data type: Boolean Value range: false/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. 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 Value range:
Required: Yes Default value: ERROR Configuration notes:
|
Data collection
To meet compliance requirements, configure the information collection settings as early as possible. By default, device information, system information, and network information 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; 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, system version (Build.VERSION.RELEASE, Build.VERSION.SDK_INT), and unique system build ID (Build.FINGERPRINT) |
NO_NETWORK_DATA | Do not collect network information | 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>Log printing
1. Import the required header file:
import com.alibaba.ha.adapter.service.tlog.TLogService;2. Add the code to the appropriate location to output log messages. 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: Outputs a log message of a specified level.
Parameter | Description |
LogLevel | Specifies the log level to pull. For more information about log levels, see Terms. Data type: enumeration Value range:
Configuration notes: Whether the output log can be pulled by the console depends on the parameter settings of the |
MODEL | Sets the functional module that outputs the log content. This helps you filter logs by source. Data type: string Character type: Uppercase and lowercase letters, Chinese characters, digits, and special characters Required: Yes Case-sensitive: No Example: "Push feature module Push" |
TAG | Sets a keyword for the log. This helps you filter logs by tag. Data type: string Character type: Uppercase and lowercase letters, Chinese characters, digits, and special characters Required: Yes Case-sensitive: No Example: "The push feature module received a push notification Push.receive, the push feature module clicked a push notification Push.click" |
MESSAGE | Outputs the log message. Data type: string Character type: Uppercase and lowercase letters, Chinese characters, digits, and special characters Required: Yes |
Configure obfuscation
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*,EnclosingMethodCompile
If you use other Alibaba Cloud products at the same time, a UTDID conflict may occur in the dependencies and cause the compilation to fail. For more information, see Solutions for SDK UTDID conflicts.
Sample code
For a sample project that shows how to connect to the Remote Log Access Android SDK, see the Demo project.