• EnglishEspañol日本語한국어Português
  • Log inStart now

Configure ProGuard or DexGuard for Android apps

Follow these instructions to support ProGuard or DexGuard with the Android agent. Check our Android compatibility and requirements, and if you have previously installed the Android agent SDK, follow the steps before upgrading to the latest version with ProGuard or DexGuard.

Configure ProGuard

To add support for ProGuard:

  1. Add an exclusion to your app; for example:

    • To support New Relic instrumentation, add keep class.
    • To disable warnings related to unresolved problems, add dont warn.
    • To preserve line numbers for crash reporting, add LineNumberTable.
    • To preserve stack information for handled exceptions, add SourceFile and EnclosingMethod.
  2. Add the following to your ProGuard config file (proguard.cfg, proguard-android.txt, proguard-rules.pro, etc.):

    -keep class com.newrelic.** { *; }
    -dontwarn com.newrelic.**
    -keepattributes Exceptions, Signature, InnerClasses, LineNumberTable, SourceFile, EnclosingMethod
    ##
    ## NewRelic Gradle plugin 7.x may require the following additions:
    ##
    # Retain generic signatures of TypeToken and its subclasses if R8 version 3.0 full-mode is enabled.
    # https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md#r8-full-mode
    -keepattributes Signature
    -keep class com.newrelic.com.google.gson.reflect.TypeToken { *; }
    -keep class * extends com.newrelic.com.google.gson.reflect.TypeToken
    # For using GSON @Expose annotation
    -keepattributes *Annotation*
  3. Clean and rebuild your project.

  4. Run your app in an emulator or device to start seeing data on your mobile app's Overview page.

  5. Optional: Use the Settings page to customize your mobile app.

If no data appears, review your logcat output for errors.

Did this doc help with your installation?

Network library support

New Relic instrumentation happens before ProGuard obfuscates your code. In order for these libraries to be properly instrumented, their classes must not be obfuscated by ProGuard.

Here are examples of rules to be applied to preserve these classes. This is not a complete list. Different rules will be needed depending on your library or version.

Library

Rules

Apache Http

-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**

OkHttp 2

-keep class com.squareup.okhttp.* { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**

OkHttp 3

-keep class okhttp3.** { *; }
-dontwarn okhttp3.**
-dontwarn okio.**

Retrofit 2

-keep class retrofit2.** { *; }
-dontwarn retrofit2.**

Configure DexGuard

DexGuard uses the same configuration options as ProGuard, and it can read any pre-existing ProGuard configuration files. DexGuard also has its own set of additional configuration options and provides sample configurations for many common app frameworks.

To add support for DexGuard:

  1. Add DexGuard to your app and set up the Gradle plugin according to the directions from DexGuard.

  2. Create a dexguard-project.txt file to hold specific DexGuard configuration options, and add:

    -dontnote com.newrelic.agent.android.NewRelic
    -dontnote com.newrelic.agent.android.harvest.crash.Crash
  3. After the DexGuard plugin has been configured, check the following.

    DexGuard 8.x: verify that your app's buildTypes configuration is similar to this:

    buildTypes {
    release {
    minifyEnabled false
    shrinkResources false
    proguardFile getDefaultDexGuardFile('dexguard-release.pro')
    proguardFile 'proguard-rules.pro'
    proguardFile 'dexguard-project.txt'
    }
    ...
  4. Clean and rebuild your project.

  5. Run your app in an emulator or device to start seeing data on your mobile app's Overview page.

  6. Optional: Use the mobile monitoring Settings page to customize your mobile app.

If no data appears, review your logcat output for errors.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.