Real User Monitoring (RUM) of Application Real-Time Monitoring Service (ARMS) provides comprehensive monitoring capabilities for iOS apps and Android apps. This topic describes how to integrate an Android app into RUM through Maven.
Prerequisite
Your application is running Android V8.0 or later.
Step 1: Add the app
Log on to the ARMS console.
In the left-side navigation pane, choose . In the top navigation bar, select a region.
On the Applications page, click Add Application.
In the Create Application panel, click Android.
In the Android panel, enter the app name, set other parameters as needed, and click Create.
NoteThe name must be unique.
Then, an address to which monitoring data is reported (ConfigAddress) and an app ID (AppID) are automatically generated for the app.
Step 2: Integrate the RUM SDK
Automatic integration through Maven (recommended)
In Android Studio, add Maven online dependencies to the build.gradle file of the project and import the RUM SDK of the latest version.
Add the RUM plug-in dependency to the build.gradle file in the root directory of the project.
buildscript { repositories { mavenLocal() google() mavenCentral() gradlePluginPortal() } dependencies { // Import the RUM plug-in dependency // Import the latest SDK version. For more information about the latest version, see the Android SDK documentation. classpath "com.aliyun.rum:alibabacloud-android-rum-plugin:1.0.7" } }In the build.gradle file, enable the plug-in and add the SDK dependency.
Enable the RUM plug-in.
apply plugin: "com.aliyun.rum"Add the SDK dependency.
dependencies { // Import the RUM SDK. // Import the latest SDK version. For more information about the latest version, see the Android SDK documentation. implementation("com.aliyun.rum:alibabacloud-android-rum-sdk:1.0.7") }
Manual integration
Download the installation package of the RUM SDK and decompress the package.
The package contains the following contents:
libs folder: contains the required JAR packages and JNI libraries.
repo folder: contains the required plug-ins.
Configure the project.
Copy the repo and libs folders and respectively paste them to the project root directory and app Module directory.

Open the build.gradle (Gradle 7.0 or later) or settings.gradle (Gradle 7.0 or later) file under the project root directory, and add the following Maven configurations to the repositories block.
build.gradle file configurations
buildscript { repositories { maven { url uri('./repo') } //...Other configurations } } allprojects { repositories { maven { url uri('./repo') } //...Other configurations } } //...Other configurationssettings.gradle file configurations
pluginManagement { repositories { maven { url uri('./repo') } //...Other configurations } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { maven { url uri('./repo') } //...Other configurations } } //...Other configurationsIn the build.gradle file under the project root directory, add the classpath configuration.
// Add the following content without distinguishing Gradle versions. buildscript { dependencies { classpath "com.aliyun.rum:alibabacloud-android-rum-plugin:1.0.0" } } //...Other configurationsOpen the build.gradle file under the app Module directory and import the RUM plug-in and dependencies.
apply plugin: "com.aliyun.rum" //...Other configurations android { //...Other configurations sourceSets { main { jniLibs.srcDirs = ['libs'] } } //...Other configurations } dependencies { implementation files('libs/alibabacloud-android-rum-sdk.jar') //...Other configurations }
Step 3: Grant permissions
To use the RUM SDK, grant the following permissions on the app.
<!-- Mandatory -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- Optional -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_BASIC_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>Step 4: Configure obfuscation
If you want to use ProGuard to obfuscate the code, add the following configurations.
-keep public class com.alibabacloud.rum.** { *; }
-dontwarn com.alibabacloud.rum.**
-optimizations !code/simplification/*,!field/*,!class/merging/*,!method/propagation/*,!class/unboxing/enum,!code/allocation/variableStep 5: Initialize the RUM SDK
Add the following code to the onCreate function of the app:
import com.alibabacloud.rum.AlibabaCloudRum;
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AlibabaCloudRum.withAppID("<your appid>") // Specify the app ID.
.withConfigAddress("<your config address>") // Specify the address.
.start(getApplicationContext());
}
}Verify the result
Start the APK. In the Logcat window, view the logs, and search for the RUM agent by keyword (AlibabaCloudRUM) or tag. If the following log entry appears, the RUM SDK has been integrated and data is being collected.
