Android数据绑定的Kotlin问题

Android数据绑定的Kotlin问题,android,kotlin,android-databinding,Android,Kotlin,Android Databinding,我正在尝试使用Kotlin在Android上进行数据绑定,但遇到了一些问题。下面列出了我的gradle文件 顶级: buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0-beta3' classpath 'com.google.gms:google-services:2.1

我正在尝试使用Kotlin在Android上进行数据绑定,但遇到了一些问题。下面列出了我的gradle文件

顶级:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0-beta3'
        classpath 'com.google.gms:google-services:2.1.0-beta3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "..."
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        resValue 'string', 'package_name', applicationId
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name: 'app-release', ext: 'aar')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.android.support:recyclerview-v7:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.google.android.gms:play-services-plus:8.4.0'
    compile 'com.google.android.gms:play-services-auth:8.4.0'
    compile 'com.google.android.gms:play-services-gcm:8.4.0'
    compile 'com.google.android.gms:play-services-nearby:8.4.0'
    compile 'io.reactivex:rxkotlin:0.55.0'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'com.trello:rxlifecycle-kotlin:0.5.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'io.pristine:libjingle:11139@aar'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:retrofit:2.0.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
    compile 'com.pushtorefresh.storio:sqlite:1.8.0'
    compile 'com.pushtorefresh.storio:content-resolver:1.8.0'

    kapt 'com.google.dagger:dagger-compiler:2.0.2'
    compile 'com.google.dagger:dagger:2.0.2'
    provided 'org.glassfish:javax.annotation:10.0-b28'
}
buildscript {
    ext.kotlin_version = '1.0.1-2'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

kapt {
    generateStubs = true
}

apply plugin: 'com.google.gms.google-services'
应用程序级别:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0-beta3'
        classpath 'com.google.gms:google-services:2.1.0-beta3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "..."
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        resValue 'string', 'package_name', applicationId
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name: 'app-release', ext: 'aar')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.android.support:recyclerview-v7:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.google.android.gms:play-services-plus:8.4.0'
    compile 'com.google.android.gms:play-services-auth:8.4.0'
    compile 'com.google.android.gms:play-services-gcm:8.4.0'
    compile 'com.google.android.gms:play-services-nearby:8.4.0'
    compile 'io.reactivex:rxkotlin:0.55.0'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'com.trello:rxlifecycle-kotlin:0.5.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'io.pristine:libjingle:11139@aar'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:retrofit:2.0.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
    compile 'com.pushtorefresh.storio:sqlite:1.8.0'
    compile 'com.pushtorefresh.storio:content-resolver:1.8.0'

    kapt 'com.google.dagger:dagger-compiler:2.0.2'
    compile 'com.google.dagger:dagger:2.0.2'
    provided 'org.glassfish:javax.annotation:10.0-b28'
}
buildscript {
    ext.kotlin_version = '1.0.1-2'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

kapt {
    generateStubs = true
}

apply plugin: 'com.google.gms.google-services'
我使用下面的代码来膨胀我的视图

val binding = FragmentTransferListBinding.inflate(inflater, container, false)
但是当我尝试构建项目时,我得到了这个错误

Error:(7, 31) Unresolved reference: databinding
Error:(28, 9) Unresolved reference: FragmentTransferListBinding
Error:Execution failed for task ':app:compileDebugKotlinAfterJava'.
> Compilation error. See log for more details
我试着向kapt添加数据绑定编译器,正如其他一些答案中所建议的那样

kapt 'com.android.databinding:compiler:2.1.0-beta3'
但是我得到了下面的错误

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.append(Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable;
你需要

kapt 'com.google.guava:guava:19.0'
kapt 'com.android.databinding:compiler:2.1.0'

在dagger的依赖项描述之前

在我的案例中添加
version=“2.0.0


数据绑定{
启用=真
version=“2.0.0”
}


ubarua123AlokBansal8所述,解决了
NoSuchMethodError
尝试删除.idea、.build文件夹并使Android Studio无效并重新启动
kapt'com.Android.databinding:compiler:2.1.0-beta3'
。尝试清理和重建应用程序在那之后。@Michael是的,正如我上面提到的,我已经尝试添加了它,但是我得到了一个java.lang.NoSuchMethodError。是的,我知道。我的意思是有必要在
build.gradle
中包含这一行。好的,我会保留它,但是有解决NoSuchMethodError的方法吗?