https://kotlinlang.org logo
#android-studio
Title
# android-studio
c

czuckie

09/07/2023, 7:05 AM
Is there any fix for AS telling me I need to Opt-In to experimental APIs over and over?
plus1 1
y

Yingding Wang

09/07/2023, 7:22 AM
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

czuckie

09/07/2023, 7:26 AM
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

Yingding Wang

09/07/2023, 7:56 AM
Maybe the AS team can help with this, why
@file:OptIn(…)
is giving warning repeatedly.
e

eygraber

09/07/2023, 12:04 PM
@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

czuckie

09/07/2023, 12:08 PM
!!! Eliezer I'll try and figure out which one I'm using, that's so satisfying to get an answer to, thank you
j

Jeff Lockhart

09/07/2023, 8:06 PM
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.