Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_773e439/Offline;

I have an android application which depends on some android libraries I have built on my own. If I build the application with the library dependencies specified in the build.gradle then I get the following exception.

-6694/com.mycompany.myproject D/AndroidRuntime: Shutting down VM
05-10 18:47:55.986 6694-6694/com.mycompany.myproject E/AndroidRuntime: FATAL EXCEPTION: main
                                                                        Process: com.mycompany.myproject, PID: 6694
                                                                        java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_773e439/Offline;
                                                                            at com.mycompany.ui.components.ListArrayAdapter.$jacocoInit(ListArrayAdapter.java)
                                                                            at com.mycompany.ui.components.ListArrayAdapter.<init>(ListArrayAdapter.java)
                                                                            at com.mycompany.myproject.NationalityFragment.onCreateView(NationalityFragment.java:47)
                                                                            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
                                                                            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
                                                                            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
                                                                            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
                                                                            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
                                                                            at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
                                                                            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602)
                                                                            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
                                                                            at android.app.Activity.performStart(Activity.java:5953)
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
                                                                            at android.app.ActivityThread.access$800(ActivityThread.java:144)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:135)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5221)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at java.lang.reflect.Method.invoke(Method.java:372)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

If I remove the dependencies and instead copy the concerned classes from the libraries and run the application, it runs perfectly fine. Also I have other dependencies like junit and app-compat and those don't seem to cause this issue. Any ideas what might be causing this issue?

  • I have tried specifying the jacoco plugin to the following version and it still doesn't seem to work.
  • I have tried removing jacoco dependencies from the libraries : no effect.

My main build.gradle looks like this :

    task wrapper(type: Wrapper) {
    gradleVersion = '2.13'
}

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
    }
}

subprojects {
    project.ext.set('compileSdkVersion', 23)
    project.ext.set('buildToolsVersion', '23.0.3')

    project.ext.set('minSdkVersion', 19)
    project.ext.set('targetSdkVersion', 23)
    project.ext.set('versionCode', 1)
    project.ext.set('versionName', '1.0-SNAPSHOT')

    project.ext.set('javaVersion', JavaVersion.VERSION_1_7)

    group 'com.mycompany.myproject'
    version = project.ext.get('versionName')

    repositories {
        mavenLocal()
        mavenCentral()
    }
}
like image 330
LeoNeo Avatar asked May 11 '16 03:05

LeoNeo


3 Answers

I got this error after updating Android Studio. I found out that switching off Instant Run in Settings fixed it.

like image 171
Topo Avatar answered Nov 15 '22 05:11

Topo


According to here, you'll need to jacocoagent.jar put on the classpath. In other words, you'll need to compile the same version of jacocoagent.jar in gradle.

First check the version code here(In your situation is version0.7.4.201502262128) and then download jars from here.

Put jacocoagent.jar in libs folder then add compile fileTree(dir: 'libs', include: ['jacocoagent.jar']) in your app's build.gradle.

like image 20
bjiang Avatar answered Nov 15 '22 03:11

bjiang


bijang is correct. You need to add the jacocoagent.jar. Rather than including the jar directly, pull it down from maven. The version of the jacocoagent has to match the version of the jacocoplugin since the Offline.class package has a commmit hash. Here are my dependencies:

compile 'org.jacoco:jacoco-maven-plugin:0.7.9'

compile 'org.jacoco:org.jacoco.agent:0.7.9:runtime'

like image 44
Ryan Newsom Avatar answered Nov 15 '22 04:11

Ryan Newsom