cashapp / paparazzi

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

AdaptiveIcon isn't rendered #1040

Open apkelly opened 10 months ago

apkelly commented 10 months ago

Description I have the following code to fetch and render adaptive icons, specifically the res/mipmap-anydpi-v26/ic_launcher.xml file.

@Composable
fun adaptiveIconPainterResource(@DrawableRes id: Int): Painter {
    val res = LocalContext.current.resources
    val theme = LocalContext.current.theme

    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        // Android O supports adaptive icons, try loading this first (even though this is least likely to be the format).
        val adaptiveIcon = ResourcesCompat.getDrawable(res, id, theme) as? AdaptiveIconDrawable
        if (adaptiveIcon != null) {
            BitmapPainter(adaptiveIcon.toBitmap().asImageBitmap())
        } else {
            // We couldn't load the drawable as an Adaptive Icon, just use painterResource
            painterResource(id)
        }
    } else {
        // We're not on Android O or later, just use painterResource
        painterResource(id)
    }
}

This code work fine in the running app, and fine in the Android Studio preview, but fails with the following error in Paparazzi.

SEVERE: null: Failed to parse file /Users/andy/Development/mx51/vaa-android/x-paparazzi-tests/../core/ui/build/intermediates/packaged_res/geckoBankDebug/mipmap-anydpi-v26/ic_launcher.xml
java.lang.IllegalArgumentException: Path string can not be null.
    at android.util.PathParser.createPathFromPathData(PathParser.java:36)
    at android.graphics.drawable.AdaptiveIconDrawable.<init>(AdaptiveIconDrawable.java:167)
    at android.graphics.drawable.AdaptiveIconDrawable.<init>(AdaptiveIconDrawable.java:151)
    at android.graphics.drawable.DrawableInflater.inflateFromTag(DrawableInflater.java:161)
    at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:136)
    at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1394)
    at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1355)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1330)
    at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:393)
    at android.content.res.Resources_Delegate.getDrawable(Resources_Delegate.java:184)
    at android.content.res.Resources.getDrawable(Resources.java:931)
    at androidx.core.content.res.ResourcesCompat$Api21Impl.getDrawable(ResourcesCompat.java:705)
    at androidx.core.content.res.ResourcesCompat.getDrawable(ResourcesCompat.java:137)
    at io.mx51.vaa.ui.composables.PainterResourceExtKt.adaptiveIconPainterResource(PainterResourceExt.kt:22)
    at io.mx51.vaa.ui.settings.ManageSpaceScreenKt.ManageSpaceView(ManageSpaceScreen.kt:68)

Steps to Reproduce

  1. Create a new Compose project with default icons in Android Studio.
  2. Create a new Composable screen and use the method above to display the launcher icon on the screen.
  3. Note that the screen renders fine in Android Studio and when run on a phone (Android O or later).
  4. Record the paparazzi tests and note that the screen doesn't show the icon.

Expected behavior The adaptive icon for the launcher icon of my app should be rendered correctly using the code above.

Additional information:

Screenshots Paparazzi Test io mx51 vaa ui paparazzi_SettingsTests_manageSpaceSnapshot vs Android Studio Preview Screenshot 2023-08-15 at 00 01 06

jamesrapadmi commented 3 months ago

I'm seeing this too on 1.3.2 and 1.3.3. I'm struggling to deal with this on 1.3.3 because even if I handle the exception the test fails as exceptions were logged. Is there an expected fix date or version for this?

jamesrapadmi commented 3 weeks ago

Is there any update on this, this is still preventing us from updating to 1.3.3 or 1.3.4