Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Multiple flavors

android
gradle
rfb

#1

Hi. I have a project which has multiple versions, each one in a specific flavor.

We consider each flavor as a unique app, and we want to do it as well on new relic. The problem is that I haven’t found a way to set flavor specific tokens (since I have to create a newrelic.properties file containing the token in the project’s root).

Is there a way to configure new relic with multiple tokens depending on the flavor?


#2

The newrelic.properties token value is specifically for crash reporting, and not the general performance monitoring data(Http requests, Interactions, Geo, etc).

Right now, there’s not a good way to set this token value for a specific productFlavor as defined in the build.gradle. I’ll make sure this gets added to our feature requests for the Android agent, because it really is a great suggestion, and an area we could improve on.


#3

We are currently facing the same issue. A correct way is to use a newrelic.xml file in res folder. That way each flavour can override this xml file


#4

We’ll certainly look into the options we have, and a newrelic.xml for overriding certainly seems like a good option.

Thanks


#5

Another option would be to create a gradle task to create the properties file every time a build is being made. But seems a little like an overkill. But a good workaround in the meantime though.


#6

Thanks for that workaround, @nicolas_hormazabal!


#7

Did something change in flavors support? Or we should stay with gradle ask for now?


#8

Hi @mirek,
The process hasn’t changed. If gradle ask is working for you it would be best to stick with it for now


#9

Would be great if someone can provide a working code solution to make this work in a clean way.
I am especially talking about the newrelic.properties file, since the token for newrelic initialization is pretty straight forward.


#10

@mit Just to clarify - you are using separate app tokens for each of the flavors in your app? If you use the same app token for each flavor of your app, there’s no need for any kind of custom logic.


#11

I had to revive the topic since I’m having the same issue … Any updates on that?

I’m thinking to create a createPropertiesFile() task on Gradle’s build and make the build tasks depends on it … That way the API token will be part of the script and I don’t know if it’s the best solution …

If anyone have a more elegant way please share.

PS: I have two apps for my app created on the dashboard (debug and production), if also there’s a better way to do it please advice.

Thanks!


#12

Hi @fduarte – There has been no change to our functionality yet, but we have recorded your feedback as a feature request.


#13

Seems like the only workaround is to create gradle task to dynamically change newrelic.properties.
It’s my regret that NR does not support multiple flavor yet.


#14

Hey @pingchenok - :frowning: I went ahead and submitted a feature request to support multiple flavors :slight_smile:


#15

Well if anyone wants a workaround for now here it goes:

// Create New Relic properties file according to flavor
File newRelicProperties = new File("${project.projectDir.absolutePath}/newrelic.properties")
newRelicProperties.createNewFile()

android.applicationVariants.all { variant ->
    variant.productFlavors.each { flavor ->
        def variantSuffix = variant.name.capitalize()
        def generateResourcesTask = project.tasks.getByName("compile${variantSuffix}Sources")
        def generatePropertiesTask = task("newRelicGenerateProperties${variantSuffix}") << {
            Properties properties = new Properties()
            properties.load(newRelicProperties.newDataInputStream())
            properties.setProperty("com.newrelic.application_token", flavor.ext.newRelicAppToken)
            properties.store(newRelicProperties.newWriter(), null)
        }
        generateResourcesTask.dependsOn generatePropertiesTask
    }
}

the ext.newRelicAppToken should be added to each flavor like this:

productFlavors {
    dev {
        ext.newRelicAppToken = "<dev-key>"
    }

    qa {
        ext.newRelicAppToken = "<qa-key>"
    }
...

Best,


Crash stack trace shows '-1' for app's line numbers, obfuscated method names
How to set up newRelic.properties file for project with multiple build variants?
12/21/2015 Post of the WeeK: Multiple Flavors, Synthetics Scripts, and .NET DLLs!
#16

@fduarte This is great. Thank you for sharing your work!


#17

Thanks for sharing the code snippet. (y)


#18

Any updates on this, should we use this workaround or ?


#19

Will this ever be implemented by New Relic?