airbnb / Showkase

🔦 Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements
https://medium.com/airbnb-engineering/introducing-showkase-a-library-to-organize-discover-and-visualize-your-jetpack-compose-elements-d5c34ef01095
Apache License 2.0
2.1k stars 107 forks source link

Paparazzi Integration - Resources not found #311

Closed DPGLuke closed 11 months ago

DPGLuke commented 1 year ago

I'm using the Paparazzi integration: com.airbnb.android:showkase-screenshot-testing-paparazzi

When I try to run the test to generate screenshots, all of my composables which use resources fail with this error: android.content.res.Resources$NotFoundException: Could not resolve resource value: XXX

I have a feeling this is related to https://github.com/cashapp/paparazzi/issues/657

Problem

This happens in a multi-module project, where I have:

When I ran Paparazzi to generate screenshots (./gradlew app-test:testDebug) I would get the Could not resolve resource value error for every Composable that used a resource.

Solution

The solution was for app-test to not use the ShowkaseRoot from app. Instead, app-test now declares its own @ShowkaseRoot, and references that from ScreenshotTest:

@ShowkaseRoot
class AppTestShowkase : ShowkaseRootModule

...

@ShowkaseScreenshot(rootShowkaseClass = AppTestShowkase::class)
abstract class ScreenshotTest : PaparazziShowkaseScreenshotTest {
    companion object : PaparazziShowkaseScreenshotTest.CompanionObject
}

I also had to remove the dependency app-test had on app. This was to avoid having multiple ShowkaseRootModules in app-test - this seems to confuse the code generation of ShowkaseScreenshot.

This seems to work around the issue of resources not being available across modules, as I now don't have any Could not resolve resource value errors, and my screenshots generate perfectly!

To do

Can we add some documentation for this somewhere in this library? I think this use-case (wrapping the 'root' application module in a library module for Paparazzi) will be fairly common, and I'd like to save someone else time so they don't have to discover this all by themselves.

Thanks for the great library by the way!

vinaygaba commented 1 year ago

@DPGLuke What you are describing is a requirement of Paparazzi (that it only works in library modules). I'll make sure to add this info when I complete my "Screenshot testing with Showkase" documentation which I'm currently working on.

RadoslawGorczyca commented 1 year ago

Hi, I'm having the same issue, but your solution isn't working for me. After all steps I get this error: error: com.airbnb.android.showkase.processor.exceptions.ShowkaseProcessorException: Showkase was not able to find the root class that youpassed to @ShowkaseScreenshot. Make sure that you have configured Showkase correctly. Do you have any suggestions on how to fix it?

micHar commented 1 year ago

Same issue here

vinaygaba commented 11 months ago

@RadoslawGorczyca It sounds like you have a different issue, as suggested by the stack trace. If you'd like, open a separate issue and give me a bit more details about your setup. It does sound like something is not set up correctly.

vinaygaba commented 11 months ago

@DPGLuke like you correctly pointed out, it does sound like the Paparazzi issue that you linked - https://github.com/cashapp/paparazzi/issues/657