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 Android agent, follow the instructions on this page.
Check compatibility and requirements
Splunk RUM for Mobile supports Java and Kotlin applications for Android. You can include this agent in applications with a minimum API level of 21 (Android 5.0) or higher. Full observability and feature support are available at runtime on API level 24 (Android 7.0) and above. API levels 21 to 25 require core library desugaring to be activated. See Activate desugaring in your application.
Activate desugaring in your application
In yor application module's build.gradle file, 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.
Install the Splunk RUM Android agent as a dependency
Install the agent in your Android application as a code-level dependency using Maven Central. Installing the the agent activates it. Follow these steps to install it:
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:- Kotlin DSL (build.gradle.kts)
allprojects { repositories { google() mavenCentral() ... } }
- Groovy (build.gradle)
allprojects { repositories { google() mavenCentral() ... } }
Add the Splunk RUM Android agent to your build scripts:
In your application 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.2") ... }
- Groovy (build.gradle)
dependencies { implementation 'com.splunk:splunk-otel-android:2.0.2' ... }
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.2'
Initialize the Android RUM agent by passing a configuration object to the initialization call in
Application.onCreate()
:Note: In case of integration onboarding, replace all <placeholder> strings in the following code blocks with the value that is either generated (rumAccessToken
) or prefilled by the client in previous steps (appName
,deploymentEnvironment
,appVersion
).If
appVersion
(optional to be specified by the client) is not provided, remove its line of code 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 = "<placeholder>", rumAccessToken = "<placeholder>" ), appName = "<placeholder>", deploymentEnvironment = "<placeholder>", appVersion = "<placeholder>" ) ) } }
- Java
public class App extends Application { @Override public void onCreate() { super.onCreate(); SplunkRum agent = SplunkRum.install( this, new AgentConfiguration( new EndpointConfiguration( "<placeholder>", // Splunk realm "<placeholder>" // Splunk access token ), "<placeholder>", // Application name "<placeholder>", // Deployment environment "<placeholder>" // 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");