Real User Monitoring (RUM) of Cloud Monitor 2.0 provides comprehensive monitoring for mobile apps, including real-time monitoring and analysis of key metrics such as app performance, crashes, and stuttering. This topic describes how to integrate an Android app into Cloud Monitor 2.0.
Prerequisite
Your application is running Android V8.0 or later.
Step 1: Add the app
Log on to the Cloud Monitor 2.0 console, and select a workspace. In the left navigation pane, click Integration Center.
In the Frontend Applications section, click the Android card. Enter an app name, set other parameters, and click Create Application.
NoteThe name must be unique.
After the app is created, the integration code appears at the bottom of the page. This code contains key information, such as the app ID and configuration address.
To view the created app, choose page. On the application details page, view the integration code on the page.
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 SDK
Add the following code to the first line of the onCreate function in your custom app.
import com.alibabacloud.rum.AlibabaCloudRum;
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AlibabaCloudRum.withAppID("<your appid>") // The app ID obtained in Step 1.
.withConfigAddress("<your config address>") // The configuration address obtained in Step 1.
.withWorkspace("<your workspace>") // Replace it with the name of your current workspace.
.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.
