Bummer. I can’t use Compose because it requires IR...
# compose
t
Bummer. I can’t use Compose because it requires IR, but my app crashes with IR enabled due to my use of Kotlin.Result (https://youtrack.jetbrains.com/issue/KT-44722). And the fix won’t be released until 1.5. 😞
j
There might be a way that you can use it. You should try adding a new module to the project, where you can useIR = true
l
yeah, that is indeed unfortunate! As jaqxues mentions, you can just have IR enabled on specific modules if that unblocks you.
1
t
Yeah, I was thinking about that. But then I have to handle the ComposeView in my XML (just testing it one area). Perhaps I could make that a generic View and add the ComposeView in to that View in code?
j
I think you can even use
include
to include layouts from other modules, so that would not be an issue either.
t
Sorry, I am a n00b at modules. Which one would I use?
j
Well, Android Library probably
t
Okay, cool. I will give that a shot. And we do expect a non-IR app to link to an IR lib without issue? Guess I will find out… 🙂
j
Sure, the IR feature is basically just a different compiler backend, and I at least do certainly expect different modules to use different compilers
t
great. i will give it a try and report back here..
l
it should work, although there is a kotlin flag that you might need to pass to allow it. i can’t remember if we pass it in with AGP automatically or not.
t
something like this?
Copy code
//tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
//    kotlinOptions {
//        jvmTarget = "1.8"
//        freeCompilerArgs += [
//                "-Xallow-jvm-ir-dependencies",
//                "-P",
//                "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
//        ]
//    }
//}
z
Pretty sure you don’t need that flag as of 1.4.30, since the Ir backend is now guaranteed to generate stable bytecode - in fact the compiler complains if you try
1
t
great. 🤞
Okay, I was able to move the three compose files into an android library module (and as you say, i could simply include them). Have not hooked up all the code, but the main app loads and runs and does not crash on Result.onSuccess(). So very good progress. Thank you all!
c
Nice. I have never used gradle modules either, but putting compose in a separate module makes a lot of sense to me.
t
just have to move over any resources - colors, drawables, etc. that i use in the Compose code, and should be golden…
FYI, I got all my Compose moved into a lib, wrote a couple wrappers to setContent on the lib side, and all working as before while using 1.4.30 throughout - IR in lib, no IR in app. Thanks again all.