Search code examples
androidkotlinjunitkotlin-coroutines

Why am I getting a No interface method complete in class CompletableJob Exception


I'm getting this error when running a unit test on a composable:

No interface method complete()Z in class Lkotlinx/coroutines/CompletableJob; or its super classes (declaration of 'kotlinx.coroutines.CompletableJob' appears in /data/app/~~fIPCXqaEQds-4dojIoIsag==4dojIoIsag==/com.fluffypants.rockhard==/base.apk!classes2.dex

It's throwing it on this line in IdlingResourceRegistry.jvm.kt:

private var pollJob: Job = Job().also { it.complete() } 

This is the upstream code that I'm running that ultimately leads to the line that errors. It breaks on createComposeRule():

@RunWith(AndroidJUnit4:class
class MyInstrumentedTest{
    @get:Rule
    val composeTestRule = createComposeRule()

@OptIn(ExperimentalCoroutinesApi::class)
@Test
    fun myTest() = runTest {
        //errors no matter what I put in here
    }
}

I have these test libraries configured in my build.gradle

testImplementation "junit:junit:4.13.2"
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1"
androidTestImplementation "androidx.compose.ui:ui-test-junit4-android:1.6.3"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.6.3"

I'm using the most up to date versions of all of the test libraries. What am I doing wrong?


Solution

  • The cause of the issue was that 'minifyEnabled' was set to 'true' in my buildType variant configuration.

    So for example, my buildType was configured like this:

    android{
        buildTypes{
            myBuildTypeName{
                shrinkResources false
                debuggable true
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                signingConfig signingConfigs.lle
            }
        }
    }
    

    Just changing the value for 'minifyEnabled' to 'false' resolved the issue for me.