How to disable the Android gradle plugin?

I could not find any documentation on what/where to disable the Android gradle New Relic plugin. How should it be disabled?

For example, the New Relic plugin does a lot of work to process and modify the dex files and when the plugin isn’t being used anyway during debug builds, running all that code and then never enabling it in code is a waste.

It would be a lot easier to be able to set a ‘disable’ flag somewhere in the android section of the build.gradle so it can be turned on and off based on the build mode (debug/release) and/or Android ‘flavor’.

For example, if you have a ‘regularRelease’ flavor, and a ‘fastDebug’ to compile in with a higher minSdkVersion 21 so the Android gradle build is faster (an Android plugin quirk—don’t worry about why it is for this discussion); if we could disable the New Relic via a gradle configuration value in the ‘fastDebug’ flavor it would also help speed up our development build cycle.

I’m hoping for something like:


android {
    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
            newRelicEnabled false
        release {
            minifyEnabled true
            shrinkResources true
            newRelicEnabled true // default should be true

From what I can tell, this isn’t in any New Relic Android SDK version. However, right now, I’m using:

  • gradle v2.1.2
  • New Relic Android SDK v5.6.1
1 Like

To be clear, this issue is to enable/disable at build time, not run time.

I am aware it can be enabled/disabled at run time via code by calling (or not) NewRelic.withApplicationToken(...).start(...). But that doesn’t remove the build time cost of the New Relic plugin, only the app startup cost.

Hey @jon.adams if you’re wanting to completely remove the agent from the build process you can remove or comment out apply plugin: 'newrelic' from your gradle script.

No. I want to disable it for some configurations, not all.

Hi @jon.adams, I think this other post is what you’re looking for.

That thread is close. But from what I understand in reading that, that script will stop New Relic from being compiled, but won’t stop it from the dex processing. The tracing feature that needs to process the dex files is the biggest time cost of this plugin (I think, from looking at the output timing).

The goal is to have something simple in the build.gradle so that the plugin will not run the expensive New Relic processing during development build iterations during development builds since it is usually unnecessary for dev builds to have the instrumentation and reporting.

Perhaps another option, instead of a build.gradle flag to disable the plugin, as per my suggestion in the original post above, you could do like LeakCanary that provides two libraries that can be turned on/off by the usual dependency debugCompile, releaseCompile, etc.: A release and a no-op library. That way the app code can still reference those APIs, but when compiling, dexing, and running the app, the library will just return nearly empty bodies of no-ops and empty results instead of performing the real costly and permanent operations.
(I don’t know if this system will work for plugins that need to run different code for the same task based on the dependency compile directive.)

@jon.adams looks like I had an extra character in the URL. I’ve updated the link to work properly now. This will prevent the New Relic agent from being part of the dexing process.

I’ve updated the link to work properly now. This will prevent the New Relic agent from being part of the dexing process.

I don’t understand. What link? The one in your previous post linking to the Disable New Relic for Android debug builds thread? That link was pointing to the thread before, so if that’s the link you are talking about, I’m not sure what changed.

Therefore my issue as detailed more in my last post still applies.

Hey @jon.adams - the script in that post will not include New Relic’s additional overhead to the dex process. In fact, checking logs you can see that the instrumentation is added, and then disabled just before the transform task is ran. The trick is making sure to disable instrumentation after the gradle plugin has added the New Relic instrumentation task, but before dexing. Originally I had hooked into the compileDebug set of tasks, but found that was less consistent than using transformClassesWithDexFor. Both of those tasks can be set to depend on a task which disables New Relic instrumentation in a debug build.

Okay. I will try that post with the change of using transformClassesWithDexFor and post back here if it accomplishes what I’m hoping.

Even still, it would be nice if there was a quick, easy flag to accomplish this instead of the detailed script in the other thread—an easy flag like as requested in the original post of this thread.

FOLLOWUP: The referenced thread does indeed accomplish the optimization I was hoping for. Though, for what it’s worth, adding a simpler flag instead of the complicated gradle script hack would still be nice.


Glad you ended up with the optimization you were hoping for after all, @jon.adams.

Adding a simple flag is a nice idea and I bet the Mobile Product Manager would think so, too! I will go ahead and create a feature request for you about that, including your use case. Thanks for letting us know how you see the product improving! :thumbsup:

I have the same issue. In our project we don’t want to use newrelic gradle plugin in the debug because it doubles build time. We also tried solution from the mentioned discussion but it doesn’t work constantly.
Do you have solution for this problem?

@andrii.boiko What task are you using when building for debug? It’s possible that your task tree is different and the script isn’t seeing the specific tasks run that would disable the agent.

The example gradle script assumes transformClassesWithDexFor is invoked but it’s possible that’s not the case.

i have multi-module project. In the main module I applies newrelic plugin.
Steps to reproduce:

  1. I do gradle clean assembleDebug for the version without disabling newrelictask
  2. checkout for the branch with disabled newrelictask
  3. I do gradle clean assembleDebug for the version with disabled newrelictask
    this is my log

the interesting part in the log that I see the line thats say that task was skipped

and i’m using multidex

Hm, that’s weird that the task is being skipped but instrumentation is still occurring.

I’m curious if the build config for the other modules also include New Relic? We may end up needing to move this into a ticket to get a better repro case and take a look at the build.gradles from the other modules.

Ok. How we can do this? Should I create a ticket?

I’ve gone ahead and created a ticket for you where we can collect some more information about your project.

Whatever the findings/solution I’ll be sure to come back and update this thread.

1 Like