airbnb / Showkase

🔦 Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements

Home Page:https://medium.com/airbnb-engineering/introducing-showkase-a-library-to-organize-discover-and-visualize-your-jetpack-compose-elements-d5c34ef01095

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KSP compiler warning when using multi preview annotations

JeremiahStephenson opened this issue · comments

When using ksp combined with multi preview annotations I am seeing a compiler warning like this:

w: [ksp] No dependencies are reported for ShowkaseMetadata_showkase_ which will prevent incremental compilation.

The custom annotation looks like this:

@Preview(
    name = PreviewConfig.PreviewDefaultSuffix,
    device = PreviewConfig.DefaultDevice,
    locale = PreviewConfig.DefaultLocale,
    uiMode = Configuration.UI_MODE_NIGHT_NO,
)
@Preview(
    name = PreviewConfig.PreviewDarkSuffix,
    group = PreviewConfig.PreviewNoSnapshotGroup,
    device = PreviewConfig.DefaultDevice,
    locale = PreviewConfig.DefaultLocale,
    uiMode = Configuration.UI_MODE_NIGHT_YES,
)
@Preview(
    name = PreviewConfig.PreviewScaledSuffix,
    group = PreviewConfig.PreviewNoSnapshotGroup,
    device = PreviewConfig.DefaultDevice,
    locale = PreviewConfig.DefaultLocale,
    uiMode = Configuration.UI_MODE_NIGHT_NO,
    fontScale = PreviewConfig.DefaultUpscale,
)
annotation class DefaultPreviews

What I think is happening is that KSP is picking up on the @Preview annotation over the custom annotation (like it would normally do for a compose preview) and generates a file based on it. But then something checks it later and realizes something is wrong since the generated code isn't tied to an actual preview.

@JeremiahStephenson Is this only happening in the multi preview context? i.e can you confirm you aren't seeing this when you are not using multi-preview?

I'm also experiencing something similar, but it is not related to the root module, not multiple annotations:

No dependencies are reported for MyRootModuleCodegen which will prevent incremental compilation.

@vinaygaba I can confirm that this happens with custom annotation classes. My annotations look like this:

import androidx.compose.ui.tooling.preview.Preview

@Preview(widthDp = 411, heightDp = 842)
annotation class PortraitPreview

@Preview(widthDp = 842, heightDp = 411)
annotation class LandscapePreview

@PortraitPreview
@LandscapePreview
annotation class OrientedPreviews

When I use @OrientedPreviews (or @PortraitPreview and @LandscapePreview respectively) on my previews, the warning already shown above will be printed out:

> Task :cmx:kspDebugKotlin
w: [ksp] No dependencies are reported for ShowkaseMetadata_showkase_some_path_previews_portraitpreview which will prevent
incremental compilation.
Please file a bug at https://issuetracker.google.com/issues/new?component=413107.
w: [ksp] No dependencies are reported for ShowkaseMetadata_showkase_some_path_previews_landscapepreview which will prevent
incremental compilation.
Please file a bug at https://issuetracker.google.com/issues/new?component=413107.

If I replace @PortraitPreview and @LandscapePreview with the @Preview(...) annotations, the warning is not shown.

Yes, the issue seems to come from that generated metadata used to be able to automatically detect multi preview annotations in KSP through different runs in different modules. I modified the code in Showkase to only process annotations provided with multiPreviewType in KSP too, removing the intermediate step of generating ShowkaseMultiPreviewCodegenMetadata and this issue is gone and the custom annotations are working just fine, tested against our real project.

You can see my changes here, in case they help.