无法运行 Kotlin 应用程序 - 任务":app:kaptDebugKotlin"的执行失败



我继续运行我的应用程序,它一直显示下面的错误:

Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
> java.lang.reflect.InvocationTargetException (no error message)

这个应用程序在我的手机上无法启动。我试图清理项目和运行。/gradlew清洁,但仍然得到相同的错误。应用程序构建成功,但无法运行。下面是我的项目级gradle文件:

buildscript {
ext.kotlin_version = '1.7.0-RC2'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.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()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

下面是我的应用级gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdk 32
defaultConfig {
applicationId "com.schatzdesigns.mobileloanappuiconcept"
minSdkVersion 16
targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
buildToolsVersion '33.0.0 rc2'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.6.0-alpha04'
implementation 'androidx.core:core-ktx:1.9.0-alpha04'
implementation 'com.google.android.material:material:1.7.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.vectordrawable:vectordrawable:1.2.0-beta01'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.0-rc01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
//noinspection LifecycleAnnotationProcessorWithJava8
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.0-rc01'
implementation 'com.google.dagger:dagger:2.35.1'
implementation 'com.google.dagger:dagger-android:2.35.1'
implementation 'com.google.dagger:dagger-android-support:2.16'
kapt 'com.google.dagger:dagger-android-processor:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.5.0-alpha04'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0-alpha07'

}
kapt {
generateStubs = false
}

问题是你使用的是不同版本的dagger-android &dagger处理器导致kapt问题。

试着用这个:

implementation 'com.google.dagger:dagger:2.21'
implementation 'com.google.dagger:dagger-android:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16'
kapt 'com.google.dagger:dagger-android-processor:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'

或者如果你需要升级你的dagger版本,尝试使用他们的升级指南从这里dagger2发布或升级到dagger柄。

我在Kotlin版本升级到1.7.0时遇到了这个问题

修复-将dagger版本更新到最新版本- 2.42

实现"com.google.dagger:dagger:2.42">

kapt"com.google.dagger: dagger-compiler: 2.42">

查找最新的dagger版本- https://github.com/google/dagger/releases

相关内容

最新更新