Kotlin unresolved reference in IntelliJ

后端 未结 20 1298
太阳男子
太阳男子 2020-12-01 08:47

I started off with the tutorial for learning Kotlin in IntelliJ.When I tried running the example i.e

fun main(args: Array) {
 prin         


        
相关标签:
20条回答
  • 2020-12-01 09:28

    My problem was solved by adding kotlin as follow

    presentation.gradle (app.gradle)

    apply plugin: 'com.android.application'
    
    apply plugin: 'kotlin-android' // here
    
    apply plugin: 'kotlin-android-extensions' // and here
    
    android {
        ...
    }
    
    dependencies {
        ...
    }
    

    domain.gradle (pure kotlin)

    My error was throw here, because Android Studio create my domain module as pure Java Module and applied plugin as java, and I used it in the my presentation module that is a Android/Kotlin Module

    The Android Studio finds and import the path of package but the incompatibillity don't allow the build.

    Just remove apply plugin: 'java' and swith to kotlin as follow

    apply plugin: 'kotlin' // here is
    
    dependencies {
        ...
    }
    
    ...
    

    data.gradle

    apply plugin: 'com.android.library'
    
    apply plugin: 'kotlin-android' // here
    
    apply plugin: 'kotlin-android-extensions' // and here 
    
    android {
        ...
    }
    
    dependencies {
        ..
    }
    

    I think that it will be helpfull

    0 讨论(0)
  • 2020-12-01 09:28

    I tried everything: clean build folders, run gradle clean build, execute AS invalidate cache(x2), reinstall Kotlin plugin, restarting pc.

    But in the end after doing all this it still didn't work, but doing also removal from project build.gradle of this line: apply plugin: 'kotlin-android-extensions', gradle sync and then re-adding worked

    0 讨论(0)
  • 2020-12-01 09:30

    Invalidating caches and updating the Kotlin plugin in Android Studio did the trick for me.

    0 讨论(0)
  • 2020-12-01 09:30

    Another thing I would like to add is that you need to select View -> Tool Windows -> Gradle before you can run the project using the Gradle.

    If using the Gradle the project builds and runs normally but using the IntelliJ it doesn't, then this can solve the matter.

    0 讨论(0)
  • 2020-12-01 09:31

    Check and install Android Studio Updates. This fix the problem.

    0 讨论(0)
  • 2020-12-01 09:32

    For me, it was due to the project missing Gradle Libraries in its project structure.

    Just add in build.gradle: apply plugin: 'idea'

    And then run: $ gradle idea

    After that gradle rebuilds dependencies libraries and the references are recognized!

    0 讨论(0)
提交回复
热议问题