What on earth am I doing wrong? Is this not how yo...
# announcements
u
What on earth am I doing wrong? Is this not how you use
@OptIn
?
z
It looks like you haven’t opted into the
OptIn
annotation itself maybe?
u
I'm sorry, not sure what you mean? From what I gather, you either propagate, or optin, no?
z
The
OptIn
annotation itself is marked as
RequiresOptIn
, so typically you have gradle tell the kotlin compiler you want to optin to it. I assume that’s why your
OptIn
line is yellow. I’m not sure why you’re getting error message though, although all that red code looks suspicious
u
ohh so thats how it works, I thought it was either OptIn annot or the compiler args; and I have to compiler args the generic OptIn annotation, which will then be pluggable at source level, i see sort of like @Keep for proguard THANK YOU
z
You can actually opt-in to any annotation at the module level via compiler args. Just that typically you leave them in the source, since it’s useful documentation that things might break in the future.
u
but that would be the concrete google camera anntation class, right?
If I may borrow you a bit more
Copy code
tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile).configureEach { task ->
        task.kotlinOptions {
            jvmTarget = "1.8"
            freeCompilerArgs += "-Xopt-in=kotlin.OptIn"
            freeCompilerArgs += "-Xopt-in=kotlin.ExperimentalStdlibApi"
            freeCompilerArgs += "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
        }
    }
this would only work for pure kotlin modules? stupid OptIn is still "yellow"; however that call site is in a android module
z
Are you trying to exclude android modules? Typically kotlin options config is done with
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile)
u
yea im doing that but at compile time I see warnings of
Copy code
> Task :texts:impl:compileDebugKotlin
w: Class kotlin.OptIn is not an opt-in requirement marker
so not sure if this works
Copy code
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { task ->
        task.kotlinOptions {
            jvmTarget = "1.8"
            freeCompilerArgs += [
                    "-Xopt-in=kotlin.OptIn",
                    "-Xopt-in=kotlin.RequiresOptIn",
                    "-Xopt-in=kotlin.ExperimentalStdlibApi",
                    "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
            ]
        }
    }
yea, it doesn't work. lint complains about the
Annotation 'androidx.camera.core.ExperimentalGetImage' is not an opt-in requirement marker, therefore its usage in @OptIn is ignored
so the original issue stands
isnt google to blame?
Copy code
@Retention(CLASS)
@Experimental
public @interface ExperimentalUseCaseGroup {
}

should it not contain @RequiresOptIn(message = "This API is ?
z
Oh, yea they’re using the super old version of those annotations.
Experimental
->
RequiresOptIn
, and I think
OptIn
used to be called
UseExperimental
? That was changed so long ago I forget
u
Oh, well I think the lint is actually broken. It complains about it not being OptIn-ed into, but the source annotation is still Experimental, not RequiredOptIn; and even if I do all the analogues with @UsesExperimenta(..), it still says it needs OptIn..
thanks for your time