Install the Splunk RUM Android agent
Instrument your Android applications in using the unified agent.
To instrument a new Android application with the new Splunk RUM agent, follow the instructions on this page. If you're already instrumenting the application with an older version of the Splunk RUM, follow the instructions on Upgrade the Splunk RUM Android agent instead.
Check compatibility and requirements
Splunk RUM for Mobile supports Java and Kotlin applications for Android API Level 24 and higher. API levels 24 to 25 require core library desugaring activated. See Activate desugaring in your application. Android 7.0 (also known as Nougat) corresponds to API level 24.
Activate desugaring in your application
Open the build.gradle file for your application module and update the
compileOptions
anddependencies
sections as in the following examples:- Kotlin
android { compileOptions { // Flag to enable support for the new language APIs // For AGP 4.1+ isCoreLibraryDesugaringEnabled = true // For AGP 4.0 // coreLibraryDesugaringEnabled = true // Sets Java compatibility to Java 8 sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } kotlinOptions { // If this setting is present, jvmTarget must be "1.8" jvmTarget = "1.8" } } dependencies { // For AGP 7.4+ coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.3") // For AGP 7.3 // coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.2.3") // For AGP 4.0 to 7.2 // coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.9") }
- Groovy
android { compileOptions { // Flag to enable support for the new language APIs coreLibraryDesugaringEnabled true // Sets Java compatibility to Java 8 sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { // If this setting is present, jvmTarget must be "1.8" jvmTarget = "1.8" } } dependencies { // For AGP 7.4+ coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.3' // For AGP 7.3 // coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.3' // For AGP 4.0 to 7.2 // coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.9' }
Save and sync your project to implement desaguring in your application.
Install the Android agent as a dependency
Activate the Splunk RUM agent by installing it as a code-level dependency in your Android application, using Maven Central:
Confirm that Maven Central is included in your build scripts. In your project's root
build.gradle
file, inside theallprojects
block, addmavenCentral()
to the list of repositories, and also an additional URL to include session replay:- Kotlin DSL (build.gradle.kts)
allprojects { repositories { google() mavenCentral() ... } }
- Groovy (build.gradle)
allprojects { repositories { google() mavenCentral() ... } }
Add the Splunk RUM agent library to your build scripts. In your app module's
build.gradle
file, inside thedependencies
block, include the following: file, inside the dependencies block, include the following:Note: Change the versions of these dependencies with every release. Don't use the+
wildcard notation to specify the version.- Kotlin DSL (build.gradle.kts)
dependencies { implementation("com.splunk:splunk-otel-android:2.0.0") ... }
- Groovy (build.gradle)
dependencies { implementation 'com.splunk:splunk-otel-android:2.0.0' ... }
Remove the line below your dependencies (the upstream opentelemetry-android repository) because it's already linked in our SDK:
implementation 'io.opentelemetry.android:instrumentation:2.0.0'
Initialize the Android RUM agent by passing a configuration object to the initialization call in
Application.onCreate()
:Note: In case of integration onboarding, all places in the code visible in the following code blocks that are marked as placeholder must be replaced with a string value that is either generated (rumAccessToken
) or prefilled by the client in previous steps (appName
,deploymentEnvironment
,appVersion
) based on the previous steps.In case the
appVersion
, which is optional to fill, was not specified by the client, this line of code should be removed from the code blocks, along with its trailing comma (,
).- Kotlin
class App: Application() { override fun onCreate() { super.onCreate() val agent = SplunkRum.install( application = this, agentConfiguration = AgentConfiguration( endpoint = EndpointConfiguration( realm = "<inserted>", rumAccessToken = "<inserted>" ), appName = "<inserted>", deploymentEnvironment = "<inserted>", appVersion = "<inserted>" ) ) } }
- Java
public class App extends Application { @Override public void onCreate() { super.onCreate(); SplunkRum agent = SplunkRum.install( this, new AgentConfiguration( new EndpointConfiguration( "<inserted>", // Splunk realm "<inserted>" // Splunk access token ), "<inserted>", // Application name "<inserted>", // Deployment environment "<inserted>" // Application version ) ); } }
The value passed to
EndpointConfiguration
is the Splunk Observability Cloud realm, for example,us0
. To find the realm name of your account, follow these steps:Open the navigation menu in Splunk Observability Cloud.
Select Settings.
Select your username.
The realm name appears in the Organizations section.
To generate a RUM access token, see Generate your RUM access token in Splunk Observability Cloud.
For a sample application using Android RUM, see the sample application in GitHub .
Instrument Android WebViews using the Browser RUM agent
You can use Mobile RUM instrumentation and Browser RUM instrumentation simultaneously by sharing the session.id
between both instrumentations to see RUM data combined in one stream.
The following snippet shows how to integrate Android RUM with browser RUM:
- Kotlin
/* * IMPORTANT: * Only load pages you control and that are instrumented with Splunk Browser RUM. * The integrateWithBrowserRum() method can expose your user's session.id * to every site/page loaded in this WebView instance. */ val webView: WebView = /* obtain the WebView instance */ val webSettings: WebSettings = webView.settings webSettings.javaScriptEnabled = true SplunkRum.instance.webViewNativeBridge.integrateWithBrowserRum(webView) webView.webViewClient = WebViewClient() webView.loadUrl("https://subdomain.example.com/instrumented-page.html")
- Java
// IMPORTANT: // Only load pages you control and that are instrumented with Splunk Browser RUM. // The integrateWithBrowserRum() method can expose your user's session.id // to every site/page loaded in this WebView instance. WebView webView = /* obtain the WebView instance */; WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); WebViewNativeBridge.getInstance().integrateWithBrowserRum(webView); webView.setWebViewClient(new WebViewClient()); webView.loadUrl("https://subdomain.example.com/instrumented-page.html");