1

My Compose unit tests fail if I have minify enabled on my app.

java.lang.NoSuchMethodError: No interface method complete()Z in class Lkotlinx/coroutines/CompletableJob; or its super classes (declaration of 'kotlinx.coroutines.CompletableJob' appears in /data/app/com.clover.engine-7ap2fJvfCgX89H0L0ytLZg==/base.apk!classes3.dex)
at androidx.compose.ui.test.junit4.IdlingResourceRegistry.<init>(IdlingResourceRegistry.jvm.kt:46)
at androidx.compose.ui.test.junit4.IdlingResourceRegistry.<init>(IdlingResourceRegistry.jvm.kt:37)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.<init>(ComposeUiTest.android.kt:220)
...
at androidx.compose.ui.test.junit4.AndroidComposeTestRule_androidKt.createComposeRule(AndroidComposeTestRule.android.kt:212)
at com.mytest.MyTest.<init>(...)

I've tried adding proguard rules for the missing symbols, which gets past the immediate problem, but it seems to be a never ending list which makes me think that isn't the right direction.

Minify is enabled like this:

  buildTypes.all {
    minifyEnabled true
    // ...
  }

I have other androidTest tests that run fine, and the Compose-based activity in the app works fine when minify is enabled.

My Compose-related dependencies are like this:

  def composeBom = platform('androidx.compose:compose-bom:2023.1.00')
  implementation composeBom
  androidTestImplementation composeBom
  implementation 'androidx.compose.material3:material3'
  implementation 'androidx.compose.ui:ui-tooling-preview'
  debugImplementation 'androidx.compose.ui:ui-tooling'
  implementation 'androidx.compose.runtime:runtime-livedata'

  implementation 'androidx.activity:activity-compose:1.6.1'
  implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1'

  androidTestImplementation 'androidx.compose.ui:ui-test-junit4'

EDIT: I was looking into the "Now in Android" Compose best-practice app. Not 100% clear but it seems like it also does not enabled minify for unit testing: https://github.com/android/nowinandroid/blob/0d23e64848adea66ec878293a7c1bd18d128689a/app/build.gradle.kts#L46

Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134

0 Answers0