Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdaptiveIcon isn't rendered #1040

Open
apkelly opened this issue Aug 14, 2023 · 4 comments
Open

AdaptiveIcon isn't rendered #1040

apkelly opened this issue Aug 14, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@apkelly
Copy link

apkelly commented Aug 14, 2023

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:

  • Paparazzi Version: 1.3.1
  • OS: Mac
  • Compile SDK: 33
  • Gradle Version: 8.1
  • Android Gradle Plugin Version: 8.0.2

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

@apkelly apkelly added the bug Something isn't working label Aug 14, 2023
@jamesrapadmi
Copy link

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
Copy link

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

@consp1racy
Copy link

If at any point you have access to RenderParams, set the following flag:

setFlag(
    SessionParams.Key("adaptiveIconMaskPath", String::class.java),
    "M50,0L92,0C96.42,0 100,4.58 100 8L100,92C100, 96.42 96.42 100 92 100L8 100C4.58, 100 0 96.42 0 92L0 8 C 0 4.42 4.42 0 8 0L50 0Z"
)

Value taken from $ANDROID_HOME/platforms/android-35/data/res/values/config.xml!string/config_icon_mask.

It's used either in com.android.layoutlib.brige.impl.RenderAction or android.graphics.drawable.AdaptiveIconLayout depending on the version of layoutlib.

@jamesrapadmi
Copy link

I don't have access to RenderParams at any point, you can see the source above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants