joreilly / PeopleInSpace

Kotlin Multiplatform project with SwiftUI, Jetpack Compose, Compose for Wear, Compose for Desktop, and Compose for Web clients along with Ktor backend.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compose in shared android code?

cyberhenoch opened this issue · comments

Hi
thanks for publishing this. It is good for picking up good practices in multiplatform project.

I am wondering if we can have compose code in shared part (/common/src/androidMain) or just in the platform code (app/src/main).
I have created a SO question with some project setup as an example but no luck as far :(
Am I missing something?

Yes, I believe this is possible and in fact one of the IntelliJ options when creating new project is to create such a project. It's not something I've tried so far but hopefully will at some point soon.

Thanks for the hint. I've just installed IntelliJ IDEA and the Kotlin/Multiplatform/Mobile Application option is there. But even with the compose plugin installed I can't see any compose-related options there. I manually set up the shared activity with compose in this template but still have the same error at runtime:

No static method setContent$default(Landroidx/activity/ComponentActivity;Landroidx/compose/runtime/CompositionContext;

This is the one I was thinking of.

Screenshot 2021-05-12 at 17 10 35

You are right - this one has compose and I managed to add & run compose code from the common part after creating it from this wizard. Now I'll try to find out what is the key difference. Thank you for your help!

Adding org.jetbrains.compose plugin fixed it, more details here
Thanks again :)