Timo Drick
03/11/2026, 2:44 PMTimo Drick
03/11/2026, 2:46 PMtasks.named("prepareComposeResourcesTaskForCommonMain") {
val resDir = layout.buildDirectory.dir("generated/compose/resourceGenerator/preparedResources/commonMain/composeResources/files/preview").get().asFile
doLast {
println("=== Resource stripping starting ===")
// Delete specific preview files from the generated Kotlin sources
val files = resDir.list() ?: emptyArray<String>()
files.map { resDir.resolve(it) }
.forEach { generatedFile ->
if (generatedFile.exists()) {
generatedFile.delete()
println("Stripped preview file: ${generatedFile.absolutePath}")
} else {
println("Stripped preview file: ${generatedFile.absolutePath} does not exists")
}
}
}
}Winson Chiu
03/11/2026, 3:27 PMTimo Drick
03/11/2026, 3:30 PMRes.readBytes("files/preview/$url.webp")
.decodeToImageBitmap()Timo Drick
03/11/2026, 3:31 PM@OptIn(markerClass = [ExperimentalCoilApi::class])
@Composable
actual fun PreviewWrapper(content: @Composable (() -> Unit)) {
PreviewContextConfigurationEffect()
val previewHandler = AsyncImagePreviewHandler { request ->
val model = request.data
val url = model as? String
Res.readBytes("files/preview/$url.webp")
.decodeToImageBitmap()
.asAndroidBitmap()
.asImage()
}
CompositionLocalProvider(LocalAsyncImagePreviewHandler provides previewHandler) {
content()
}
}Timo Drick
03/11/2026, 3:31 PMWinson Chiu
03/11/2026, 3:35 PMTimo Drick
03/11/2026, 3:36 PMTimo Drick
03/11/2026, 3:37 PMWinson Chiu
03/11/2026, 3:37 PMTimo Drick
03/11/2026, 3:39 PMTimo Drick
03/11/2026, 3:40 PMWinson Chiu
03/11/2026, 3:48 PMWinson Chiu
03/11/2026, 3:52 PMTimo Drick
03/11/2026, 3:55 PMTimo Drick
03/11/2026, 3:55 PMWinson Chiu
03/11/2026, 4:11 PMgradlew -PwasmDebug=true :app:webRelease. You'd need to invert that and pass -PisRelease where you can check project.getProperty in the preview files module and conditionally call customDirectory. Looking at my code, seems you can just pass "commonMain" as the source set and it'll apply to all variants.
That should allow Studio to work just fine because it won't set the Gradle property.