Android 景观客房 - Kotlin Gradle 找不到 DSL 方法:'kapt()'



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

找不到 Gradle DSL 方法:"kapt((" 可能的原因:项目 "Kotlin First Class"可能使用的是Android Gradle的一个版本 不包含该方法的插件(例如,添加了"testCompile" 在 1.1.0 中(。将插件升级到版本 3.5.3 并同步项目

"Kotlin First Class"项目可能正在使用 Gradle 的一个版本 不包含该方法。打开 Gradle 包装器文件

构建文件可能缺少 Gradle 插件。应用 Gradle 插件

#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'

最新更新