---
title: Configure ProGuard or DexGuard for Android apps
source: https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/install-configure/configure-proguard-or-dexguard-android-apps
---

> #### ⚠️ IMPORTANT
>
> New Relic automatically adds the proguard rules for agent version 7.6.8 and later.

Follow these instructions to support ProGuard or DexGuard with the Android agent. Check [our Android compatibility and requirements](https://docs.newrelic.com/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](https://docs.newrelic.com/docs/mobile-apps/android-1-upgrade) to the latest version with ProGuard or DexGuard.

## Configure ProGuard [#proguard]

To add support for [ProGuard](https://www.guardsquare.com/manual/configuration/usage):

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-library) (`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](https://docs.newrelic.com/docs/mobile-apps/mobile-apps-dashboard).
5.  Optional: Use the mobile monitoring **Settings** page to [customize your mobile app](https://docs.newrelic.com/docs/mobile-apps/customizing-your-mobile-app-settings).

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

## Network library support [#proguard-library]

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]

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:

    ```gradle
    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](https://docs.newrelic.com/docs/mobile-apps/mobile-apps-dashboard).
6.  Optional: Use the mobile monitoring **Settings** page to [customize your mobile app](https://docs.newrelic.com/docs/mobile-apps/customizing-your-mobile-app-settings).

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