Hey folks, I'm building a Compose Multiplatform ap...
# compose
i
Hey folks, I'm building a Compose Multiplatform app targeting Android and Desktop. I've setup Compose Preview Screenshot Testing and it works perfectly in cases where compose multiplatform resources aren't present. However, it fails with this error when trying to record screenshots for a composable that uses a drawable resource (e.g.
Res.drawable.google_logo
)
Copy code
java.lang.NoSuchMethodError: 'void org.jetbrains.compose.resources.ResourceItem.<init>(java.util.Set, java.lang.String, long, long)'
        at pocketvibe.composeapp.generated.resources.Drawable0_commonMainKt.init_google_logo(Drawable0.commonMain.kt:63)
        at pocketvibe.composeapp.generated.resources.Drawable0_commonMainKt.access$init_google_logo(Drawable0.commonMain.kt:1)
        at pocketvibe.composeapp.generated.resources.CommonMainDrawable0.google_logo_delegate$lambda$2(Drawable0.commonMain.kt:19)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at pocketvibe.composeapp.generated.resources.CommonMainDrawable0.getGoogle_logo(Drawable0.commonMain.kt:19)
        at pocketvibe.composeapp.generated.resources.Drawable0_commonMainKt.getGoogle_logo(Drawable0.commonMain.kt:58)
Any idea how to fix it? I am considering a workaround where for screenshots we'll use a mocked image instead of the real resource which isn't ideal 😬
I made this workaround which works but it's definitely not nice and reduces the value of our screenshot tests:
Copy code
@Composable
private fun ProviderLogo(
  provider: ModelProvider,
  modifier: Modifier = Modifier,
) {
  val size = when (provider) {
    ModelProvider.OpenAI -> 40.dp
    else -> 32.dp
  }
  if (LocalInspectionMode.current) {
    // Preview mode
    Spacer(
      Modifier.size(size)
        .background(VibeTheme.colors.primary)
    )
  } else {
    // Real
    val logo = provider.logo
    Icon(
      modifier = modifier.size(
        size
      ),
      painter = painterResource(logo.resource.value),
      contentDescription = null,
      tint = if (MaterialTheme.colors.isLight) logo.tintLight else logo.tintDark,
    )
  }
}
t
In theory the ressources in the common code should be mapped to native android system automatically. But did not tested it with screenshot testing. But previews are definitly working
i
Screenshot tests (i.e. previews) that live in the
screenshotTest
source set aren't working for me. I'll look for some better workaround but for now I'm just wrapping stuff with
LocalInspectionMode.current
and not using real resources