https://kotlinlang.org logo
j

John O'Reilly

07/29/2023, 3:43 PM
What's expectation on using K2 Compiler with KMP projects. I tried on a few samples just now and failed in each of them. I'll dig deeper but just curious if this should work (using 1.5.0 version of Compose Compiler btw....think this had fix that was needed as well). Also, am using Kotlin 1.9.0.
Seeing for example "This API is not supported for K2" so maybe related to some libraries being used
Following is one of the samples for example where I see this https://github.com/joreilly/FantasyPremierLeague
Just tried with https://github.com/joreilly/StarWars and it is working...this one is using apollo graphql whereas FantasyPremierLeague is using Realm fwiw. Merged changes for StarWars project with
kotlin.experimental.tryK2=true
set by default now. I had tried with apollo one before but was failing due to issue related to use of Decompose (issue open for that)
also working and enabled now by default in https://github.com/joreilly/MortyComposeKMM (also uses apollo graphqlj)
Tried on a few more of the KMP samples I have....PeopleInSpace (as posted elsewhere) is failing for watchOS target and GalwayBus also failing in general. I'll try to dig deeper in to these when I get a chance but let me know if you want me to try anything here.
in both those cases you should be able to just comment back in
kotlin.experimental.tryK2=true
in
gradle.properties
for both projects
s

shikasd

07/30/2023, 8:44 PM
Compose compiler doesn't support K2 with KMP atm, it is creating an IrModuleFragment per source set, and that breaks Compose I hope to fix it with Kotlin 1.9.20
j

John O'Reilly

07/30/2023, 8:45 PM
It does seem to work with some KMP projects....or at least doesn't cause build failure
s

shikasd

07/30/2023, 8:45 PM
Hm, that's unexpected... :D
It definitely fails if the same compose function is used in common/JVM
Probably yours doesn't do that
j

John O'Reilly

07/30/2023, 8:47 PM
ah, in most of these I'm only sharing non-UI code
Re. the samples above that are using Realm Kotlin....looks like it's expected that they wont' work right now https://kotlinlang.slack.com/archives/C6J79CSDP/p1690790605511549?thread_ts=1690719372.009339&cid=C6J79CSDP