vanniktech/gradle-android-junit-jacoco-plugin

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

root-ansh-ct opened this issue · 0 comments

recently I added this plugin in one of my sample projects. the coverage task works perfectly. however it has impacted the assembleRelease / assembleDebug task in a manner that the aar that is generated via this plugin is giving this runtime error.

Steps to reproduce:

  1. create a multi-modular project
  2. add the plugin in root build.gradle like this:
buildscript {

    repositories {
        google()// Google's Maven repository
        mavenCentral()
        gradlePluginPortal()
        maven {
            url 'https://developer.huawei.com/repo/' }

    }
    dependencies {
        ...
        classpath("com.vanniktech:gradle-android-junit-jacoco-plugin:0.16.0")

    }
}
apply plugin: "com.vanniktech.android.junit.jacoco"

junitJacoco {
    jacocoVersion = '0.8.7' // type String
}
  1. run gradle assembleRelease this will generate an aar for your module at modulename/build/outputs/aar/modulename.aar
  2. create another android project. in its app/libs folder add the module (modulename.aar)
  3. in its app/build.gradle , add :
dependencies {
    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
    implementation files('libs/modulename.aar')   
     ....
}
  1. use the module's functions or something inside your app
  2. run app
  • expected: app will run successfully and call module's functions
  • actual: app builds, launches and crashes. error log :
2022-06-10 00:02:01.728 work.curioustools.myword E/AndroidRuntime: FATAL EXCEPTION: main
    Process: work.curioustools.myword, PID: 6741
    java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_3570298/Offline;
        at com.clevertap.android.sdk.CleverTapAPI$LogLevel.$jacocoInit(Unknown Source:13)
        at com.clevertap.android.sdk.CleverTapAPI$LogLevel.<clinit>(Unknown Source:0)
        at work.curioustools.myword.MyWordApp.ctInitLogging(MyWordApp.kt:68)
        at work.curioustools.myword.MyWordApp.onCreate(MyWordApp.kt:39)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871)
        at android.app.ActivityThread.access$1100(ActivityThread.java:199)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_3570298.Offline" on path: DexPathList[[zip file "/data/app/work.curioustools.myword-qnnHMkyzWt49lic4DRwC_Q==/base.apk"],nativeLibraryDirectories=[/data/app/work.curioustools.myword-qnnHMkyzWt49lic4DRwC_Q==/lib/arm64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)

note: this might be related to some android studio's AGP version , as mentioned here : https://issuetracker.google.com/issues/222338458#comment6

I am not sure if i understand it fully, but i really want to apply a quick resolution to this issue. i am using AGP version 4.2.1 and gradle version 7.0.2 .