Kotlin 1.5.0 不适用于 Dagger 2?
Kotlin 1.5.0 does not work with Dagger 2?
我有一个非常简单的 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_version
是 1.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)
没有任何进一步的细节。
导致此问题的原因是什么?以及如何解决?
您可以通过调用 gradle 和 --stacktrace
来获取更多详细信息。
这似乎是在 dagger 2.34 中修复的 issue。最新版本是 2.35.1.
我有一个非常简单的 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_version
是 1.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)
没有任何进一步的细节。
导致此问题的原因是什么?以及如何解决?
您可以通过调用 gradle 和 --stacktrace
来获取更多详细信息。
这似乎是在 dagger 2.34 中修复的 issue。最新版本是 2.35.1.