New Relic Class Not Found ... I don't even use new relic
Asked Answered
F

4

21

I don't even use new relic and I'm getting errors for them. It just happened all of the sudden.

I'm using the latest Android Studio build (0.61). Even my master branch has the same error. There are other projects on my machine that use new relic, but not this one. This project does not use new relic in any way, not so much as a wayward gradle dependency.

I've tried clearing out my gradle cache and re-downloading all the third party libs, didn't work.

StackTrace:

06-15 01:05:54.872  20117-20117/com.waxwings.happyhour.staging D/HappyHourApplication﹕ CREATE TABLE job_holder (_id integer  primary key autoincrement , `priority` integer, `group_id` text, `run_count` integer, `base_job` byte, `created_ns` long, `delay_until_ns` long, `running_session_id` long, `requires_network` integer );
    06-15 01:05:54.874  20117-20117/com.waxwings.happyhour.staging D/AndroidRuntime﹕ Shutting down VM
    06-15 01:05:54.877  20117-20117/com.waxwings.happyhour.staging E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.waxwings.happyhour.staging, PID: 20117
        java.lang.NoClassDefFoundError: Failed resolution of: Lcom/newrelic/agent/android/instrumentation/SQLiteInstrumentation;
                at com.path.android.jobqueue.persistentQueue.sqlite.DbOpenHelper.onCreate(DbOpenHelper.java:42)
                at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
                at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
                at com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.<init>(SqliteJobQueue.java:42)
                at com.path.android.jobqueue.JobManager$DefaultQueueFactory.createPersistentQueue(JobManager.java:594)
                at com.path.android.jobqueue.JobManager.<init>(JobManager.java:77)
                at com.waxwings.happyhour.HappyHourApplication.configureJobManager(HappyHourApplication.java:84)
                at com.waxwings.happyhour.HappyHourApplication.onCreate(HappyHourApplication.java:38)
                at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1030)
                at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4425)
                at android.app.ActivityThread.access$1500(ActivityThread.java:139)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:136)
                at android.app.ActivityThread.main(ActivityThread.java:5102)
                at java.lang.reflect.Method.invoke(Native Method)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
         Caused by: java.lang.ClassNotFoundException: Didn't find class "com.newrelic.agent.android.instrumentation.SQLiteInstrumentation" on path: DexPathList[[zip file "/data/app/com.waxwings.happyhour.staging-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.waxwings.happyhour.staging-1, /vendor/lib, /system/lib]]
                at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                at com.path.android.jobqueue.persistentQueue.sqlite.DbOpenHelper.onCreate(DbOpenHelper.java:42)
                at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
                at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
                at com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.<init>(SqliteJobQueue.java:42)
                at com.path.android.jobqueue.JobManager$DefaultQueueFactory.createPersistentQueue(JobManager.java:594)
                at com.path.android.jobqueue.JobManager.<init>(JobManager.java:77)
                at com.waxwings.happyhour.HappyHourApplication.configureJobManager(HappyHourApplication.java:84)
                at com.waxwings.happyhour.HappyHourApplication.onCreate(HappyHourApplication.java:38)
                at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1030)
                at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4425)
                at android.app.ActivityThread.access$1500(ActivityThread.java:139)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:136)
                at android.app.ActivityThread.main(ActivityThread.java:5102)
                at java.lang.reflect.Method.invoke(Native Method)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        Suppressed: java.lang.ClassNotFoundException: com.newrelic.agent.android.instrumentation.SQLiteInstrumentation
                at java.lang.Class.classForName(Native Method)
                at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                ... 19 more
         Caused by: java.lang.NoClassDefFoundError: Class "Lcom/newrelic/agent/android/instrumentation/SQLiteInstrumentation;" not found
                ... 23 more

build.gradle for module:

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

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"

    }

    buildTypes {
        release {
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }

    }

    useOldManifestMerger true

    productFlavors {

        staging {
            applicationId "com.waxwings.happyhour.staging"
        }

        production {
            applicationId "com.waxwings.happyhour"
        }
    }

    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }


}

dependencies {
    compile 'com.path:android-priority-jobqueue:1.1.2'
    compile "com.android.support:support-v4:19.1.0"
    compile 'com.google.android.gms:play-services:4.4.52'

//    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/wearable-preview-support.jar')
    compile group: 'com.squareup.okhttp', name: 'okhttp', version: '1.5.3'
    compile group: 'com.squareup.picasso', name: 'picasso', version: '2.2.0'
    compile 'com.jakewharton:butterknife:5.0.1'
    compile 'com.squareup.retrofit:retrofit:1.5.1'
    compile 'com.squareup:otto:+'
    compile 'com.squareup.phrase:phrase:+'
    compile 'com.newrelic.agent.android:android-agent:3.402.0'

    // Mockito dependencies
    androidTestCompile "org.mockito:mockito-core:1.9.5"
    androidTestCompile files(
            'libs/dexmaker-1.0.jar',
            'libs/dexmaker-mockito-1.0.jar')

    androidTestCompile ('com.squareup:fest-android:1.0.8'){
        exclude group:'com.android.support', module: 'support-v4'
    }
    androidTestCompile 'com.squareup.spoon:spoon-client:1.1.1'

    androidTestCompile('junit:junit:4.11') {
        exclude module: 'hamcrest-core'
    }

    androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
        exclude group: 'org.hamcrest:hamcrest-core:1.1'
        exclude group: 'org.hamcrest:hamcrest-library:1.1'
        exclude group: 'org.hamcrest', module: 'hamcrest-integration'
        exclude group:'com.android.support', module: 'support-v4'

    }

    androidTestCompile ('com.jakewharton.espresso:espresso-support-v4:1.1-r3'){
        exclude group:'com.android.support', module: 'support-v4'
    }

}

build.gradle for project:

buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://oss.sonatype.org/content/repositories/comnewrelic-1153'
        }
        maven {
            url 'https://oss.sonatype.org/content/repositories/comnewrelic-1154'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.11.+'
        classpath 'com.newrelic.agent.android:agent-gradle-plugin:3.402.0'

    }
}

allprojects {
    repositories {
        mavenCentral()
        maven {
            url 'https://oss.sonatype.org/content/repositories/comnewrelic-1153'
        }
    }
}

Edit

The project now imports New Relic in the build.gradle per a user suggestions. This fixed the issue but I'm still exploring why, as it doesn't seem like it should be necessary. The class throwing the error is in Path's JobQueue lib, the library hasn't been updated in 4 months, and my app has been running fine, this just started happening suddenly. The class that is erroring in the 3rd party lib doesn't even use New Relic.

Edit 2

The priority job queue lib does not use new relic. I have no clue why the stack trace says it does, seems like a red herring. I've heard the New Relic SDK modifies the Android API and gives weird errors. But again, I don't use new relic in my project. Is it possible using the NR sdk in another project somehow infected this one (maybe a bug in Android Studio)?

Edit 3

OK, the Priority Job Queue lib in the original stack trace is definitely a false flag. I went ahead and accessed my own Provider before the JobQueue had a chance to access its (knowing this would force the creation of my own DB ahead of the JobQueue lib). My logic was that if Android Sqlite was being infected by New Relic then it would cause a similar error on my own OpenHelper, it did.

06-15 15:29:39.848    1368-1368/com.waxwings.happyhour.staging W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4d81b20)
06-15 15:29:39.848    1368-1368/com.waxwings.happyhour.staging E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.waxwings.happyhour.staging, PID: 1368
    java.lang.NoClassDefFoundError: com.newrelic.agent.android.instrumentation.SQLiteInstrumentation
            at com.waxwings.happyhour.services.HHOpenHelper.onCreate(HHOpenHelper.java:56)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
            at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
            at com.waxwings.happyhour.services.HappyHourProvider.query(HappyHourProvider.java:121)
            at android.content.ContentProvider.query(ContentProvider.java:857)
            at android.content.ContentProvider$Transport.query(ContentProvider.java:200)
            at android.content.ContentResolver.query(ContentResolver.java:461)
            at android.content.ContentResolver.query(ContentResolver.java:404)
            at com.waxwings.happyhour.HappyHourApplication.onCreate(HappyHourApplication.java:39)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
            at android.app.ActivityThread.access$1500(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

Edit 4

I just ran the project on a machine that has never had a New Relic library installed in any project and it ran fine. I think this is pretty strong evidence that New Relic is doing something funny w/ their plugin/library.

Edit 5

I updated my gradle-wraper.properties file to use the rc-1 distribution and that seems to have fixed the problem. I removed the new relic dependencies from my build.gradle that one commenter suggested, and the app still runs fine.

distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-rc-1-all.zip

My guess is that the New Relic library was being cached in the 1.12-all gradle distro and this was the common link causing other projects to error. I'm still not sure what makes the New Relic library different such that gradle thinks it should include it in other projects. Given that New Relic had an almost identical issue w/ their Eclipse plugin not too long ago, I think it's reasonable to assume there's something going on w/ their Maven distribution. I have a support ticket open with them and I will continue to investigate and report back.

The odd part is if I delete all the gradle distributions/caches/etc in ~/.gradle dir and try to use the 1.12-all distro it still throws that new relic error. The only way it will work is if I use the 1.12-rc-1-all gradle distro.

Foliaceous answered 15/6, 2014 at 5:15 Comment(9)
Oh hell, when SO adds Shift+Tab to format your code to readable, I'll stop by again.Contessacontest
Look at com.path.android.jobqueue.persistentQueue.sqlite.DbOpenHelper, this class is using newRelic.Atlantic
@Atlantic , that's a third party library, JobQueue by Path. I have the version pinned via maven dependency, nothing has changed since it was working. However, I did look in the class and found nothing odd.Foliaceous
A 3rd party library can still use a 4th party library. Find and download newrelic and see if it makes it compile.Attack
@GabeSechan that did it, but I still can't figure out why? Shouldn't 3rd party libs compile w/ all the dependencies they need to run, especially something like a crash reporting lib like new relic? Also, can't figure out why my app ran fine for months and just quit today? The 3rd party app that caused it hasn't been updated in 4 months. While this did fix it, it feels wrong, like a bandaid and not a true fix.Foliaceous
No, 3rd party libraries don't compile with all of their dependencies included, or at least they don't have to. I can't tell you why it suddenly stopped working, it could be that some new code path is now being exercised that previously wasn't.Attack
Please share your build.gradle files.Kimi
@ScottBarta added, the new relic Maven repos and dependencies are per the gist found in this SO post to address a New Relic bug w/ importing their library.Foliaceous
turned out to be AS instant run for me. Turned it off and worked fine.Drury
P
31

It looks like Android Studio switched over to the gradle daemon for faster builds. Unfortunately, this caches parts of the New Relic agent and it's necessary to stop the daemon when you switch to a project without the agent (or a different version. You can accomplish this simply by running:

gradle --stop

You'll also want to clean your project to ensure the classes are rebuilt and dexed.

While this should get you up and running for now, we'll work on a fix for this issue right away and you can expect it in the next version of the agent.

Penitent answered 19/6, 2014 at 21:45 Comment(7)
Hi @asm, i've also suffering from this issue (#24933798), is there a fix already? thanks.Flawy
newrelic taints the daemon and thus it's required to stop it the hard way. I've been talking to the devs and made them aware of this and they say they are working on a fix. But as of now the problem still persists.Genevagenevan
@Penitent it really sucks, 2.5 years passed and no fix. Why I should wipe all my Gradle caches bcs of new relic.Livvy
Woah, as far as I'm aware we fixed that issue ages ago. Have you tried updating to the latest agent (in the projects that use it).Penitent
This happened for me with agent 5.12.3.Zorina
2017 Still happeningDagmardagna
Worked for me. Just had the same issue happened to me. Stuck for 2 days. I had New Relic integrated to my app then took that out, then the issue occurred. I was getting errors like this: Caused by: java.lang.NoClassDefFoundError: com.newrelic.agent.android.instrumentation.JSONObjectInstrum‌​entationCosset
R
33
./gradlew --stop
./gradlew cleanBuildCache
./gradlew clean

works for me

Refractometer answered 7/4, 2017 at 2:47 Comment(4)
This should be the accepted answer. Most people will be using Gradle via the wrapper in their project. This fixed the issue for me as well. Try this if the accepted answer did not work for you.Dagmardagna
Been struggling with this (removing newrelic from a project) it worked fine on Multidex + Proguard builds, but developer builds (API 21+) continued to blow up. Deleting the .gradle/cache, invalidating caches and restarting, nothing worked - the magic incantation above did the trick.Hijacker
Spent 3 hours Googling and trying to figure this out. This fixed the issue for me! Thanks!Biogen
this works. Update my gradle_home to gradle-3.3 and also my java_home to java-1.8 and works. (gradlew also is 3.3)Semimonthly
P
31

It looks like Android Studio switched over to the gradle daemon for faster builds. Unfortunately, this caches parts of the New Relic agent and it's necessary to stop the daemon when you switch to a project without the agent (or a different version. You can accomplish this simply by running:

gradle --stop

You'll also want to clean your project to ensure the classes are rebuilt and dexed.

While this should get you up and running for now, we'll work on a fix for this issue right away and you can expect it in the next version of the agent.

Penitent answered 19/6, 2014 at 21:45 Comment(7)
Hi @asm, i've also suffering from this issue (#24933798), is there a fix already? thanks.Flawy
newrelic taints the daemon and thus it's required to stop it the hard way. I've been talking to the devs and made them aware of this and they say they are working on a fix. But as of now the problem still persists.Genevagenevan
@Penitent it really sucks, 2.5 years passed and no fix. Why I should wipe all my Gradle caches bcs of new relic.Livvy
Woah, as far as I'm aware we fixed that issue ages ago. Have you tried updating to the latest agent (in the projects that use it).Penitent
This happened for me with agent 5.12.3.Zorina
2017 Still happeningDagmardagna
Worked for me. Just had the same issue happened to me. Stuck for 2 days. I had New Relic integrated to my app then took that out, then the issue occurred. I was getting errors like this: Caused by: java.lang.NoClassDefFoundError: com.newrelic.agent.android.instrumentation.JSONObjectInstrum‌​entationCosset
S
5

I tried gradle --stop but it didn't work.

Delete .gradle directory and sync project again, it worked.

Spaceship answered 29/5, 2015 at 23:53 Comment(1)
Same for me. Pretty rough considering this issue is from 2.5 years ago and they were going to "work on a fix for this right away" then...Lampley
N
1

I faced the weird issue of NoClassDefFoundError in kitkat. but it was working fine on lollipop.

I tried all the above fix but didn't work.

Finally I come to know that its because of multidex error. I crossed 65k method. So,I followed this tutorial from android developer site. and worked like charm

Naldo answered 8/1, 2016 at 13:59 Comment(1)
This may theoretically answer the question, but it would be best to include the essential parts of the answer here for future users, and provide the link for reference. Link-dominated answers can become invalid through link rot.Photoperiod

© 2022 - 2024 — McMap. All rights reserved.