Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin 1.5.0 does not work with Dagger 2?

I have a very simple Dagger code as below

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)
}

With plugin as

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

and dependencies as below

    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'

Where kotlin_version is 1.4.32. It compiles fine.

However when I migrate to kotlin_version = "1.5.0", it just errors out stating

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)

without any further detail.

What causes this issue? and how can it be resolved?

like image 595
Elye Avatar asked May 06 '21 09:05

Elye


People also ask

Does dagger work with Kotlin?

Dagger is implemented using Java's annotations model. It generates code at compile-time using an annotation processor. Annotation processors are supported in Kotlin with the kapt compiler plugin. They are enabled by adding id 'kotlin-kapt' to the top of the file below the id 'kotlin-android-extensions' line.

Is Kotlin 1.5 stable?

The Android Kotlin compiler produces Java 8 bytecode by default (which runs in any later JVM), but lets the programmer choose to target Java 9 up to 18, for optimization, or allows for more features; has bidirectional record class interoperability support for JVM, introduced in Java 16, considered stable as of Kotlin ...

What is dagger 2 Android Kotlin?

What is Dagger2? Dagger2 is a static compile-time dependency injection Framework for Java,Kotlin and Android. It should actually be Dagger, Dagger2 simply implies the second version which was a complete re-write of the DI framework. The earlier version was created by Square. Dagger2 is now maintained by Google.

What is the latest version of Kotlin?

Kotlin 1.6. 0 is now officially released with Stable exhaustive whens, Kover, and new memory manager for Kotlin/Native!


1 Answers

You can get more detail by invoking gradle with --stacktrace.

This seems to be an issue that was fixed in dagger 2.34. The newest release is 2.35.1.

like image 119
laalto Avatar answered Oct 20 '22 16:10

laalto