匕首2错误执行失败了任务':app:kaptdebugkotlin'

发布于 2025-02-13 12:52:59 字数 3281 浏览 0 评论 0 原文

任何人都可以帮助我,IAM仍在使用匕首学习Android和DI,然后尝试用匕首实现简单的概念,但我发现任务失败了执行失败':app:kaptdebugkotlin',有完整的错误日志。


FAILURE: Build failed with an exception.

* What went wrong:
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)

GIST中的完全错误 https://gist.github.com/masdikaid/7ff6d03338aa2c16d377703fa4db8b98

具有这样的组件:

,我刚刚实现了简单的概念车和引擎, 此类仅取决于引擎类,只有运行方法。

class Car @Inject constructor(private val engine: Engine) {
    private val TAG: String = "Car"

    fun run() {
        engine.start()
        Log.i(TAG, "Car Run ...")
    }
}

Engine.kt 引擎类只是具有启动方法的简单类。

class Engine @Inject constructor() {
    private val TAG = "Engine"
    fun start() {
        Log.i(TAG, "Engine Start")
    }
}

carcomponent.kt CAR组件仅使用GetCar方法简单组件。


@Component(modules = [AndroidSupportInjectionModule::class])
interface CarComponent {
    fun getCar(): Car
}

我的 gradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
    id 'kotlin-kapt'
    id 'kotlin-android'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.mdidproject.movupapp"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

//    firebase
    implementation 'com.google.firebase:firebase-auth-ktx:21.0.6'
    implementation 'com.google.firebase:firebase-analytics-ktx:21.0.0'

//    dagger
    implementation "com.google.dagger:dagger-android:2.35.1"
    implementation "com.google.dagger:dagger-android-support:2.17"
    kapt "com.google.dagger:dagger-android-processor:2.17"
    kapt "com.google.dagger:dagger-compiler:2.27"

//    testing
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

,当我重建项目时,我坚持执行任务失败':app:kaptdebugkotlin'错误。

我尝试过替换kapt com.google.google.google.dagger:匕首android处理器:2.17 com.google.dagger.dagger.dagger.dagger:dagger-compiler:2.27 带有AnnotationProcessor,错误已消失但是DaggerAppComponent并未生成,我该怎么办来解决此问题。

感谢您的进步,

Anyone can help me please, iam still learning android and DI in android with dagger and just try implement the simple concept with dagger but i found the error Execution failed for task ':app:kaptDebugKotlin' and there is the complete error log.


FAILURE: Build failed with an exception.

* What went wrong:
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)

complete error in gist https://gist.github.com/masdikaid/7ff6d03338aa2c16d37703fa4d0b8b98

And i just implement simple concept car and engine with component like this :

Car.kt
this class just depend on engine class and only have run method.

class Car @Inject constructor(private val engine: Engine) {
    private val TAG: String = "Car"

    fun run() {
        engine.start()
        Log.i(TAG, "Car Run ...")
    }
}

Engine.kt
engine class just the simple class that have start method.

class Engine @Inject constructor() {
    private val TAG = "Engine"
    fun start() {
        Log.i(TAG, "Engine Start")
    }
}

CarComponent.kt
car componet just simple component with getCar method.


@Component(modules = [AndroidSupportInjectionModule::class])
interface CarComponent {
    fun getCar(): Car
}

myGradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
    id 'kotlin-kapt'
    id 'kotlin-android'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.mdidproject.movupapp"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

//    firebase
    implementation 'com.google.firebase:firebase-auth-ktx:21.0.6'
    implementation 'com.google.firebase:firebase-analytics-ktx:21.0.0'

//    dagger
    implementation "com.google.dagger:dagger-android:2.35.1"
    implementation "com.google.dagger:dagger-android-support:2.17"
    kapt "com.google.dagger:dagger-android-processor:2.17"
    kapt "com.google.dagger:dagger-compiler:2.27"

//    testing
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

and when i rebuild the project i stuck with Execution failed for task ':app:kaptDebugKotlin' error.

i had try replace kapt com.google.dagger:dagger-android-processor:2.17 and com.google.dagger:dagger-compiler:2.27 with annotationProcessor and error is gone but DaggerAppComponent not generated, what should i do for fix this.

Thanks for advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一束光,穿透我孤独的魂 2025-02-20 12:52:59

最后,我在堆栈溢出和为我工作中发现了这个问题,谢谢

finally i found that question in stack overflow and work for me, thanks

Cannot find DaggerAppComponent inside Application class

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文