cashapp / paparazzi

Render your Android screens without a physical device or emulator
https://cashapp.github.io/paparazzi/
Apache License 2.0
2.23k stars 211 forks source link

Crash when using M3 Dynamic colors #1359

Closed sergio-sastre closed 1 month ago

sergio-sastre commented 3 months ago

Description After migrating from M2 to M3 and using dynamic colors, the task to execute screenshot tests fails as follows:

android.content.res.Resources$NotFoundException: Could not resolve resource value: 0x1060060.
    at app//android.content.res.Resources_Delegate.throwException(Resources_Delegate.java:1159)
    at app//android.content.res.Resources_Delegate.throwException(Resources_Delegate.java:1135)
    at app//android.content.res.Resources_Delegate.throwException(Resources_Delegate.java:1139)
    at app//android.content.res.Resources_Delegate.getColorStateList(Resources_Delegate.java:268)
    at app//android.content.res.Resources_Delegate.getColor(Resources_Delegate.java:246)
    at app//android.content.res.Resources.getColor(Resources.java:1065)
    at app//androidx.compose.material3.ColorResourceHelper.getColor-WaAFU9c(DynamicTonalPalette.android.kt:205)
    at app//androidx.compose.material3.DynamicTonalPaletteKt.dynamicLightColorScheme34(DynamicTonalPalette.android.kt:307)
    at app//androidx.compose.material3.DynamicTonalPaletteKt.dynamicLightColorScheme(DynamicTonalPalette.android.kt:170)

Steps to Reproduce In a project with M3, enable dynamic colors in the AppTheme e.g.

@SuppressWarnings
@Composable
fun AppTheme(
    content: @Composable () -> Unit
) {
    val inDarkMode: Boolean = isSystemInDarkTheme()

    val colors = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
        val context = LocalContext.current
        if (inDarkMode) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
    } else {
        if (inDarkMode) darkThemeColors else lightThemeColors
    }

    MaterialTheme(
        colorScheme = colors,
        content = content
    )
}

Then execute the Paparazzi tests and see them crashing with the aforementioned error

Expected behavior The tests should not crash. Actually the workaround is to configure the Paparazzi rule with compileSDKVersion 33 or lower. The following makes the tests pass:

environment = 
   detectEnvironment().copy(
      compileSdkVersion = 33,
   ),

Additional information:

TWiStErRob commented 3 months ago

This looks very similar: https://github.com/cashapp/paparazzi/issues/1025#issuecomment-1654065507

Is it possible #1314 will fix this?

jrodbx commented 1 month ago

@sergio-sastre per @TWiStErRob 's comment, is this now fixed with 1.3.4?

jrodbx commented 1 month ago

@sergio-sastre any updates?

sergio-sastre commented 1 month ago

@sergio-sastre any updates?

Sorry, I’ve been sick all week long. I’ll test it once I get time, hopefully next week

sergio-sastre commented 1 month ago

@sergio-sastre any updates?

I've finally got time to test it and it works with 1.3.4. Thanks for your work! :)