Java – Android Studio cannot parse classes written in Kotlin (.kt) in the IDE, but compiles normally

Android Studio cannot parse classes written in Kotlin (.kt) in the IDE, but compiles normally… here is a solution to the problem.

Android Studio cannot parse classes written in Kotlin (.kt) in the IDE, but compiles normally

I started working on an existing project that used standard java and parts of Kotlin to handle certain classes.

Question:

The project compiles and runs fine, but when viewing the code in Android Studio, classes written in kotlin show unresolved in the IDE


UserConfigActivity.kt (a class written in Kotlin).

class UserConfigActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_user_config)
        setSupportActionBar(toolbar)

Not resolved when referenced/used in standard java classes (although compiles and runs fine):

enter image description here


Open the .kt file directly in Android Studio and prompt to find the plugin as follows:

enter image description here

But when I hit Install Plugins, nothing happens (no installation or situation changes). The next time I open another .kt file, the prompt comes up again.


Question:

  1. How do I fix unresolved symbols for classes written in Kotlin?
  2. How do I install plugins that prompt but are not installed when I click Install Plugins?

I’m using Android Studio 2.1.1.

Solution

To install the Kotlin

plugin, open the Settings dialog, select the Plugins node, press the Install JetBrains plugin button and select Kotlin from the list. Then restart the IDE.

Related Problems and Solutions