【问题标题】:add kapt androidx room in gradle makes data binding error在 gradle 中添加 kapt androidx room 会导致数据绑定错误
【发布时间】:2019-04-14 07:52:40
【问题描述】:

在我添加kapt "androidx.room:room-compiler:2.1.0-alpha05"之后

我在进行数据绑定时出错。这是我的应用程序:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "insure.onoff"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    // Gradle automatically adds 'android.test.runner' as a dependency.
    useLibrary 'android.test.runner'

    useLibrary 'android.test.base'
    useLibrary 'android.test.mock'
    applicationVariants.all {
        variant ->
            variant.outputs.all {
                outputFileName = "./" + outputFileName
            }
    }
}

dependencies {
    kapt "androidx.room:room-compiler:2.1.0-alpha05"
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.1.0-alpha05'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0'
    implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.room:room-runtime:2.1.0-alpha05'
    implementation 'android.arch.work:work-runtime-ktx:1.0.1-rc01'
    implementation 'android.arch.navigation:navigation-fragment:1.0.0'

    implementation 'org.greenrobot:eventbus:3.1.1'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'

    implementation 'androidx.viewpager:viewpager:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'

    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.google.android.material:material:1.0.0'

    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

    // AWS Dependencies
    implementation "com.amazonaws:aws-android-sdk-core:2.11.1"
    implementation "com.amazonaws:aws-android-sdk-auth-core:2.11.1"
    implementation("com.amazonaws:aws-android-sdk-auth-userpools:2.11.1") { transitive = true }
    implementation("com.amazonaws:aws-android-sdk-auth-ui:2.11.1") { transitive = true }

    implementation 'com.facebook.android:facebook-login:4.36.0'
    implementation "com.google.android.gms:play-services-auth:16.0.1"

    // Testing dependencies
    androidTestImplementation "androidx.arch.core:core-testing:2.0.0"
    androidTestImplementation "androidx.test.espresso:espresso-contrib:3.1.1"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.1.1"
    androidTestImplementation "androidx.test.espresso:espresso-intents:3.1.1"
    androidTestImplementation "androidx.test.uiautomator:uiautomator:2.2.0"
    testImplementation "junit:junit:4.12"

}

项目等级:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.20'
    repositories {
        google()
        jcenter()
        maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

错误:

我的 Android Studio 版本:

Android Studio 3.3
Build #AI-182.5107.16.33.5199772, built on December 25, 2018
JRE: 1.8.0_152-release-1248-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.12.5

【问题讨论】:

    标签: android gradle data-binding android-room android-databinding


    【解决方案1】:

    当您遇到数据绑定错误时,它们通常是代码中编译错误的结果。

    使用您发布的图片作为参考,屏幕左侧的垂直工具栏上有4个图标。顶部图标是绿色锤子。单击其正下方的图标(第二个,它看起来像两个相互叠加的屏幕)。单击此图标将打开一个不同的视图,该视图详细描述了编译器不喜欢的内容 - 您通常会发现导致问题的原因。

    您还可以运行“gradle build -debug”或其他一些用于 gradle 的调试跟踪 cmd,它将详细打印错误是什么。

    仔细检查 kotlin 正在编译到您的目标 jvm 版本 1.8

    如果一切都失败了,请尝试清理/构建 + 无效/缓存 + 重新启动。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-17
      • 1970-01-01
      • 2013-09-23
      • 2013-11-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      相关资源
      最近更新 更多