Embarrassing I don't know this, but if I want to u...
# android
c
Embarrassing I don't know this, but if I want to use the newly stable Kotlin 1.4.0 explicit API mode with Android build.gradle, where would I put the block?
Copy code
kotlin.explicitApi()
z
I would think it would be in
kotlinOptions
, but it doesn’t appear to be. 🤔
c
I mean, worst case, I could set the command line option.
Ugh, I did this. Now, I'm getting
RedundantVisibilityModifier
all over the codebase. It seems that should be disabled for explicit API=strict.
Copy code
android {
    // ...
    kotlinOptions {
        // using explicit API mode to guarantee we only expose methods we intend
        freeCompilerArgs += "-Xexplicit-api=strict"
    }
}
😞 1
Maybe I need the new Kotlin 1.4.0 compiler plugin that hasn't been released yet.
z
So this works for me, but i’m not seeing any errors about implicit visibility:
Copy code
android {
  …
}

kotlin {
  explicitApi = Strict
  // or
  explicitApi()
}

dependencies {
  …
@ralf Did you actually get this to work?
r
Yes
I had to add the public modifier, otherwise there was a compilation error.
z
huh, my build is succeeding, no errors, even though there are definitely classes with no visibility modifiers
c
I got it to work with the freeCompilerArgs. Then when I built and ran my app, I got warnings which triggered warningsAsErrors in my build.
z
freeCompilerArgs
works for me too. I wonder if the Kotlin DSL is broken.
r
Possible, I’m using Groovy.
Groovy > Kotlin 🧌
z
i almost agree with you, given how terrible gradle is
Ugh, kotlin thinks tests also need explicit visibility… that’s annoying
r
You can apply this option for non-test KotlinCompile task only.
If you enable it for all, then obviously it will also run for tests.
z
makes sense
what’s the best way to filter test tasks out? this feels hacky:
Copy code
tasks.withType<KotlinCompile> {
  if (!name.contains("test", ignoreCase = true)) {
    kotlinOptions {
@colintheshots yep looks like there’s a known issue about android projects: https://youtrack.jetbrains.com/issue/KT-37652. Fixed in 1.4.20, which seems more and more to be the real 1.4 release 😂
😂 3