Hello while working on multiplatform project, I am...
# compose-web
r
Hello while working on multiplatform project, I am sharing mu compose UI between android and Web I have created a  
composable
  shared multiplatform module, inside that I have put some compose libraries as 
commonMain
Android app runs fine, but when I try to run 
./gradlew jsBrowserRun
  it fails to resolve all the compose dependencies
Here is the stacktrace
Copy code
* What went wrong:
Could not determine the dependencies of task ':composables:webPackageJson'.
> Could not resolve all dependencies for configuration ':composables:webNpm'.
   > Could not resolve org.jetbrains.compose.foundation:foundation:1.0.1.
     Required by:
         project :composables
      > No matching variant of org.jetbrains.compose.foundation:foundation:1.0.1 was found. The consumer was configured to find a usage of 'kotlin-runtime' of a library, preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js', attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir' but:
          - Variant 'debugApiElements-published' capability org.jetbrains.compose.foundation:foundation:1.0.1 declares a library:
              - Incompatible because this component declares an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.js.compiler (required 'ir')
          - Variant 'debugRuntimeElements-published' capability org.jetbrains.compose.foundation:foundation:1.0.1 declares a runtime of a library:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.js.compiler (required 'ir')
          - Variant 'desktopApiElements-published' capability org.jetbrains.compose.foundation:foundation:1.0.1 declares a library:
              - Incompatible because this component declares an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.js.compiler (required 'ir')
b
Only compose.web.core and compose.runtime dependencies are available on js target
r
but web.core and runtime are also getting failed for me Let me try again with that
Hello @Big Chungus Thanks for this, After removing compose ui and other modules from commonMain But I had to remove
compose.runtime
from commonMain as well
Infact I had to remove
compose.web.core
from
webMain sourceSet
from the shared
composable
module
Also even after I add
Copy code
compose.runtime
compose.web.core
in my
webApp
dependencies I am still not able to see/use any composable function classes
b
compose.runtime should work in commonMain, provided you use jb compose plugin as opposed to jetpack. Same for web.core on jsMain
You can inspect supported platforms of compose dependencies on kamp.petuska.dev (search for org.jetbrains.compose)
r
I am using the plugin with this id `
Copy code
id("org.jetbrains.compose") version Version.MPP_COMPOSE
`
👍 1
b
Note that on JS compose only works with IR backend. You can enable it when declaring target js("web", IR) {}
r
Yes, I did the
IR
compiler only
Still no composable function available And
compose.runtime and compose.web.core
does not work when I put them inside the shared module :\
b
Let me inspect that module's buildfile
r
here is my build file
Copy code
import org.jetbrains.compose.compose

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("org.jetbrains.compose") version Version.MPP_COMPOSE
}



kotlin {
    android ()

    js("web") {
        browser()
        binaries.executable()
    }


    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(project(":shared"))
                api(compose.runtime)
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(compose.foundation)
                implementation(compose.ui)
                implementation(compose("org.jetbrains.compose.ui:ui-tooling"))
                implementation(compose.material)
                implementation(compose.materialIconsExtended)
                api("androidx.activity:activity-compose:1.4.0")
            }
        }

        val webMain by getting {
            dependencies {
                api(compose.web.core)
            }
        }
    }
}

android {
    compileSdk = Version.COMPILE_SDK
    buildToolsVersion = Version.ANDROID_BUILD_TOOLS
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = Version.MIN_SDK
        targetSdk = Version.TARGET_SDK
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = true
        }
    }
}
this fails with message that
compose.runtime and compose.web.core
for JS not available
b
How are you enabling ir backend. Both issues look to be related to IR backend not being enabled
r
Oh, I think I reverted that IR backend thing somehow
Now its working
Thanks @Big Chungus
IR
thing I thought I enabled, but somehow I missed. I think I will remember this for sure
👍 1
b
Sweet!
🦜 1