https://kotlinlang.org logo
#compose
Title
# compose
t

tylerwilson

02/24/2021, 6:42 PM
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

jaqxues

02/24/2021, 6:51 PM
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

Leland Richardson [G]

02/24/2021, 6:52 PM
yeah, that is indeed unfortunate! As jaqxues mentions, you can just have IR enabled on specific modules if that unblocks you.
1
t

tylerwilson

02/24/2021, 6:53 PM
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

jaqxues

02/24/2021, 6:55 PM
I think you can even use
include
to include layouts from other modules, so that would not be an issue either.
t

tylerwilson

02/24/2021, 6:56 PM
Sorry, I am a n00b at modules. Which one would I use?
j

jaqxues

02/24/2021, 6:56 PM
Well, Android Library probably
t

tylerwilson

02/24/2021, 6:58 PM
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

jaqxues

02/24/2021, 6:59 PM
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

tylerwilson

02/24/2021, 6:59 PM
great. i will give it a try and report back here..
l

Leland Richardson [G]

02/24/2021, 6:59 PM
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

tylerwilson

02/24/2021, 7:00 PM
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

Zach Klippenstein (he/him) [MOD]

02/24/2021, 7:06 PM
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

tylerwilson

02/24/2021, 7:07 PM
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

Colton Idle

02/24/2021, 8:54 PM
Nice. I have never used gradle modules either, but putting compose in a separate module makes a lot of sense to me.
t

tylerwilson

02/24/2021, 9:01 PM
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.
3 Views