简体   繁体   English

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

[英]Unable to Run Kotlin App- Execution failed for task ':app:kaptDebugKotlin'

I keep running my app and it keeps showing the error below:我继续运行我的应用程序,它一直显示以下错误:

    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)

The app won't launch on my phone.该应用程序无法在我的手机上启动。 I have tried to clean the project and running ./gradlew clean but still getting the same error.我试图清理项目并运行 ./gradlew clean 但仍然遇到相同的错误。 The app builds successfully but can't run it.应用程序构建成功,但无法运行。 Below is my project level gradle file:下面是我的项目级 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
}

Below is my app level gradle file:以下是我的应用程序级 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
}

The issue is that you are using different versions for dagger-android & dagger-processor causing the kapt issue.问题是您使用不同版本的 dagger-android 和 dagger-processor 导致 kapt 问题。

Try using this:尝试使用这个:

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'

Or if you need to upgrade you dagger version, try using their upgrade guide from here Dagger 2 Releases or upgrade to Dagger Hilt.或者,如果您需要升级匕首版本,请尝试使用Dagger 2 Releases中的升级指南或升级到 Dagger Hilt。

I had this issue while upgrading Kotlin version to 1.7.0我在将 Kotlin 版本升级到 1.7.0 时遇到了这个问题

Fix - updated the dagger version to latest version - 2.42修复 - 将匕首版本更新到最新版本 - 2.42

implementation "com.google.dagger:dagger:2.42”实施“com.google.dagger:dagger:2.42”

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

To find latest dagger versions - https://github.com/google/dagger/releases查找最新的匕首版本 - https://github.com/google/dagger/releases

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 kotlin + dagger 2:任务':app:kaptDebugKotlin'的执行失败 - kotlin + dagger 2 : Execution failed for task ':app:kaptDebugKotlin' Kotlin 任务“:app:kaptDebugKotlin”执行失败 - Kotlin Execution failed for task ':app:kaptDebugKotlin' 任务 ':app:kaptDebugKotlin' 执行失败 - Execution failed for task ':app:kaptDebugKotlin' 任务“:app:kaptDebugKotlin”执行失败。 > - Execution failed for task ':app:kaptDebugKotlin'. > 带有Dagger2&Databinding的Kotlin发生:任务':app:kaptDebugKotlin'的执行失败 - Kotlin with Dagger2&Databinding occur : Execution failed for task ':app:kaptDebugKotlin' 错误:任务 ':app:kaptDebugKotlin' 执行失败 - Error:Execution failed for task ':app:kaptDebugKotlin' Dagger 2错误任务':app:kaptDebugKotlin'的执行失败 - Dagger 2 error Execution failed for task ':app:kaptDebugKotlin' 任务':app:kaptDebugKotlin'的错误MyApplication执行失败 - Error MyApplication Execution failed for task ':app:kaptDebugKotlin' 任务 ':app:kaptDebugKotlin' 执行失败。 > 执行 org.jetbrains.kotlin.gradle.internal.KaptExecution 时发生故障 - Execution failed for task ':app:kaptDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution 任务 ':app:kaptDebugKotlin' 执行失败。 当干净的构建 - Execution failed for task ':app:kaptDebugKotlin'. when clean build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM