Unresolved reference: kotlinx

I can't find it in the official documentation, but you must apply the plugin by adding the following to your build.gradle file:

apply plugin: 'kotlin-android-extensions'

When you use Android Studio 2.0 and kotlin 1.0.1-2, you will come up with the same wrong. You cann't configure kotlin android extensions in your project's build.gradle, you need to configure and kotlin android extensions in every Module's build.gradle like this:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

buildscript {
    ext.kotlin_version = '1.0.1-2'
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0 rc2"

    defaultConfig {
        applicationId "com.dazd.kotlindemo"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
       main.java.srcDirs += 'src/main/kotlin'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

Most importantly, even through the kotlin plugin included the kotlin android extension, you also need to configure the kotlin-android-extensions in your Module's bulid.gradle like this:

...
apply plugin: 'kotlin-android-extensions'
...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

Of course, you could configure the kotlin plugin's classpath in your project's build.gradle.


Add kotlin-android-extensions in our buildscript's dependencies:

1. In your project-level build.gradle

buildscript {
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    }
}

and apply the kotlin-android-extensions plugin:

2. In your module-level build.gradle

apply plugin: 'kotlin-android-extensions'