So, maybe this is an Android Studio thing, but aft...
# android
d
So, maybe this is an Android Studio thing, but after upgrading to Kotlin 1.4.0, AS keeps reporting all of the new language features of 1.4 as red squiggly errors, though it compiles just fine. To get around this, we had to explicitly add the following to our build.gradle files
Copy code
kotlinOptions {
    languageVersion = "1.4"
}
Did those of you using 1.4 have to do this? We're using AS 4.0.1, and we've got the Kotlin 1.4.10-release-Studio4.0-1 plugin installed in AS.
✔️ 1
l
@Don Phillips Do you overwrite the
freeCompileeArgs
somewhere in the project without putting what's already there? If so, using
+=
in place of
=
should fix the issue.
d
lemme check. I don't think so. But I do remember Hilt mentioning something about compiler args so maybe we did.
l
You can just do cmd/ctrl + shift + F ("Find in Path") and filter to gradle files (or also buildSrc files if you use it) to find out.
d
Hmm, yep, looks like we screwed this up. Just found this in our convention plugin for our library modules:
Copy code
freeCompilerArgs = listOf(
            "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi"
        )
lemme switch it and see if that solves it
l
It's also quite outdated.
d
We don't need that anymore for coroutines?
l
I mean, you should use
opt-in
now in place of
use-experimental
.
You need it if you use experiential APIs
d
Ok, I think I see what you're saying. From https://kotlinlang.org/docs/reference/opt-in-requirements.html so it should really be
-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi
correct?
l
Yes
Did my initial suggestions fix the issue?
d
syncing now, standby
Strange..it helped, sort of.
So it looks like the SAM conversions are working correctly now. The following code isn't tossing a red squiggly now
Copy code
viewModel.dataRefreshedEvent.observe(this) {
            if (it == true) {
                listOf(
                    homeTabFragment, geniusTabFragment, overviewTabFragment, profileTabFragment
                ).forEach { baseFragment ->
                    baseFragment.updateDataOnView()
                }
            } else {
                homeTabFragment.hidePullToRefreshView()
            }
        }
l
So it works?
d
But, in another place, this code is still throwing a red squiggly on
maxOrNull
Copy code
selectAccountVM.accountsToSelect.value?.map { item -> item.balance }
                        ?.maxOrNull() ?: -1f
l
Another module ?
d
same module
l
What's the error?
d
unresolved reference: maxOrNull
hmm, what's stranger is that even after adding back the `languageVersion = "1.4" back to the build.gradle for the module, it's still coming up as unresolved reference
l
What else do you get in autocompletion at this use site?
d
Screen Shot 2020-09-16 at 10.54.46 AM.png
Trying an "Invalidate Caches and Restart" to see if that might fix
l
That doesn't show autocompletion
d
oh, sorry, misunderstood.
I see what you're getting at, one sec
Well I'll be damned.. it seems to be pulling in 1.3.72 for some reason...
running
gradlew dependencies --configuration implementation
now. I don't see how it can be pulling in 1.3.72. I triple checked - our library convention plugin is specifying 1.4.10 for the stdlib
well hell, might have found the reason. It looks like in some of the androidTestAnnotationProcessorClasspath configurations, 1.3.72 is being pulled in by androidx.databinding:databinding-compiler
l
I'm not it's the culprit but there's some stuff to try here.
If you can share a Gradle scan (granted it doesn't leak too private info), that could help.
d
lemme run one and see what happens
Yeah, I don't think I should publish a scan. I think that'll get me into trouble w/ infosec
what other stuff should I try @louiscad?
l
Check the build window for errors, sometimes it doesn't show that Gradle sync failed.
d
Checked it, looks good, build successful with last sync
l
Then Gradle scan could help diagnosis
d
I just tested the new allowance of trailing commas as well. It's red squiggly'ing me with the message "the feature "trailing commas" is only available in 1.4. This is so very strange.
l
Does it compile from command line?
d
I've been compiling by running the assemble_VariantName_ tasks in the Gradle pane of AS without problem
lemme try from the CLI though, standby
Yep, just ran
gradlew assembleLocalDebug
just fine from the terminal
l
Can you try to make a reproducing project to share?
d
I'll have to talk to the boss
see if he wants to work this hard at the problem
l
You can also submit an issue on kotl.in/issue and attach your project privately (selecting "Kotlin team") if you trust JetBrains with your private code.
👍 1
d
Thanks, I'll ask my boss, see what he wants to do
Hey @louiscad - I figured it out. My custom gradle convention plugin was the problem. The plugin's build.gradle was still using 1.3.72 for the kotlin plugin dependency in the script. So when I applied my convention plugin to the various modules having this problem, I was unknowingly applying 1.3.72 instead of 1.4.10. TIL - precompiled script plugins which apply plugins use the version of plugins specified in their dependencies block, they ignore the plugin resolution strategy defined in the project that the precompiled script plugin is being applied to
👍 1
l
Ah, makes sense!
Thanks for the info!
d
You're welcome. Now to solve the next problem - precompiled script plugins must use the version of Kotlin that's embedded with Gradle. When I change the version to 1.4.10, I run into this problem https://youtrack.jetbrains.com/issue/KT-38010
l
I think you can use buildSrc instead of convention plugin in the meantime
p
I'm facing the same problem. Is there an issue for it? What's a "convention plugin"? @Don Phillips
d
The Gradle Community slack pointed me in this direction https://github.com/jjohannes/idiomatic-gradle A "convention plugin" is a plugin that configures things that are common to modules of a given type in a project. So if you look in this repo, you'll see how they've got a number of convention plugins, to configure java, jacoco, unit-testing, etc. in a standard way across modules in the subprojects folder.