1

I am encountering with an error like

Unresolved reference: kotlinx

and the import statement is like

kotlinx.android.synthetic.main.activity_main.*

The bold code goes red and I am not able to use Kotlin Android extensions.This project was working fine for the past 2 days.

Seeing the other post,I added

classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

in the Project level build.gradle and

apply plugin: 'kotlin-android-extensions'

in module level but they also fail.

Android studio version : 3.0.1

Kotlin version : 1.1.51

Thanks in advance :)

Daksh Agrawal
  • 855
  • 1
  • 11
  • 22
  • 1
    You only need the Kotlin plugin in your project level `build.gradle` file, as it itself includes Kotlin Android Extensions. That would be the following: `classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"`. If this doesn't help, post both of your `build.gradle` files if possible. – zsmb13 Feb 14 '18 at 11:24
  • It worked @zsmb13 . Thanks – Daksh Agrawal Feb 14 '18 at 11:34

2 Answers2

2

You only need the Kotlin plugin in your project level build.gradle file, as it itself includes Kotlin Android Extensions - there's no need for another Gradle dependency. That would look something like this:

buildscript {
    ext.kotlin_version = '1.2.21'

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
zsmb13
  • 85,752
  • 11
  • 221
  • 226
  • Perhaps something changed, or perhaps you just weren't using synthetics across multiple modules, but for synthetics to resolve one must include apply plugin: 'kotlin-android-extensions' – straya Dec 02 '20 at 03:23
1

Unresolved reference: kotlin

The kotlin-gradle-plugin compiles Kotlin sources and modules.

The version of Kotlin to use is usually defined as the kotlin_version property:

  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

Your build.gradle (Project Level) will be

buildscript {
    ext.kotlin_version = '1.2.21'

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}  
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198