Hi everyone. I understand that if I develop a KMM-...
# compose-desktop
h
Hi everyone. I understand that if I develop a KMM-Compose library, Android developers would have to add "org.jetbrains.compose" plugin in their app module to prevent duplicate class errors. On the other hand, in my android specific libraries that also use compose, this plugin is not needed when a KMM-Compose library is added as a dependency. That's really confusing to me.. My actual question is: "Is there any other way that Android developers can apply in their projects to prevent duplicate class errors without using org.jetbrains.compose plugin"?
Copy code
tasks.create("replaceAndroidxCompose") {
  project.dependencies.modules {
    module("androidx.compose.animation:animation") {it.replacedBy("org.jetbrains.compose.animation:animation")}
    module("androidx.compose.animation:animation") { it.replacedBy("org.jetbrains.compose.animation:animation") }
    module("androidx.compose.animation:animation-core") { it.replacedBy("org.jetbrains.compose.animation:animation-core") }
    module("androidx.compose.compiler:compiler") { it.replacedBy("org.jetbrains.compose.compiler:compiler") }
    module("androidx.compose.compiler:compiler-hosted") { it.replacedBy("org.jetbrains.compose.compiler:compiler-hosted") }
    module("androidx.compose.foundation:foundation") { it.replacedBy("org.jetbrains.compose.foundation:foundation") }
    module("androidx.compose.foundation:foundation-layout") { it.replacedBy("org.jetbrains.compose.foundation:foundation-layout") }
    module("androidx.compose.material:material") { it.replacedBy("org.jetbrains.compose.material:material") }
    module("androidx.compose.material:material-icons-core") { it.replacedBy("org.jetbrains.compose.material:material-icons-core") }
    module("androidx.compose.material:material-icons-extended") { it.replacedBy("org.jetbrains.compose.material:material-icons-extended") }
    module("androidx.compose.material:material-ripple") { it.replacedBy("org.jetbrains.compose.material:material-ripple") }
    module("androidx.compose.runtime:runtime") { it.replacedBy("org.jetbrains.compose.runtime:runtime") }
    module("androidx.compose.runtime:runtime-saveable") { it.replacedBy("org.jetbrains.compose.runtime:runtime-saveable") }
    module("androidx.compose.ui:ui") { it.replacedBy("org.jetbrains.compose.ui:ui") }
    module("androidx.compose.ui:ui-geometry") { it.replacedBy("org.jetbrains.compose.ui:ui-geometry") }
    module("androidx.compose.ui:ui-graphics") { it.replacedBy("org.jetbrains.compose.ui:ui-graphics") }
    module("androidx.compose.ui:ui-test") { it.replacedBy("org.jetbrains.compose.ui:ui-test") }
    module("androidx.compose.ui:ui-test-junit4") { it.replacedBy("org.jetbrains.compose.ui:ui-test-junit4") }
    module("androidx.compose.ui:ui-text") { it.replacedBy("org.jetbrains.compose.ui:ui-text") }
    module("androidx.compose.ui:ui-unit") { it.replacedBy("org.jetbrains.compose.ui:ui-unit") }
    module("androidx.compose.ui:ui-util") { it.replacedBy("org.jetbrains.compose.ui:ui-util") }
  }
}

tasks.named("build") {
  it.dependsOn("replaceAndroidxCompose")
}
this seems to work ๐Ÿ˜„
k
I thought that Googleโ€™s plugin did all the replacing. I was looking at the plugin code and saw a bunch of replacement stuff
h
Not exactly Google's but as I said Jetbrains compose plugin resolves this issue. Understandably, I don't think many Android developers want to include this plugin in their app just because they are using an KMP library. The code I sent is directly from that plugin and the only necessary part for an Android app to use an KMP-Compose library.
a
This is a known issue for us and we together work to make life easier here. I expect some news in reasonable timeframe.
๐Ÿ‘€ 1
๐Ÿ‘๐Ÿผ 1
๐Ÿ‘ 1
๐Ÿฆœ 1
s
You can also publish your library removing all Compose Desktop transitive dependencies
b
Maybe
org.jetbrains.compose
plugin could produce additional
*-jetpack
artifact with replaced dependencies? Projects that do not use Compose Multiplatform could use the Jetpack version of the library and would not have to replace dependencies at build time. I did something similar in my library, but semi-manually.
a
We are considering one approach here. Probably there will be an experimental CMPP build soon, that will reference Jetpack Compose for android platform and thus there will be no duplicate class issue. This is truly experimental approach, but I hope it will work
๐Ÿ‘ 1
K 1
@Halil Ozercan We have published experimental build that is compatible with Jetpack - 0.0.0-master-build423. It uses 1.1.0-alpha06 Jetpack artifacts for android target. IMO it should solve this problem. If you build your MPP library based on it, it will be possible to use it in Android projects that uses Jetpack Compose. Simple smoke test is to take any android project and add there simultaneously
Copy code
implementation "androidx.compose.ui:ui:$compose_version"
and
Copy code
implementation "org.jetbrains.compose.ui:ui:$mpp_compose_version"
versions are:
Copy code
buildscript {
    ext {
        compose_version = '1.1.0-alpha06'
        mpp_compose_version = '0.0.0-master-build423'
    }
}
The build is published in
Copy code
maven {
    url("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
}
Let me know if it works or you have some issues with it
@burnoo I see you also might be interested in information above
๐Ÿ‘ 1
b
Works exactly as expected, thanks! Both
jvm
and
android
targets works with Jetpack Compose. Tested here
๐Ÿ†’ 1
h
Wow such great news @Alexander Kurasov[JB]! I'll definitely check it out as soon as possible.
๐Ÿ‘ 1
b
@Halil Ozercan it is already shipped in 1.0.0-beta1 ๐ŸŽ‰
๐ŸŽ‰ 1