簡體   English   中英

在gradle中添加kapt androidx room會導致數據綁定錯誤

[英]add kapt androidx room in gradle makes data binding error

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

我在進行數據綁定時遇到錯誤。 這是我的應用程序gradle:

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"

}

項目gradle:

    // 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

當您獲得數據綁定錯誤時,它們通常是代碼中編譯錯誤的結果。

使用您發布的圖片作為參考,屏幕左側的垂直工具欄上有4個圖標。 頂部圖標是綠色錘子。 單擊下面的圖標(第二個,它看起來像兩個屏幕分層在彼此之上)。 單擊此圖標將打開一個不同的視圖,詳細描述編譯器不喜歡的內容 - 您通常會找到導致問題的原因。

您還可以運行“gradle build -debug”或其他一些用於gradle的調試跟蹤cmd,它將詳細打印錯誤。

雙重檢查kotlin正在編譯你的目標jvm版本1.8

如果所有其他方法都失敗了,請嘗試清理/ build + invalidate / cache + restart。 希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM