Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ metaDescription: 'How to configure the New Relic Android agent to report app lau
freshnessValidatedDate: 2024-06-11
---

<Callout variant="important">
New Relic automatically adds the provider to capture app launch times for agent version 7.6.8 and later.
</Callout>

<Callout variant="important">
This feature is available for agent versions 6.9.0 and higher.
</Callout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ redirects:
freshnessValidatedDate: never
---

<Callout variant="important">
New Relic automatically adds the proguard rules for agent version 7.6.8 and later.
</Callout>

Follow these instructions to support ProGuard or DexGuard with the Android agent. Check [our Android compatibility and requirements](/docs/mobile-monitoring/new-relic-mobile-android/get-started/new-relic-android-compatibility-requirements), and if you have previously installed the Android agent SDK, follow the [steps before upgrading](/docs/mobile-apps/android-1-upgrade) to the latest version with ProGuard or DexGuard.

## Configure ProGuard [#proguard]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,107 +50,113 @@ To install the Android agent, we recommend you follow our guided install:
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.

<Steps>
<Step>
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](https://plugins.gradle.org/) 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.
<Step>
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](https://plugins.gradle.org/) 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.

<CollapserGroup>

<Collapser
id="DSL"
title="(Recommended) Apply the plugin using the plugins DSL block"
>
The recommended approach for managing plugin dependencies in Gradle utilizes the plugins DSL block. This section details applying the fully qualified form of the plugin ID (`com.newrelic.agent.android`) within this structure.

1. Declare the New Relic plugin to the top-level `build.gradle(.kts)` file using the Gradle Plugin Portal plugin ID:

```groovy
plugins {
// for binary Gradle plugins that need to be resolved
id("com.newrelic.agent.android") version "AGENT_VERSION" apply false
}
```

Follow the detailed steps below for your chosen installation method.
Make sure to replace `AGENT_VERSION` with your agent version number. We strongly recommend you use the [latest version](/docs/release-notes/mobile-release-notes/android-release-notes/).

<CollapserGroup>
<Collapser
id="DSL"
title="(Recommended) Apply the plugin using the plugins DSL block"
>
The recommended approach for managing plugin dependencies in Gradle utilizes the plugins DSL block. This section details applying the fully qualified form of the plugin ID (`com.newrelic.agent.android`) within this structure.
2. Apply the plugin explicitly to the app-level build file (and any sub-modules intended for instrumentation) using the following syntax:

1. Declare the New Relic plugin to the top-level `build.gradle(.kts)` file using the Gradle Plugin Portal plugin ID:
```groovy
plugins {
id("com.newrelic.agent.android")
}
```

```groovy
plugins {
// for binary Gradle plugins that need to be resolved
id("com.newrelic.agent.android") version "AGENT_VERSION" apply false
}
```
For detailed information on applying plugins within Gradle, refer to the [Gradle documentation](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block).

Make sure to replace `AGENT_VERSION` with your agent version number. We strongly recommend you use the [latest version](/docs/release-notes/mobile-release-notes/android-release-notes/).
</Collapser>

2. Apply the plugin explicitly to the app-level build file (and any sub-modules intended for instrumentation) using the following syntax:
<Collapser
id="buildscript"
title=" Apply the plugin using the buildscript{} block"
>
The Android agent plugin is available on MavenCentral and uses the legacy plugin ID `newrelic` for compatibility with older projects. If you choose to leverage this legacy ID for an existing app, you'll need to explicitly configure the classpath to MavenCentral. This ensures Gradle can locate the plugin during your build process. For further details on various methods for resolving plugins, refer to the [Gradle documentation](https://docs.gradle.org/current/userguide/plugins.html#sec:binary_plugin_locations).

```groovy
plugins {
id("com.newrelic.agent.android")
}
```
To prefer MavenCentral over the Gradle Plugin Portal, you need to make the following changes to Gradle files:

For detailed information on applying plugins within Gradle, refer to the [Gradle documentation](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block).
1. Add this snippet to your top-level build.gradle(.kts) file:

</Collapser>
```groovy
buildscript {
repositories {
mavenCentral()
}

<Collapser
id="buildscript"
title=" Apply the plugin using the buildscript{} block"
>
The Android agent plugin is available on MavenCentral and uses the legacy plugin ID `newrelic` for compatibility with older projects. If you choose to leverage this legacy ID for an existing app, you'll need to explicitly configure the classpath to MavenCentral. This ensures Gradle can locate the plugin during your build process. For further details on various methods for resolving plugins, refer to the [Gradle documentation](https://docs.gradle.org/current/userguide/plugins.html#sec:binary_plugin_locations).

To prefer MavenCentral over the Gradle Plugin Portal, you need to make the following changes to Gradle files:

1. Add this snippet to your top-level build.gradle(.kts) file:
// not required if plugin classpath in resolutionStrategy{} below
dependencies {
classpath "com.newrelic.agent.android:agent-gradle-plugin:AGENT_VERSION"
}
}
```

2. Add this snippet to your `settings.gradle(.kts)` file through the `pluginManagement {}` block:

```groovy
pluginManagement {
repositories {
mavenCentral() // adds repo for NewRelic artifacts
}
resolutionStrategy {
eachPlugin {
// not required if using `classpath dependency` above
if (requested.id.id.startsWith("newrelic") || requested.id.id.startsWith("com.newrelic.agent.android")) {
useModule("com.newrelic.agent.android:agent-gradle-plugin:${AGENT_VERSION}")
}
}
}
plugins {
id("newrelic") apply false
}
}
```

```groovy
buildscript {
repositories {
mavenCentral()
}
Make sure to replace `AGENT_VERSION` with your agent version number. We strongly recommend you use the [latest version](/docs/release-notes/mobile-release-notes/android-release-notes/).

// not required if plugin classpath in resolutionStrategy{} below
dependencies {
classpath "com.newrelic.agent.android:agent-gradle-plugin:AGENT_VERSION"
}
}
```
3. Apply the plugin to the app-level build file, as well as any other sub-module to be instrumented:

2. Add this snippet to your `settings.gradle(.kts)` file through the `pluginManagement {}` block:

```groovy
pluginManagement {
repositories {
mavenCentral() // adds repo for NewRelic artifacts
}
resolutionStrategy {
eachPlugin {
// not required if using `classpath dependency` above
if (requested.id.id.startsWith("newrelic") || requested.id.id.startsWith("com.newrelic.agent.android")) {
useModule("com.newrelic.agent.android:agent-gradle-plugin:${AGENT_VERSION}")
```groovy
plugins {
id("newrelic")
}
}
}
plugins {
id("newrelic") apply false
}
}
```
```
</Collapser>

</CollapserGroup>

Make sure to replace `AGENT_VERSION` with your agent version number. We strongly recommend you use the [latest version](/docs/release-notes/mobile-release-notes/android-release-notes/).
<Callout variant="important">
New Relic automatically adds the following permissions to allow the agent to make HTTP requests to deliver captured data for agent versions 7.6.8 and higher.
</Callout>

3. Apply the plugin to the app-level build file, as well as any other sub-module to be instrumented:

```groovy
plugins {
id("newrelic")
}
```
</Collapser>
</CollapserGroup>

</Step>
</Step>

<Step>
In your `AndroidManifest.xml` file, add the following permissions:
Expand Down Expand Up @@ -191,6 +197,9 @@ If you use ProGuard or Dexguard for code shrinking, follow these steps:
```java
com.newrelic.application_token=GENERATED_TOKEN
```
<Callout variant="important">
New Relic automatically adds the proguard rules for agent version 7.6.8 and later.
</Callout>
3. Follow the steps decribed on [Configure ProGuard or DexGuard for Android apps](/docs/mobile-monitoring/new-relic-mobile-android/install-configure/configure-proguard-or-dexguard-android-apps/).
</Step>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,6 @@ If you need to install the agent manually, follow these steps:
apply plugin: "com.android.application"
apply plugin: 'newrelic' // <-- include this
```

2. In your `AndroidManifest.xml` file, add the following permissions:

```xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```
</Step>
</Steps>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,7 @@ If you need to install the agent manually, follow these steps:
```


3. In your `AndroidManifest.xml` file, add the following permissions:
```xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```

4. To automatically link the package, rebuild your project:
3. To automatically link the package, rebuild your project:
```shell
# Android apps
ionic capacitor run android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,6 @@ If you need to install the agent manually, follow these steps:
* `Previous`: The URI of the previous page. This won't exist if the previous page was null.
</Step>

<Step>
### (Android only) Add permissions [#android-add-permissions]

If you have an Android-native app, you'll need to add `INTERNET` and `ACCESS_NETWORK_STATE` permissions in your `Platforms/Android/AndroidManifest.xml` file:

```xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
```
</Step>
</Steps>

## Customize the agent instrumentation [#mobile-sdk]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,6 @@ If you need to install the agent manually, follow these steps:
apply plugin: "com.android.application"
apply plugin: 'newrelic' // <-- add this
```

4. In your `AndroidManifest.xml` file, add the following permissions:

```xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```
</Step>

<Step>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,6 @@ If you need to install the agent manually, follow these steps:
apply plugin: "com.android.application"
apply plugin: 'newrelic' // <-- include this
```

3. Make sure your app requests `INTERNET` and `ACCESS_NETWORK_STATE` permissions by adding these lines to your `AndroidManifest.xml`:
```xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```
</Step>

<Step>
Expand Down