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

No preview found in a minified and shrinked build (Proguard) #244

Closed tomjegan closed 2 years ago

tomjegan commented 2 years ago

With direct reference to this issue we are also experience this problem with builds where we have pro guard enabled.

As per VincentJouanne's comments we also would like to enable showkase for our internal QA builds such that design/product can inspect the components in app.

We also want to shift the annotation processing away from our dev/debug build as the build times are too high for this tool to be valuable as is unfortunately (even with ksp enabled).

Is it possible to provide a set of rules which will stop all the functions required from from converted?

Have tried StylianosGakis's suggestion but does not appear to work for us. Have also tried:

-keep class **.ShowkaseModuleCodegen { }

-keep,allowobfuscation @interface androidx.compose.ui.tooling.preview.Preview

-keep @androidx.compose.ui.tooling.preview.Preview class *
-keepclassmembers class * {
    @androidx.compose.ui.tooling.preview.Preview *;
}

-keepclassmembers class * {
    @com.airbnb.android.showkase.annotation.ShowkaseComposable <methods>;
}

But still seeing the error that there are no components.

Are we able to add in some default rules (or at least advise further in this instance) please?

tomjegan commented 2 years ago

Resolved. Needed to use correct name of ShowkaseRootModule implementing class. Therefore:

-keep class **.ShowkaseModuleCodegen { }

Was not correct.

Should have been.

-keep class **.ShowkaseRootCodegen { }

vinaygaba commented 2 years ago

@tomjegan Thank you for the tip 🥇

zaaaach commented 1 year ago

@tomjegan Is the single -keep class **.ShowkaseRootCodegen { } all that is required? I have tried that line in combination alone and in combination in my app & module level proguard rules but I am still getting the no components error.

vinaygaba commented 1 year ago

Just to summarize what's exactly needed for future reference -

You essentially need to add a proguard keep rule to make it with in release/alternate builds. The exact keep rule depends on your setup. For example, if your ShowkaseRootModule implementation looks like this -

package my.lovely.package

@ShowkaseRoot
class MyRootModule: ShowkaseRootModule

Then your proguard rule will need to be

-keep class **.MyRootModuleCodegen { }

We are essentially trying to retain the final XCodegen class that Showkase generates. The name of this generated class is of the format (_name_of_ShowkaseRootModule_implementation_)Codegen.

Hope this makes sense!

kotasjan commented 1 year ago

@tomjegan Thank you for your insights! Works great! 🚀