Android Studio and Kotlin: Unresolved reference: also
11,352
Solution 1
The also function was added in Kotlin 1.1 but you have your Language version set to 1.0. Go to your settings/preferences and change the Kotlin version to 1.1.
Solution 2
I tried everything possible and nothing worked. The only solution for me was to delete .AndroidStudio folder from C:/Users/YourName/. Android Studio resets and everything works as it should.
Comments
-
Love almost 2 years
also compiles and runs from Android Studio:
val greeted = "World".also { println("Hello $it") }
Yet the editor highlights
also
andit
as errors and don't give any help with intellisense. apply still works and when I go to source I can see the definition of bothapply
andalso
. How do I get Android Studio to recognizealso
?- Android Studio 2.3.3
- kotlin_version = '1.1.3-2'
- Kotlin plugin 1.1.3-release-Studio2.3-2
I've also had this problem with earlier versions.
-
Love almost 7 yearsThis worked after a restart. Do you know why configuring 1.1 in gradle isn't enough?
-
Troy Heninger almost 7 yearsThat's a good question. I don't know. But my guess is that the Kotlin compiler in AS is not looking at the Gradle setting. So it has to have its own setting. You might want to report that discrepancy to JetBrains.
-
Erik almost 7 yearsThis was my exact problem. However, I've set the Kotlin compiler version to 1.1 already many times in the past for the project and it keeps resetting after some unknown magics... Any idea if this is an Android Studio bug? A Kotlin plugin bug?
-
Troy Heninger almost 7 yearsCould it be that someone has checked in an older .iml file for the module into your repository so when you do a clean checkout it get's reset to the previous version? If so, I would recommend that you either replace the .iml file with a newer one, or (better) remove the .iml file from the repository and .ignore them in GIT.
-
easy_breezy over 4 yearsThanks it worked for me. I had problems with all kotlin keywords like apply, until, and even with annotations like JvmOverload, Throws and so on, after i followed your advice everything forks fine.
-
FEBRYAN ASA PERDANA almost 4 yearsCame across this answer as I had similar problem, and this one solved the issue very well. Should be the accepted answer after all, so others confronting similar problem can immediately implement this workaround.