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.11k stars 107 forks source link

Showkase not working in a multi module project #285

Closed francescocervone closed 1 year ago

francescocervone commented 1 year ago

We have a design-system module. We'd like to create an Android application module design-system-preview that imports composables from design-system and shows the Showkase activity.

By reading the documentation, I believe we just need to declare our @ShowkaseRoot class MyRootModule : ShowkaseRootModule in our design-system-preview, apply Showkase annotation processor and everything should work as expected.

Unfortunately I found two issues:

  1. getBrowserIntent extension doesn't get generated. It gets generated if you have at least one @Composable @Preview in design-system-preview
  2. Once generated getBrowserIntent, the Showkase activity shows only composables defined in design-system-preview.

I've created a sample project: https://github.com/francescocervone/ShowkaseMultiModuleBug

oas004 commented 1 year ago

Hey @francescocervone, from the project you sent it seems that you have forgotten the dependency from :app to :composables. Furthermore, the composable module that has the previews that you want to show in the Showkase app needs to implement the showkase dependencies.

If you apply this diff. Then do a clean build and run the project again, you will see the button from your composable module.

diff --git a/app/build.gradle b/app/build.gradle
index 07a8313..e0e23de 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -36,6 +36,7 @@ android {
 }

 dependencies {
+    implementation project(':composables')
     implementation platform('androidx.compose:compose-bom:2022.12.00')
     implementation 'androidx.compose.material:material'
     implementation 'androidx.compose.ui:ui'
diff --git a/composables/build.gradle b/composables/build.gradle
index fc4fcac..de16799 100644
--- a/composables/build.gradle
+++ b/composables/build.gradle
@@ -1,6 +1,7 @@
 plugins {
     id 'com.android.library'
     id 'org.jetbrains.kotlin.android'
+    id 'org.jetbrains.kotlin.kapt'
 }

 android {
@@ -38,4 +39,7 @@ dependencies {
     implementation 'androidx.compose.ui:ui'
     implementation 'androidx.compose.ui:ui-tooling-preview'
     debugImplementation 'androidx.compose.ui:ui-tooling'
+
+    implementation "com.airbnb.android:showkase:1.0.0-beta15"
+    kapt "com.airbnb.android:showkase-processor:1.0.0-beta15"
 }
\ No newline at end of file

You can consider using compileOnly in the :composable module if you don't want it to be exposed to dependent projects.

francescocervone commented 1 year ago

from the project you sent it seems that you have forgotten the dependency from :app to :composables

Oh what a shame, I forgot about that in the sample, but in our project I didn't.

I was actually missing that I needed to import Showkase also in the imported module. Thanks!