我面临的问题已经超过3天了,我无法解决。自从我开始为安卓使用Kotlin,我停止使用"annotationProcessor“并开始使用" kapt ",所有的事情都在使用kapt,直到我开始构建一个Android,当我将"kapt”添加到任何依赖项中,比如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.这是我的项目分级文件
项目分级文件
// 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
}app模块级文件
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')
}基本模块级文件
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'
}特征模块分级文件
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'
}实例化分级文件
apply plugin: 'com.android.instantapp'
dependencies {
implementation project(':feature')
implementation project(':base')
}==========
解决了
将kotlin-android插件添加到基本模块中。
apply plugin: 'kotlin-android'发布于 2020-03-31 15:53:33
在我的案子里,我失踪了
apply plugin: 'kotlin-kapt'希望它能帮助像我这样的盲人。
发布于 2021-02-09 07:39:52
这是一个最新版本的android的工作解决方案,而不是应用插件,使用id 'kotlin-kapt'内置插件。
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
} 发布于 2022-03-19 19:36:37
以防有人与/Room库作斗争
我尝试了以上所有的技巧,但没有任何帮助,除非我改变了这个悲惨的:
ksp("androidx.room:room-compiler:$roomVersion")转入:
annotationProcessor("androidx.room:room-compiler:$roomVersion")起初,我也改变了:
val roomVersion = "2.4.2"转入:
def roomVersion = "2.4.2"这个终于完成了任务!
https://stackoverflow.com/questions/53823451
复制相似问题