Unresolved reference: kotlinx

前端 未结 14 2673
无人及你
无人及你 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条回答
  • 2020-11-29 03:16

    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'
    

    Original answer:

    Most likely it's a bug in the Kotlin plugin. I've filed an issue on their tracker.

    0 讨论(0)
  • 2020-11-29 03:19

    Removing the following import fixed the issue for me.

    import android.R
    
    0 讨论(0)
  • 2020-11-29 03:20

    I found why mine didn't work. My blocks were misplaced and by moving the buildscript{} block before the plugins as follow I got it working:

    buildscript {
        ext.kotlin_version = '1.0.0-beta-3595'
        ext.anko_version = '0.8.1'
    
        repositories {
            jcenter()
        }
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
        }
    }
    
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"
    
        defaultConfig {
            applicationId "com.kotlin"
            minSdkVersion 15
            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.1.1'
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
        compile "org.jetbrains.anko:anko-sdk15:$anko_version"
        compile "org.jetbrains.anko:anko-support-v4:$anko_version"
    }
    
    0 讨论(0)
  • 2020-11-29 03:20

    In my case, I had put the code referring the view in a companion object. How silly..

    0 讨论(0)
  • 2020-11-29 03:20

    For me the only thing that helped was to click "File" -> "Invalidate caches / Restart..."

    0 讨论(0)
  • 2020-11-29 03:22

    The buildscript block containing the kotlin-android-extensions dependency apparently needs to be in the app-module build.gradle, not in the top-level one.

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