Search code examples
androidandroid-studiogradlenewrelic

New Relic in Android Studio - newrelic.properties - variants


I'm integrating New Relic in my project (with Android Studio & Gradle) which has 2 variants. Each variant has its own generated token, which I store in each variant's string.xml file.

In the New Relic documentation, it states the following:

In your project’s root directory (projectname/app), add a newrelic.properties file with the following line:

com.newrelic.application_token=generated_token

The problem is, if I do this, how can make the correct token appear for the correct variant? If this file must appear in the project root, I can't create one per variant, and so I'm forced to use the same token for both variants, which doesn't work for my requirements.

Any insight would be appreciated.


Solution

  • Okay, so after contacting the support team at New Relic, there is apparently no direct solution for this as of today, although they said they've opened a feature request, and so this problem might be solved soon.

    From what I managed to understand, the reason this file is needed is so that the New Relic system can display an un-obfuscated error log when an exception occurs on a production version which has been obfuscated with ProGuard.

    The New Relic system, with the help of this file, will upload the ProGuard mapping.txt file to the New Relic servers and associate it with your app according to the specified token. With this, New Relic can un-obfuscate stack traces and display a descriptive stack trace with actual class & method names, rather a, b, c, etc.

    As a workaround, I was told that I can forego this file all together, if I upload the mapping file manually.

    The mapping file can be found at:

    build/outputs/proguard/release/mapping.txt  
    

    In order to manually upload the file, perform the following via command line:

    curl -v -F proguard=@"<path_to_mapping.txt>" -H "X-APP-LICENSE-KEY:<APPLICATION_TOKEN>" https://mobile-symbol-upload.newrelic.com/symbol
    

    This must be done for each variant which is being obfuscated with ProGuard (classically, release builds).

    Source

    Hope this helps someone else.