Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daily release/08/26/2024/evening #18493

Merged
merged 10 commits into from
Aug 27, 2024
4 changes: 4 additions & 0 deletions scripts/actions/utils/handlers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ export default {
deserialize: deserializeComponent,
serialize: serializeComponent,
},
span: {
deserialize: deserializeComponent,
serialize: serializeComponent,
},
sup: {
deserialize: deserializeComponent,
serialize: serializeComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ These are generalized steps to set up Micrometer metrics forwarding. You may wan
.registerMetricReader(
PeriodicMetricReader.builder(
OtlpHttpMetricExporter.builder()
.setEndpoint("https://otlp.nr-data.net")
.setEndpoint("https://otlp.nr-data.net/v1/metrics")
.addHeader("api-key",
Optional
.ofNullable(System.getenv("NEW_RELIC_LICENSE_KEY"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tags:
translate:
- jp
- kr
freshnessValidatedDate: 2024-11-30
freshnessValidatedDate: 2024-08-21
metaDescription: 'New accounts: Get Android app monitoring in New Relic at newrelic.com/signup. Existing accounts: Add mobile monitoring to your Android apps from the UI.'
redirects:
- /docs/mobile-apps/troubleshooting-eclipse-configurations
Expand Down Expand Up @@ -38,150 +38,186 @@ redirects:
- /docs/mobile-monitoring/new-relic-mobile-android/install-configure/install-android-apps-gradle-android-studio
---

To install the Android agent, you need to use our [guided install](https://onenr.io/0kjnEoryzRo). Setting up the Android agent requires an [application token](/docs/mobile-apps/viewing-your-application-token) that authenticates each mobile app you want to monitor. The app token is only available by going through the guided install.

## Install the Android agent with guided install [#guided-install]
To install the Android agent, we recommend you follow our guided install:

1. Go to <DNT>**[one.newrelic.com](https://one.newrelic.com) > Integrations & Agents > Mobile > Android**</DNT>.
2. Follow the guided install steps to set up your Android agent.
3. Wait a few minutes, then view your data by going to <DNT>**[one.newrelic.com > All capabilities](https://one.newrelic.com/all-capabilities) > Mobile > (select your app)**</DNT>.


## Manually install the Android agent [#manual-install]

These procedures appear in our guided install. Keep in mind that even if you're updating your build files through the docs, you still need to add your app to New Relic and grab your generated app token from the guided install. You cannot capture data about your Android apps otherwise.
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.

1. Add the following code to your `build.gradle` files found in the Gradle & Android Studio tab. You need to update the top-level build snippet and each sub-module that you want to instrument.
<Steps>
<Step>
Add the Android agent plugin to your project.

<CollapserGroup>
<Collapser
id="project-level"
title="Project level `build.gradle` file:"
>
In this example, `AGENT_VERSION` represents your agent version number. See the [agent release notes](/docs/release-notes/mobile-release-notes/android-release-notes), and use the latest version.
Regarding the location of the plugin, you have two options:

```groovy
buildscript {
repositories {
mavenCentral()
}
* 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. The Gradle plugin DSL simplifies 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.

dependencies {
classpath "com.newrelic.agent.android:agent-gradle-plugin:AGENT_VERSION"
}
}
```
</Collapser>

<Collapser
id="app-level"
title="App level `build.gradle` file:"
>
In this example, `AGENT_VERSION` represents your agent version number. See the [agent release notes](/docs/release-notes/mobile-release-notes/android-release-notes), and use the latest version.

```groovy
repositories {
mavenCentral()
}
Follow the detailed steps below for your chosen installation method.

apply plugin: 'android'
apply plugin: 'newrelic'
<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.

dependencies {
implementation 'com.newrelic.agent.android:android-agent:AGENT_VERSION'
}
```
</Collapser>
</CollapserGroup>
1. Declare the New Relic plugin to the top-level `build.gradle(.kts)` file using the Gradle Plugin Portal plugin ID:

2. Set app permissions. Ensure that your Android app requests `INTERNET` and `ACCESS_NETWORK_STATE` permissions by adding these lines to your `AndroidManifest.xml` file:
```groovy
plugins {
// for binary Gradle plugins that need to be resolved
id("com.newrelic.agent.android") version "AGENT_VERSION" apply false
}
```

```xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```
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/).

3. Start the Android agent. In your default Activity found in your manifest, import the `NewRelic` class:
2. Apply the plugin explicitly to the app-level build file (and any sub-modules intended for instrumentation) using the following syntax:

```java
import com.newrelic.agent.android.NewRelic;
```
```groovy
plugins {
id("com.newrelic.agent.android")
}
```

We don't support starting the <InlinePopover type="mobile"/> agent in other classes, as that can cause unexpected or unstable behavior.
For detailed information on applying plugins within Gradle, refer to the [Gradle documentation](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block).

4. After you've imported the `NewRelic` class, you need to add an additional snippet to the `onCreate()` method, which includes your app token, which is generated in the guided install. The snippet looks like this:
</Collapser>

```java
NewRelic.withApplicationToken("GENERATED_TOKEN").start(this.getApplicationContext());
```
<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:

```groovy
buildscript {
repositories {
mavenCentral()
}

// 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
}
}
```

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/).

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>

5. If you're using minification (for example, like with ProGuard or Dexguard), you need to add `newrelic.properties` file to your app-level directory (_projectname/app_). This step only applies to ProGuard and DexGuard users.
</Step>

```ini
com.newrelic.application_token=GENERATED_TOKEN
```
<Step>
In your `AndroidManifest.xml` file, add the following permissions:

To finish set up for minification, follow the steps in [configure ProGuard or DexGuard for Android apps](/docs/mobile-monitoring/new-relic-mobile-android/install-configure/configure-proguard-or-dexguard-android-apps).
```xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```
</Step>

6. 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.
<Step>
In your main `Activity` class within the `onCreate` method, add this import statement:

7. View your data for your Android app. Go to <DNT>**[one.newrelic.com > All capabilities](https://one.newrelic.com/all-capabilities) > Mobile > (select an app)**</DNT>.
```java
import com.newrelic.agent.android.NewRelic;
```

## Configure the Android agent for Gradle Plugin Portal [#plugin-portal]
Note: You must add this import statement to the `Activity` class. We don’t support starting the agent in other classes.
</Step>

Because the Android agent isn't yet available as a community plugin, you need to provide the classpath through [MavenCentral](https://mvnrepository.com/artifact/com.newrelic.agent.android/agent-gradle-plugin) so the agent can instrument your Android app. If you've configured your app to look for plugins through Gradle Plugin Portal, you need to repeat this step in the `settings.gradle(.kts)` file.
<Step>
In the `onCreate` method, add the following line, making sure to replace `GENERATED_TOKEN` with your actual app token (created during the guided install):

1. Add this snippet to your `settings.gradle(.kts)` file through `pluginManagement {}` block:
```java
NewRelic.withApplicationToken("GENERATED_TOKEN").start(this.getApplicationContext());
```

```groovy
pluginManagement {
repositories {
mavenCentral() // adds repo for NewRelic artifacts
}
resolutionStrategy {
eachPlugin {
if (requested.id.id.startsWith("newrelic")) {
useModule("com.newrelic.agent.android:agent-gradle-plugin:${AGENT_VERSION}")
}
}
}
</Step>

// optional: define as a community plugin here or in root level build file
<Step>
(Optional) Additional configurations for Proguard/Dexguard

// for core Gradle plugins or plugins already available to the build script
plugins {
id("newrelic") version "${AGENT_VERSION}"
}
}
```
If you use ProGuard or Dexguard for code shrinking, follow these steps:

2. Declare the New Relic plugin:
1. Create a `newrelic.properties` file in your app-level directory (ex: `/projectname/app/newrelic.properties`).
2. In this new file, add the following line, replacing `GENERATED_TOKEN ` with your actual token:

```groovy
plugins {
// for binary Gradle plugins that need to be resolved
id("newrelic") version "AGENT_VERSION" apply false
}
```
```java
com.newrelic.application_token=GENERATED_TOKEN
```
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>

3. Apply the plugin to the app-level build files:
<Step>
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.
</Step>

```groovy
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("newrelic")
}
```
<Step>
View your app's data on New Relic by going to <DNT>**[one.newrelic.com > All capabilities](https://one.newrelic.com/all-capabilities) > Mobile > (select an app)**</DNT>.
</Step>
</Steps>

In the above snippets, `AGENT_VERSION` represents your agent version number. We strongly recommend you use the latest agent for set up.
## 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](/docs/mobile-monitoring/new-relic-mobile-android/install-configure/configure-new-relic-gradle-plugin).
* [Upgrade the Android agent SDK](/docs/mobile-monitoring/new-relic-mobile-android/install-configure/upgrading-new-relic-mobiles-android-sdk) to keep your Android agent up to date.
* Having problems with your Android installation? Follow the [troubleshooting procedures](/docs/mobile-monitoring/new-relic-mobile-android/troubleshoot/no-data-appears-android).

## Android 4.x: Multidex support [#4x-multidex]

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](https://developer.android.com/studio/build/multidex.html). Then you can use the [multidex support library](https://developer.android.com/tools/support-library/features.html#multidex), which becomes part of the primary DEX file of your app. The library manages access to the additional DEX files and their containing code.

<Collapser
id="error"
title="Troubleshoot `java.lang.NoClassDefFoundError`"
title="Troubleshoot the java.lang.NoClassDefFoundError error"
>
When building each DEX file for a multidex app, the build tools perform complex decision making to determine which classes are needed in the primary DEX file so that your app can start successfully. If, during start up, the required classes aren't available in the primary DEX file, your app will crash with the error `java.lang.NoClassDefFoundError`.

Expand Down Expand Up @@ -211,12 +247,4 @@ Mobile monitoring for Android versions older than Android 5.0 (API level 21) use
```

For more information, see the [Android Developers documentation](https://developer.android.com/studio/build/multidex.html#keep) on declaring classes required in the primary DEX file.
</Collapser>

## 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](/docs/mobile-monitoring/new-relic-mobile-android/install-configure/configure-new-relic-gradle-plugin).
* [Upgrade the Android agent SDK](/docs/mobile-monitoring/new-relic-mobile-android/install-configure/upgrading-new-relic-mobiles-android-sdk) to keep your Android agent up to date.
* Having problems with your Android installation? Follow the [troubleshooting procedures](/docs/mobile-monitoring/new-relic-mobile-android/troubleshoot/no-data-appears-android).
</Collapser>
Loading