Android Room with a View - Kotlin Gradle DSL 方法未找到 : 'kapt()'

标签 android gradle kotlin

https://codelabs.developers.google.com/codelabs/android-room-with-a-view-kotlin/index.html?index=..%2F..index#2

Gradle DSL method not found: 'kapt()' Possible causes: The project 'Kotlin First Class' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0). Upgrade plugin to version 3.5.3 and sync project

The project 'Kotlin First Class' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file

The build file may be missing a Gradle plugin. Apply Gradle plugin

#Mon Jan 20 12:01:05 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip




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

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        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()

    }
}

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



ext {
    roomVersion = '2.2.1'
    archLifecycleVersion = '2.2.0-rc02'
    androidxArchVersion = '2.1.0'
    coreTestingVersion = "2.1.0"
    coroutines = '1.3.2'
    materialVersion = "1.0.0"
}





apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.n ame.kotlinfirstclass"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'


    // Room components
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

// Lifecycle components
    implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion"
    kapt "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion"
    androidTestImplementation "androidx.arch.core:core-testing:$rootProject.androidxArchVersion"

// ViewModel Kotlin support
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.archLifecycleVersion"

// Coroutines
    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"

// UI
    implementation "com.google.android.material:material:$rootProject.materialVersion"


    ext {
        roomVersion = '2.2.1'
        archLifecycleVersion = '2.2.0-rc02'
        androidxArchVersion = '2.1.0'
        coreTestingVersion = "2.1.0"
        coroutines = '1.3.2'
        materialVersion = "1.0.0"
    }
}

最佳答案

将此插件添加到 gradle 文件的顶部:

apply plugin: 'kotlin-kapt'

关于Android Room with a View - Kotlin Gradle DSL 方法未找到 : 'kapt()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59819194/

相关文章:

ios - Java FX Gluon移动版

linux - elasticsearch 中的 Gradle 问题

escaping - 当workDir具有空格时,将gradle与Exec任务一起使用

android - 如何在 Android 上使用 Kotlin 将 FrameLayout 替换为 fragment

php - PHP中如何获取某个url请求的最后一个参数

android - 如何结合place autoComplete Fragment和navigation drawer

android - 缩放级别更改时谷歌地图标记大小更改

android - BroadcastReceiver 收不到广播事件消息

arraylist - 根据列表大小在Kotlin中初始化数组

kotlin - Kotlin 中的 HashMap 和 MutableMap 有什么区别