To install the Android agent, we recommend you follow our guided install:
- Go to one.newrelic.com > Integrations & Agents > Mobile > Android.
- Follow the guided install steps to set up your Android agent.
- Wait a few minutes, then view your data by going to one.newrelic.com > All capabilities > Mobile > (select your app).
Manually install the Android agent
The steps below are outlined in our guided install. Note that even if you manually install the agent, you'll still need to create a New Relic app and obtain the generated application token. This token is essential for the agent to send data to New Relic.
Add the Android agent plugin to your project.
Regarding the location of the plugin, you have two options:
- Recommended: Using the Gradle plugin DSL
- Starting with agent version 7.6.0, the Android agent plugin is available on the Gradle Plugin Portal as a community plugin. The Gradle plugin DSL simpifies adding plugin dependencies to apps.
- This method involves adding the agent plugin dependency to your project's plugins DSL block.
- Legacy Plugin ID (
newrelic
)- For older projects or specific use cases, you can use the legacy plugin ID.
- This method involves adding the agent as a dependency to your project's build script, specifying the MavenCentral repository.
Follow the detailed steps below for your chosen installation method.
In your AndroidManifest.xml
file, add the following permissions:
<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
In your main Activity
class within the onCreate
method, add this import statement:
import com.newrelic.agent.android.NewRelic;
Note: You must add this import statement to the Activity
class. We don’t support starting the agent in other classes.
In the onCreate
method, add the following line, making sure to replace GENERATED_TOKEN
with your actual app token (created during the guided install):
NewRelic.withApplicationToken("GENERATED_TOKEN").start(this.getApplicationContext());
(Optional) Additional configurations for Proguard/Dexguard
If you use ProGuard or Dexguard for code shrinking, follow these steps:
Create a
newrelic.properties
file in your app-level directory (ex:/projectname/app/newrelic.properties
).In this new file, add the following line, replacing
GENERATED_TOKEN
with your actual token:com.newrelic.application_token=GENERATED_TOKENFollow the steps decribed on Configure ProGuard or DexGuard for Android apps.
Clean your project, then run your app in an emulator or device to generate traffic. Wait a few minutes as your agent captures that data.
View your app's data on New Relic by going to one.newrelic.com > All capabilities > Mobile > (select an app).
What's next?
Congratulations! You've successfully installed the Android agent. You have a few options for next steps:
- Configure agent behavior during Gradle builds with the New Relic Gradle plugin.
- Upgrade the Android agent SDK to keep your Android agent up to date.
- Having problems with your Android installation? Follow the troubleshooting procedures.
Android 4.x: Multidex support
Mobile monitoring for Android versions older than Android 5.0 (API level 21) use the Dalvik runtime to execute app code. By default, Dalvik limits apps to a single classes.dex
bytecode file per APK. To get around this limitation, you must enable multidex support. Then you can use the multidex support library, which becomes part of the primary DEX file of your app. The library manages access to the additional DEX files and their containing code.