找不到 Glide 的方法 kapt()

Could not find method kapt() for Glide

apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

classpath 'com.android.tools.build:gradle:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.61"

我有上面的gradle配置,但我仍然得到

Could not find method kapt() for arguments [com.github.bumptech.glide:compiler:4.3.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

有人能告诉我哪里错了吗?预先感谢您的帮助

我认为 kapt 可用于 Glide 的新版本,因此,尝试添加:

kapt 'com.github.bumptech.glide:compiler:4.8.0'

在您的 Build.gradle 依赖项中 when using Kotlin

注意Glide依赖应该和编译器有相同的版本:

dependencies {
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    kapt 'com.github.bumptech.glide:compiler:4.8.0'
}

或者,尝试将您的 Kotlin 更新为 v1.2.71:

buildscript {

    ext.kotlin_version = '1.2.71'
}


 dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

在根目录 Build.gradle。这应该有效。

项目级build.gradle:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.3.2"
        classpath "com.google.gms:google-services:4.2.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.70"
    }
}

模块级build.gradle:

apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: "kotlin-kapt"
...
android {

} 
dependencies {
    implementation "com.github.bumptech.glide:glide:4.8.0"
    // annotationProcessor "com.github.bumptech.glide:compiler:4.8.0"
    kapt "com.github.bumptech.glide:compiler:4.8.0"
}
...
apply plugin: "com.google.gms.google-services"
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'kotlin-kapt' // add this line in file build.gradle (Module : YourAppName)
}

应用必须在对我有用的插件下

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}
apply plugin: "kotlin-android-extensions"
apply plugin: 'kotlin-kapt'

在另一个build.grandle中:

buildscript {
    ext.kotlin_version="1.4.0"
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.1'
        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
    }
}