New Relic Android agent error with gradle
Asked Answered
A

3

9

I have a project that uses the gradle build system and I'm willing to add New Relic monitoring to it.

The project (including New Relic) is working fine on Linux (Fedora 20), but won't build on my Mac development system, and gives out an error stating Agent JAR loaded but agent failed to initialize.

Here is the full log of the error:

Dev-1:test 0x4d$ ./gradlew clean
> Configuring > 1/2 projects > :appobjc[4437]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
[newrelic.error] Agent startup error
java.lang.IllegalAccessException: Can not set static final java.lang.Object field java.util.logging.Logger.treeLock to com.newrelic.agent.compile.RewriterAgent$InvocationDispatcher
    at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:73)
    at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:77)
    at sun.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl.set(UnsafeQualifiedStaticObjectFieldAccessorImpl.java:77)
    at java.lang.reflect.Field.set(Field.java:741)
    at com.newrelic.agent.compile.RewriterAgent.createInvocationDispatcher(RewriterAgent.java:772)
    at com.newrelic.agent.compile.RewriterAgent.premain(RewriterAgent.java:137)
    at com.newrelic.agent.compile.RewriterAgent.agentmain(RewriterAgent.java:102)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:382)
    at sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:407)
> Configuring > 1/2 projects > :appExcjava.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:382)
    at sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:407)
Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: Can not set static final java.lang.Object field java.util.logging.Logger.treeLock to com.newrelic.agent.compile.RewriterAgent$InvocationDispatcher
    at com.newrelic.agent.compile.RewriterAgent.premain(RewriterAgent.java:168)
    at com.newrelic.agent.compile.RewriterAgent.agentmain(RewriterAgent.java:102)
    ... 6 more
Caused by: java.lang.IllegalAccessException: Can not set static final java.lang.Object field java.util.logging.Logger.treeLock to com.newrelic.agent.compile.RewriterAgent$InvocationDispatcher
    at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:73)
    at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:77)
    at sun.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl.set(UnsafeQualifiedStaticObjectFieldAccessorImpl.java:77)
    at java.lang.reflect.Field.set(Field.java:741)
    at com.newrelic.agent.compile.RewriterAgent.createInvocationDispatcher(RewriterAgent.java:772)
    at com.newrelic.agent.compile.RewriterAgent.premain(RewriterAgent.java:137)
    ... 7 more
> Configuring > 1/2 projects > :appAgent failed to start!
[newrelic] Error encountered while loading the New Relic agent
com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
    at sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:121)
    at com.newrelic.agent.android.NewRelicGradlePlugin.apply(NewRelicGradlePlugin.java:47)
    at com.newrelic.agent.android.NewRelicGradlePlugin.apply(NewRelicGradlePlugin.java:15)
    at org.gradle.api.internal.plugins.DefaultPluginContainer.providePlugin(DefaultPluginContainer.java:104)
    at org.gradle.api.internal.plugins.DefaultPluginContainer.addPluginInternal(DefaultPluginContainer.java:68)
    at org.gradle.api.internal.plugins.DefaultPluginContainer.apply(DefaultPluginContainer.java:34)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:101)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:32)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:72)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:114)
    at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:39)
    at org.gradle.api.Project$apply.call(Unknown Source)
    at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:34)
    at org.gradle.api.Script$apply.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at build_hf6jnn002tc8mnuv025i0lb49.run(/Users/0x4d/Desktop/test/app/build.gradle:15)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:156)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:507)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:82)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:31)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:46)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.Main.main(Main.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/0x4d/Desktop/test/app/build.gradle' line: 15

* What went wrong:
A problem occurred evaluating project ':app'.
> com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 14.094 secs

I have also tested with a freshly generated, bare-bones project, but it fails with the exact same error.

I use the JDK 1.7u55 version, if that matters.

Thanks

Ahmadahmar answered 23/4, 2014 at 5:9 Comment(3)
Having this same issue. Is there a workaround yet? Using Travis.Garibaldi
@loeachg: Not yet I suppose.Ahmadahmar
Switching from OpenJDK to Oracle JDK solves the problem for me. Hope it also work for your case.Tersanctus
W
6

Unfortunately u55 introduced a change that breaks the New Relic agent. For now, if possible, use an older version of Java to work around this issue while building. This shouldn't affect the resulting APK. New Relic is aware of this issue and is working to fix it as fast as possible.

Wines answered 23/4, 2014 at 21:10 Comment(1)
com.newrelic.agent.android:agent-gradle-plugin:3.372.0 fixed this issue for mePersephone
G
4

I emailed New Relic support, and I got the following response:

Hello,

Thanks for writing into New Relic support.

A new version of the New Relic for Mobile Apps Android SDK is in beta and includes a fix for compatibility with JDK v7u55 and JDK v8

It is available here: https://gist.github.com/asm/bed819fb32253e4cb072.

We're waiting to release this agent until we hear from users like you that the SDK is running smoothly and instrumentation is now working correctly.

Please let us know if you have any trouble installing this SDK.

I'm going to leave this ticket open so that you can send us an update. Our automatic system will ping you to see how you're doing in a few days and then try to close the ticket a few days after that. If it does, don't worry, write back any time and we'll get right to helping you.

Garibaldi answered 7/5, 2014 at 17:33 Comment(1)
Unfortunately it seems that they don't understand the basic concepts of bug fixing and releasing updates. This is an issue that is keeping a lot of users, including me and you, from running their agents on our software and it's a major issue that needs to be handled quickly. They are fixing this issue on a new version they are not even sure when will be released. Presuming that this is not a fix that will cause a lot of new bugs, they should have pushed it to their tested old version code and release it, instead of making us wait because it is stuck with some new features they haven't tested.Ahmadahmar
J
1

There's a new version of new relic client available. It resolves issues that V3.361.0 had around newer JDKs and proguard. Here's what you should use to resolve the JDK problem.

classpath 'com.newrelic.agent.android:agent-gradle-plugin:3.378.0'

Paste this into your build.gradle where you have listed your dependencies. Let me know if it doesn't work.

Jareb answered 16/5, 2014 at 23:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.