【问题标题】:Kotlin 1.5.0 does not work with Dagger 2?Kotlin 1.5.0 不适用于 Dagger 2?
【发布时间】:2021-05-06 09:57:38
【问题描述】:

我有一个非常简单的 Dagger 代码如下

class MainActivity : AppCompatActivity() {
    @Inject
    lateinit var info : Info
    init {
        DaggerMagicBox.create().poke(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

class Info @Inject constructor() {
    val text = "Hello Dagger 2"
}

@Component
interface MagicBox {
    fun poke(mainClass: MainActivity)
}

用插件作为

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

以及以下依赖项

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.dagger:dagger:2.33'
    kapt 'com.google.dagger:dagger-compiler:2.33'

其中kotlin_version1.4.32。它编译得很好。

但是当我迁移到 kotlin_version = "1.5.0" 时,它只是错误地指出

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)

没有任何进一步的细节。

是什么导致了这个问题?以及如何解决?

【问题讨论】:

标签: android kotlin dagger-2


【解决方案1】:

您可以通过 --stacktrace 调用 gradle 来获取更多详细信息。

这似乎是在 dagger 2.34 中修复的issue。最新版本是 2.35.1。

【讨论】:

    猜你喜欢
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 2019-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多