All Products
Search
Document Center

:Integrate an Android app into RUM through Android Studio

Last Updated:Aug 20, 2024

The Real User Monitoring (RUM) sub-service 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 Android Studio.

Prerequisites

The Gradle version is later than 3.0.

Change the Gradle version

Import or create a project in Android Studio, choose File > Project Structure from the top navigation bar, select an appropriate Gradle version, and then click OK.

Step 1: Add the app and configure the OpenRUM agent

  1. Log on to the ARMS console.

  2. In the left-side navigation pane, choose User Experience Monitoring > Application List. In the top navigation bar, select a region.

  3. On the Applications page, click Add Application.

  4. In the Create Application panel, click Android.

  5. In the Android panel, enter the app name and description, and click Create.

    Note

    The 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.

  6. Preset the environment for the OpenRum SDK.

    1. Download the installation package of the OpenRUM SDK and decompress the package.

    2. Compress the contents in the jniLibs directory, copy the compressed file, and paste the file to the module-level jniLibs directory that stores the .so libraries. If no jniLibs directory exists, create one.

    3. Copy the repo folder and paste it to the root directory of the project at the same level as the module-level jniLibs directory.

    4. Copy the co.openrum.skd.jar file and paste it to the module-level libs directory.

  7. Configure Gradle.

    1. Open the build.gradle file in the root directory of the project.

      1. Add the following content to the buildscript block.

        Note

        If no buildscript block exists, create one.

        ext.openrumsdk_version = "7.7.0" // Specify the OpenRUM SDK version.
      2. Add the following content to the repositories block under the buildscript block.

        Note

        If no repositories block exists, create one.

        maven {
          url uri("./repo")
        }
      3. Add the following content to the dependencies block under the buildscript block.

        Note

        If no dependencies block exists, create one.

        classpath "com.openrum.agent.android:openrum:$openrumsdk_version"
      4. Click Sync Now.

    2. Open the build.gradle file in all module-level directories.

      1. Introduce the OpenRUM plug-in in the header.

        apply plugin: 'openrum'
      2. Add the OpenRUM plug-in to the plugin block if the method for introducing the plug-in has been changed.

        id: "openrum"
      3. Add the following content to the Dependencies section.

        implementation files('libs/com.openrum.sdk.jar')
      4. Click Sync Now.

  8. Rebuild and clean the project to ensure that the OpenRUM configuration takes effect.

Step 2: Configure the app

  1. Grant the permissions.

    Check the AndroidManifest.xml file and grant the following permissions.

    <!-- Access the network -->
    <uses-permission android:name="android.permission.INTERNET"/> 
    <!-- Obtain network status -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <!-- Obtain device information and phone number -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <!-- Read and write data through public storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  2. Add obfuscation.

    Add the following configurations to the proguard-rules.pro file under the Gradle Scripts folder.

    #ProGuard configurations for OpenRum-Agent
    -keep public class com.openrum.**{*;}
    -keep public class openrum.**{*;}
    -dontwarn com.openrum.**
    -dontwarn openrum.**
    #End OpenRum-Agent
    
    -optimizations !code/simplification/*,!field/*,!class/merging/*,!method/propagation/*,!class/unboxing/enum,!code/allocation/variable

Step 3: Initialize the OpenRUM SDK

Add the following code to the onCreate function of the app:

Note

Replace the appKey and configUrl parameters in the following code with the app ID and address obtained in the ARMS console.

// Optional. Specify the user ID in a string.
OpenRum.setUserID("userID");
// Specify the app ID and address.
OpenRum.withAppID("appKey")
.withConfigAddress("configUrl")
.start(getApplicationContext());

(Optional) Step 4: Collect WebView data

You can use WebViewClient and WebChromeClient to collect WebView data.

  • Scenario 1: If you do not need custom clients, you do not need to call the setWebViewClient() or setWebChromeClient() method.

  • Scenario 2: If you need custom clients, rewrite the structure to prevent from affecting WebView data collection.

    webView.setWebChromeClient(new WebChromeClient(){});
    webView.setWebViewClient(new WebViewClient(){});

Step 5: Verify the result

Start the APK. In the Logcat window, view the logs, and search for the OpenRUM agent by keyword (openrum) or tag. If the following log entries appear, the embedding is successful and data is being collected.

image.png