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

Update compileSdk to 34 and fix deprecation warning #335

Closed rschattauer closed 1 year ago

rschattauer commented 1 year ago

Hello.

Please bump compileSdk to 34 for your lib and sample.

In my project I have allWarningsAsErrors = true within kotlinOptions { .. }. The issue is that ksp generates the following Class.forName("de.hochbahn.hvvswitch.ui.RootModuleCodegen").newInstance() where newInstance() is deprecated with compileSdk 34 and this fires due to allWarningsAsErrors = true.

As workaround I currently run a script after the gradle ksp task that adds @Suppress("DEPRECATION") to that function:

tasks.withType(KspTask::class.java).configureEach {
        doLast {
            fileTree(buildDir).apply { include("**/*ShowkaseExtension*.kt") }.files.forEach { file ->
                ReplaceRegExp().apply {
                    setMatch("public fun Showkase.getMetadata")
                    setReplace("@Suppress(\"DEPRECATION\") public fun Showkase.getMetadata")
                    setFlags("g")
                    setByLine(true)
                    setFile(file)
                    execute()
                }
            }
        }
    }
vinaygaba commented 1 year ago

Thanks for flagging. I'll have to investigate what the recommended API is going forward. Should be straightforward to fix it if it only requires using a different API (haven't investigated yet)

ahinton-league commented 1 year ago

If anyone is interested, here's the work around in groovy:

    tasks.withType(KspTask).configureEach {
        doLast {
            def tree = fileTree(buildDir)
            tree.include("**/*ShowkaseExtension*.kt")
            tree.files.forEach { file ->
                def rep = new ReplaceRegExp()
                rep.setMatch("public fun Showkase.getMetadata")
                rep.setReplace("@Suppress(\"DEPRECATION\") public fun Showkase.getMetadata")
                rep.setFlags("g")
                rep.setByLine(true)
                rep.setFile(file)
                rep.execute()
            }
        }
    }