Error:Unresolved reference


#1

Hey there!

I’ve tried to get Kotlin to work inside VSCode. I’ve managed to get it working with the basic kotlin library but when I try to import any java package or kotlinx I get this error on the import statement.

I get no syntax error from VSCode and I even get documentation reference so is not due to VSCode or Gradle for that matter. I am thinking is due to the command that I use to compile my source (kotlinc main.kt -include-runtime -d main.jar) or due to my folder structure(my source is in the root of the project), but this is just a rough guess.

Does anyone have any idea what the problem might be? Thanks in advance!


#2

You need to specify all files/libraries you need to compile your code. Based on your command the compiler expects all code you need to be either in “main.kt” or be part of the standard library.
I suggest you use a build system like Gradle. There are multiple tutorials and examples out there.
https://kotlinlang.org/docs/reference/using-gradle.html


#3

I am using gradle. Here is my build script :

```
 {
    ext.kotlin_version = '1.2.71'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
apply plugin: 'kotlin'

kotlin {
    experimental {
        coroutines 'enable'
    }
}
repositories {
    mavenCentral()
}
dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.21"
}
```

Does the main.kt have to be in a src>kotlin folder?