Is there any fix for AS telling me I need to Opt-I...
# android-studio
c
Is there any fix for AS telling me I need to Opt-In to experimental APIs over and over?
plus1 1
y
One possible solution is put the opt-in in the
kotlinOptions
of your project root build.gradle
Copy code
kotlinOptions {
    freeCompilerArgs += "-opt-in=androidx.compose.foundation.ExperimentalFoundationApi"
... 
}
Then it works for all Files and Classes. You need to do it for all the opt-ins though once.
c
sorry I wasn't super clear- I'm adding a
@file:OptIn(...)
and that is fine until I start using more of the experimental API and it starts warning me again. Doing the quick fix to opt in at a file level adds the exact same opt in
(I'm happier to have the opt in explicit in the file it's being used, rather than a blanket via compiler arguments)
y
Maybe the AS team can help with this, why
@file:OptIn(…)
is giving warning repeatedly.
e
@czuckie there are two opt in types now. The Kotlin one, and an androidx one. They're not compatible with each other and they can cause issues like the one you're seeing
c
!!! Eliezer I'll try and figure out which one I'm using, that's so satisfying to get an answer to, thank you
j
I've experienced where opt-in annotations don't properly disable all the warnings they should in the IDE. It works as it should at compile-time. Similarly, sometimes the annotation gets a warning in the IDE that it isn't needed, when it really is. Seems this started happening more recently. I never know whether it's the IDE, Kotlin, or plugin version that's to blame.