Install the New Relic plugin for Android Instant Apps

Android Instant Apps allow users to quickly use your applications without installation. With the Mobile Android agent version 5.17.0 and higher, you can use New Relic to detect and instrument all feature modules for an instant app.

Use this documentation along with the standard New Relic procedures to install Android apps with Gradle and Android Studio. After following the standard installation procedures, follow these additional steps for Android instant apps.

Terminology

This procedure uses the following terms that are specific to the Android Instant Apps plugin:

  • Module: Any packaged class and/or resource collection
  • APK: A module that packages the apps resources and DEX’ed classes
  • Feature module: A slimmed down module that contains only a subset of the total APK

Install the plugin

To install the New Relic plugin for Android Instant Apps:

  1. First follow the steps in the Install Android apps with Gradle and Android Studio documentation.

  2. Apply the agent plugin in every project Gradle build file.

  3. List the Android agent as a dependency.

  4. Start the agent from each Activity class in the feature that could be side-loaded through a Digital Asset Link intent, (for example, mobile.example.com/signin).

    Minimal build.gradle example
    apply plugin: ‘com.android.[application|library|feature|instantapp]'
    
    apply plugin: ‘newrelic’
    
    dependencies {
    
        implementation "com.newrelic.agent.android:android-agent:${project.agentVersion}"
    
    }
  5. Review the considerations for instrumentation.

Instrumentation

When instrumenting an instant app, be aware of the following considerations with APKs:

Instant apps and APKs Comments
Instrumentation
  • Instrumentation of instant apps behaves the same as instrumentation with a normal APK. The agent will detect when an APK is an instant app. For feature APKs, the agent will inject a unique build ID that instant apps will use when reporting crashes.

  • The side-loaded (main) activity of every feature must call NewRelic.start() when the activity is created (as per normal instructions).

ProGuard and Dexguard support for feature and application APKs

Place the newrelic.properties file in the root (main) directory of the project.

ProGuard and Dexguard support

The Android Studio Gradle plugin will obfuscate any build configuration where minifyEnabled is set to true. In these conditions, the New Relic agent will forward the ProGuard map generated for the build to crash collectors, tagged with a unique build ID generated by the agent.

Obfuscation is best configured in the application or instant app project that includes other modules as dependencies. Modules may configure ProGuard as needed.

When using ProGuard or DexGuard with Android apps, follow the procedures to complete the additional, required configuration steps. For more information, see the ProGuard and DexGuard configuration documentation.

Troubleshoot auto-instrumentation

If you are not whether the agent is auto-instrumenting an instant app project, try running these steps:

  1. Build app with debug (-d, --debug) option, and capture the build log.

  2. Search the log for evidence of instant apps by looking for either of these terms:

    • This appears to be an Instant App
    • BuildId[1a2b34c5-def6-7890-g123-h4567890a]
  3. The agent will add an attribute named 'instantApp' to the app's Insights session attributes if the app appears to be an instant app.

For more help

Recommendations for learning more: