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

ConstraintLayout 1.1.0-alpha12 "Width (0) and height (0) cannot be <= 0" error or font resource loading error or empty screenshot issue #1054

Closed
alashow opened this issue Aug 22, 2023 · 14 comments
Labels
bug Something isn't working waiting on user Waiting on information from OP
Milestone

Comments

@alashow
Copy link

alashow commented Aug 22, 2023

Description
When upgrading from androidx.constraintlayout:constraintlayout-compose:1.1.0-alpha05 to 1.1.0-alpha-12 (or any versions in between), screenshot tests start failing (even the tests that don't use constraintlayout)

Steps to Reproduce
Apply androidx.constraintlayout:constraintlayout-compose:1.1.0-alpha12 dependency

Screenshot tests fail with different reasons:

Variant 1:
java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
        at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016)
        at java.desktop/java.awt.image.BufferedImage.<init>(BufferedImage.java:333)
        at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:519)
        at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:451)
        at app.cash.paparazzi.Paparazzi$takeSnapshots$1$2.invoke(Paparazzi.kt:314)
        at app.cash.paparazzi.Paparazzi$takeSnapshots$1$2.invoke(Paparazzi.kt:313)
        at app.cash.paparazzi.Paparazzi.withTime(Paparazzi.kt:361)
        at app.cash.paparazzi.Paparazzi.takeSnapshots(Paparazzi.kt:313)
        at app.cash.paparazzi.Paparazzi.snapshot(Paparazzi.kt:207)
        at app.cash.paparazzi.Paparazzi.snapshot$default(Paparazzi.kt:206)
        at app.cash.paparazzi.Paparazzi.snapshot(Paparazzi.kt:202)

Variant 2
java.lang.IllegalStateException: Could not load font
	at androidx.compose.ui.text.font.TypefaceRequestCache.runCached(FontFamilyResolver.kt:200)
	at androidx.compose.ui.text.font.FontFamilyResolverImpl.resolve(FontFamilyResolver.kt:92)
	at androidx.compose.ui.text.font.FontFamilyResolverImpl.resolve-DPcqOEQ(FontFamilyResolver.kt:79)
	at androidx.compose.foundation.text.HeightInLinesModifierKt$heightInLines$2.invoke(HeightInLinesModifi
...
android.content.res.Resources$NotFoundException: Font resource ID #0x7f09000f could not be retrieved.

or Variant 3, empty rendering:

(Interestingly enough, for empty ones it keeps/renders background color from theme)

Expected behavior
Screenshot tests to not break

Additional information:

  • Paparazzi Version: 1.3.1
  • OS: osx, 13.4.1
  • Compile SDK: 33 or 34
  • Gradle Version: 8.1.0 or 8.2.1-alpha16
  • Android Gradle Plugin Version: 8.1.0 or 8.2.0-alpha16

Screenshots
If applicable, add screenshots to help explain your problem.

@alashow alashow added the bug Something isn't working label Aug 22, 2023
@alashow alashow changed the title ConstraintLayout 1.1.0-alpha12 "Width (0) and height (0) cannot be <= 0" error or font resouce or empty screenshot issue ConstraintLayout 1.1.0-alpha12 "Width (0) and height (0) cannot be <= 0" error or font resource loading error or empty screenshot issue Aug 22, 2023
@jrodbx jrodbx self-assigned this Aug 31, 2023
@jrodbx jrodbx added this to the 1.4 milestone Aug 31, 2023
@jrodbx
Copy link
Collaborator

jrodbx commented Aug 31, 2023

Also seen on CashApp although with a different library version bump, investigating

@ivannarino
Copy link

ivannarino commented Sep 12, 2023

I had this issue a bit randomly on my CI, I didn't commit some flaky screenshots that didn't fail the build locally. After generating all the snapshots and pushing them to remote, the errors went away.

It may not resolve your issue, but thought it would be nice adding my feedback.


Edit: I am still having this issue on a new PR, but the previous fix didn't work

@ivannarino
Copy link

Managed to make it work only rebuilding the PR from the same commit. So it's flaky

@jrodbx
Copy link
Collaborator

jrodbx commented Sep 15, 2023

Having some trouble repro'ing this issue, has anyone found a recipe?

@mrmike
Copy link

mrmike commented Sep 18, 2023

I didn't find what exactly is causing the issue but disabling cache with --no-build-cache while running verify task fixed the issue in my case.

@mrmike
Copy link

mrmike commented Sep 18, 2023

Together with @ivannarino, we've dug more into the issue and found out that there's some caching issue when using the new resource loading mechanism.

We've noticed that snapshot verification only fails when output for the task preparePaparazziDebugResources comes from the cache. When a task was executed, snapshot verification worked as expected (this explains why adding --no-build-cache fixes the issue).

After checking that Paparazzi 1.3.1 introduced a new resource/asset loading mechanism I've switched to the legacy one using

app.cash.paparazzi.legacy.resource.loading=true
app.cash.paparazzi.legacy.asset.loading=true

and with the legacy mechanism, everything is working ok.

Hopefully, this will help find the root cause of this issue. Also, let me know If I can provide any more details.

@mrmike
Copy link

mrmike commented Sep 19, 2023

I'm adding a couple more findings that helped me reproduce the issue on my local machine (with some manual modifications)

  1. In my project I use fonts provided in the resources of the external AAR library
  2. Enable the new resource loading mechanism to make sure Paparazzi is not using merged_res directories
  3. In the Gradle cache (.gradle/caches) find the corresponding entry for the library that provides fonts (make sure cache is populated)
  4. Manually remove fonts (sample path .gradle/cache/transforms-3/a8b69e7d0b4f9fbed8763a56c9bccf70/transformed/{libraryName-version}/res/font/)
  5. Run verifyPaparazziDebug task to get
    java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
    
    and
    java.lang.IllegalStateException: Could not load font
    
    exceptions.

Originally I was getting those exceptions only on CI, never on my local machine so I assume this could be somehow related to the Gradle cache state on the CI.

@jrodbx
Copy link
Collaborator

jrodbx commented Jan 13, 2024

Update:

I've spent considerable time investigating this and I think this was ultimately a Gradle caching bug, addressed here: #1226

Can someone try reproducing with the latest snapshot (@mrmike, @alashow) and confirm that this is now solved? I'd much appreciate it.

In the meantime, I'll move this into the next milestone as I'd like to move forward with a release.

@jrodbx jrodbx modified the milestones: 1.3.2, 1.3.3 Jan 13, 2024
@jrodbx jrodbx added the waiting on user Waiting on information from OP label Jan 14, 2024
@jrodbx jrodbx removed their assignment Jan 14, 2024
@mrmike
Copy link

mrmike commented Jan 15, 2024

Hi @jrodbx

I was trying to reproduce the issue using the latest version of Paparazzi but I've encountered different exception

java.lang.IllegalAccessError: class com.android.resources.ResourceType tried to access method 'java.util.stream.Collector com.google.common.collect.Sets.toImmutableEnumSet()' (com.android.resources.ResourceType and com.google.common.collect.Sets are in unnamed module of loader 'app')
	at com.android.resources.ResourceType.<clinit>(ResourceType.java:175)
	at app.cash.paparazzi.internal.DynamicResourceIdManager$IdProvider.<init>(DynamicResourceIdManager.kt:14)
	at app.cash.paparazzi.internal.DynamicResourceIdManager.<init>(DynamicResourceIdManager.kt:28)
	at app.cash.paparazzi.internal.PaparazziCallback.<init>(PaparazziCallback.kt:52)
	at app.cash.paparazzi.Paparazzi.prepare(Paparazzi.kt:155)
	at app.cash.paparazzi.Paparazzi$apply$1.evaluate(Paparazzi.kt:142)

I think this might be somehow related to the Guava version bump but I'll need to spend more time to investigate this exception.

@TWiStErRob
Copy link
Contributor

@mrmike see full report and workaround for that issue: #1231

@mrmike
Copy link

mrmike commented Jan 15, 2024

With the workaround applied I was not able to reproduce the issue. Thanks @TWiStErRob for providing the link :)

@jrodbx
Copy link
Collaborator

jrodbx commented Jan 16, 2024

Closing as fixed!

@jrodbx jrodbx closed this as completed Jan 16, 2024
@alashow
Copy link
Author

alashow commented Feb 7, 2024

Sorry for coming to this late, but I'm still seeing this issue with 1.3.2.

@mrmike Were you still seeing width/height issues before upgrading to 1.3.2? Because for me 1.3.2 only introduced #1054 (comment) issue, and the workaround was only for guava.

@alashow
Copy link
Author

alashow commented Feb 7, 2024

Apparently now this problem shows up even with composeBom version 2024.01.00

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

No branches or pull requests

5 participants