In a multiplatform module, I would like to use Com...
# compose-desktop
a
In a multiplatform module, I would like to use Compose for Android and Desktop in a shared source set (
javaMain
), but keep assembling a normal iOS framework (to be consumed from an XCode project with SwiftUI), and also use Kotlin/React for UI in
jsMain
. I managed to put the Compose code into
javaMain
and
android
and
desktop
target compile just fine. I also managed to disable the Compose plugin for JS by adding
compose.web.targets()
, and it also compiles just fine. But I can't find a way to disable the Compose plugin for iOS. My iOS build fails with:
Copy code
Compilation failed: Cannot find the Composer class in the classpath
Is there any workaround? I'm using Compose
1.1.1
.
t
Experienced the same issue too, and worked around it by adding the following to the build.gradle.kts file:
Copy code
configurations.all {
    // Exclude native compiler
    exclude("org.jetbrains.compose.compiler", "compiler-hosted")
}
Works for me but not sure if it can cause any other issues
a
Thanks, I will try!
a
Looks like that workaround no longer works with Kotlin 1.7.0
t
Right, I am using a different workaround now
Copy code
import org.jetbrains.compose.ComposeCompilerKotlinSupportPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
    // ... other plugins
    id("org.jetbrains.compose") version "1.2.0-alpha01-dev741"
}

// Exclude native compiler
plugins.removeAll { it is ComposeCompilerKotlinSupportPlugin }
class ComposeNoNativePlugin : KotlinCompilerPluginSupportPlugin by ComposeCompilerKotlinSupportPlugin() {
    override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean {
        return when (kotlinCompilation.target.platformType) {
            KotlinPlatformType.native -> false
            else -> ComposeCompilerKotlinSupportPlugin().isApplicable(kotlinCompilation)
        }
    }
}
apply<ComposeNoNativePlugin>()
That works, it hasn’t gotten any prettier but it does the job
If you find anything better please share!
👍 1
a
Wow thanks a lot! Works like a charm!
181 Views