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.

enter image description here

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.

Share:
11,352
Love
Author by

Love

Code poet wannabe

Updated on June 07, 2022

Comments

  • Love
    Love almost 2 years

    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.

  • Love
    Love almost 7 years
    This worked after a restart. Do you know why configuring 1.1 in gradle isn't enough?
  • Troy Heninger
    Troy Heninger almost 7 years
    That'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
    Erik almost 7 years
    This 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
    Troy Heninger almost 7 years
    Could 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
    easy_breezy over 4 years
    Thanks 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
    FEBRYAN ASA PERDANA almost 4 years
    Came 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.