Does an example repo exists with all three of comp...
# compose
m
Does an example repo exists with all three of compose desktop (configured to build for every OS), android and web with common sources without having to use subprojects?
p
Official repo examples: https://github.com/JetBrains/compose-jb/tree/master/experimental/examples Notice they are under experimental. You can search on GitHub, there are a couple of other good setups too. I am working on one setup right now, planning to add iOS soon. https://github.com/pablichjenkov/uistate3 Anyone welcome to participate. The idea is getting familiar with the technology by doing an App at the same time.
Now, the subproject part, I think you won't find anything like that out there. The multi platform nature of the project requires that. Notice any project of this magnitude relies a lot on abstractions and dependency provition rather than actual implementation and direct call of a platform specific API. Pretty much you got to abstract platforms away
m
I've been working on adapting chat-mpp, but I'm getting the following error, and google doesn't yield any results:
Copy code
Could not create an instance of type org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget.
> Could not generate a decorated class for type KotlinAndroidTarget.
   > com/android/build/gradle/api/BaseVariant
p
Humm, I see. I will go through the pain soon. Are you using Android Studio or Intellij
I’ve noticed that Android Studio picks up Android modules better
d
Just ran into the "Could not create an instance..." error message myself, and a Google search trying to find the answer led me to this thread. (Note: I'm using IntelliJ Community Edition, not Android Studio) However, I then fixed it, so I thought I'd paste my solution here, for any future devs who also hit it: 1. Add the Android Library (or Application) Plugin to your plugins block. (I just used the latest version available, from here: https://developer.android.com/studio/releases/gradle-plugin) 2. Add
google()
to your
pluginManagement
block, in your settings.gradle file (next to where
gradlePluginPortal
is declared)
At this point, I got passed the original error but there are more. I'm not 100% sure what I'm doing, but I'll include my steps here as I do my best to figure things out. If an Android dev sees I'm doing something wrong / missing something, please don't hesitate to call that out. 1. Add a top-level
android { ... }
block with a compileSdk and namespace set. 2. Add the following line to my
gradle.properties
file:
kotlin.mpp.androidSourceSetLayoutVersion=2
(I got a warning message suggesting it) 3. Configure the
android
target in the
kotlin
block to publish a release artifact (since in my project, I'm building a multiplatform library that can be consumed by Android):
Copy code
kotlin {
  android {
    publishLibraryVariants("release")
  }
}
4. Add an
AndroidManifest.xml
file under
src/androidMain
Edit: Here's the final diff of the change I made, in case anyone wanted to reference it.