Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Relic not working (gradle + android studio)

I am having problem enabling newrelic monitoring in android app while using gradle and android studio.

I followed exactly instructions adding newrelic to build.gradle, adding code to activity and requesting permissions in manifest:

buildscript {
  repositories {
    mavenCentral()
  }

  dependencies {
    classpath 'com.newrelic.agent.android:agent-gradle-plugin:3.239.0'
  }
}

repositories {
  mavenCentral()
}

apply plugin: 'android'
apply plugin: 'newrelic'

dependencies {
  compile 'com.newrelic.agent.android:android-agent:3.239.0'
}

But I am not able to build the app. The result is:

java.lang.ClassNotFoundException: com.newrelic.agent.compile.RewriterAgent
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:280)
    at sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:348)
[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:103)
    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)

Am I missing something? In Eclipse everything worked fine.

like image 288
Yozooo Avatar asked Nov 01 '22 08:11

Yozooo


2 Answers

I got the same error when tried to build my project with JDK8. It was solved when I switched to JDK7. New Relic support suspect this is an issue with Java 8.

like image 170
slaven Avatar answered Nov 09 '22 13:11

slaven


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.

like image 36
iTapAndroid Avatar answered Nov 09 '22 13:11

iTapAndroid