找不到参数的方法kapt()



我现在正在面临3天以上的问题,我无法解决。自从我开始使用Kotlin作为Android,我停止使用" AnnotationProcessor"并开始使用" Kapt",所有的事情都与Kapt一起工作,直到我开始构建Android Instant App,当我将" Kapt"添加到任何依赖性时,例如Glide,例如Glide或Butterknife Gradle总是显示出错误的错误,找不到方法Kapt()

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

这是我的项目gradle文件

项目gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.2.71'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.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
    }
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

应用模块Gradle文件

apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.demo.instantapptest.app"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

    }
    buildTypes {
       release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
       }
    }
}
dependencies {
    implementation project(':feature')
    implementation project(':base')
}

基本模块gradle文件

apply plugin: 'com.android.feature'
apply plugin: 'kotlin-kapt'
android {
    compileSdkVersion 28
    baseFeature true
    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    api 'com.android.support:appcompat-v7:28.0.0'
    api 'com.android.support.constraint:constraint-layout:1.1.3'
    application project(':app')
    feature project(':feature')

    implementation "android.arch.lifecycle:extensions:1.1.1"
    kapt "android.arch.lifecycle:compiler:1.1.1"
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    kapt 'com.github.bumptech.glide:compiler:4.7.1'
    implementation 'com.google.dagger:dagger:2.15.0'
    kapt 'com.google.dagger:dagger-compiler:2.15.0'
    implementation 'com.jakewharton:butterknife:9.0.0-rc2'
    kapt 'com.jakewharton:butterknife-compiler:9.0.0-rc2'
}

功能模块gradle文件

apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation project(':base')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

instantapp gradle文件

apply plugin: 'com.android.instantapp'
dependencies {
    implementation project(':feature')
    implementation project(':base')
}

===========

已解决

通过将kotlin-android插件添加到基本模块

apply plugin: 'kotlin-android'

在我的情况下,我缺少

apply plugin: 'kotlin-kapt'

这是最新版本Android Studio的工作解决方案而不是应用插件在插件中使用id 'kotlin-kapt'

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
} 

如果任何人都在与 Room Library 挣扎:

我尝试了上述所有技巧,除非我改变了这种痛苦:

ksp("androidx.room:room-compiler:$roomVersion")

进入:

annotationProcessor("androidx.room:room-compiler:$roomVersion")

首先,我也更改了:

val roomVersion = "2.4.2"

进入:

def roomVersion = "2.4.2"

这最终完成了工作!

我试图在Android项目中添加房间库时遇到了同样的错误。截至2022年8月17日,我可以解决 build.gradle(:app)的线路下方的问题。

插件中

id 'kotlin-kapt'

依赖项 block中,我添加了;

def room_version = "2.4.3"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// To use Kotlin annotation processing tool (kapt)
kapt "androidx.room:room-compiler:$room_version"

这样做,我可以对"找不到参数的方法Kapt()说再见。希望有人可以节省一些时间阅读这篇文章。

,所以您也忘记了添加

apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

在应用程序级别Gradel文件中。很好。

Use plugin with this order,
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin:  'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

我面对这个

找不到参数的方法kapt()

错误,当我尝试在项目中添加dagger的依赖项时。这是最新版本的Android Studio的工作解决方案。

plugins {
   id 'com.android.application'
   id 'org.jetbrains.kotlin.android'
   id 'kotlin-kapt'   //Add this line in the plugins block usually seen at the top of build.gradle
}

毫无疑问,人们添加了ksp('androidx.room:室内补偿器:$ roomversion")诽谤而不是kapt('androidx.Room:Room-Compiler:$ Roomervers")

最新更新