Unresolved reference: kotlinx

前端 未结 14 2728
无人及你
无人及你 2020-11-29 02:31

I am trying to try out Kotlin and the Kotlin Android extensions in Android Studio. I have tried this both in Android Studio v 1.5.1 on Ubuntu 14.04, and in Android Studio v

14条回答
  •  Happy的楠姐
    2020-11-29 03:09

    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.

提交回复
热议问题