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:
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
andEnclosingMethod.
- To support New Relic instrumentation, add
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*Clean and rebuild your project.
Run your app in an emulator or device to start seeing data on your mobile app's Overview page.
Optional: Use the Settings page to customize your mobile app.
If no data appears, review your logcat
output for errors.
Este documento ajudou você na instalação?
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 |
|
OkHttp 2 |
|
OkHttp 3 |
|
Retrofit 2 |
|
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:
Add DexGuard to your app and set up the Gradle plugin according to the directions from DexGuard.
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.CrashAfter 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 falseshrinkResources falseproguardFile getDefaultDexGuardFile('dexguard-release.pro')proguardFile 'proguard-rules.pro'proguardFile 'dexguard-project.txt'}...Clean and rebuild your project.
Run your app in an emulator or device to start seeing data on your mobile app's Overview page.
Optional: Use the mobile monitoring Settings page to customize your mobile app.
If no data appears, review your logcat
output for errors.