Search code examples
androidandroid-studiokotlinkotlin-extension

Android Studio and Kotlin: Unresolved reference: also


also compiles and runs from Android Studio:

val greeted = "World".also { println("Hello $it") }

Yet the editor highlights also and it 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 both apply and also. How do I get Android Studio to recognize also?

  • 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.


Solution

  • 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.

    enter image description here