Skip to content

❗ Kotlin 2.1.20 + Hilt 2.56.1: Unable to read Kotlin metadata due to unsupported metadata kind: null on CoroutineWorker #4693

Description

@javadjafari1

After updating to Kotlin 2.1.20 and Hilt 2.56.1, I'm getting the following error at compile time:

error: Unable to read Kotlin metadata due to unsupported metadata kind: null. public final class XStatusWorker extends androidx.work.CoroutineWorker {

This happens in a class that uses @HiltWorker with @AssistedInject constructor and also has @Inject lateinit var fields.

import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import javax.inject.Inject

@HiltWorker
internal class XWorker @AssistedInject constructor(
    @Assisted context: Context,
    @Assisted params: WorkerParameters,
) : CoroutineWorker(context, params) {

    @Inject
    internal lateinit var localDataSource: XLocalDataSource

    @Inject
    internal lateinit var remoteDataSource: XRemoteDataSource

    override suspend fun doWork(): Result = withContext(Dispatchers.IO) {
        // ...
    }
}

This setup was working fine with Kotlin 2.0.x and Hilt 2.51+, and it broke only after moving to Kotlin 2.1.20.

Repro info:
Kotlin: 2.1.20

AGP: 8.9.1

Hilt: 2.56.1

By the way Im using Kapt not KSP

Activity

  1. danysantiago commented on Apr 22, 2025

    @danysantiago
    Member

    It seems this issue is coming from androidx's Hilt worker extension. Can you use --stacktrace in Gradle command line to confirm this? What version of androidx.hilt.hilt-compiler are you using?

    If you explicitly depend on androidx.room:room-compiler-processing:2.7.0 does it fix the issue for you?

  2. LouisCAD commented on Apr 23, 2025

    @LouisCAD

    Thank you, @danysantiago, adding kapt("androidx.room:room-compiler-processing:2.7.0") to the dependencies fixed the compilation issue!

    Will check if it runs fine.

  3. javadjafari1 commented on Apr 23, 2025

    @javadjafari1
    Author

    @danysantiago How can I confirm that? What exactly should I look for in the stacktrace?

    I'm using version 1.2.0 of androidx.hilt:hilt-compiler.

    I also tried the workaround suggested by @LouisCAD, but no luck on my end. (I'm using KSP for Room, so I replaced kapt with ksp.)

    For now, I’ve temporarily resolved the compilation issue by downgrading Kotlin to 2.1.10 and KSP to 2.1.10-1.0.30.

  4. ffgiraldez commented on Apr 24, 2025

    @ffgiraldez

    Same issue here.
    I use KSP for room and KAPT for Hilt. Upgrading to Kotlin 2.1.20 breaks the build. I need to use kapt.use.k2=false as a workaround

  5. javadjafari1 commented on Apr 24, 2025

    @javadjafari1
    Author

    Also, I tried setting ksp.useKSP2=false, but the issue remains.

    I’ll try the workaround suggested by @ffgiraldez next and report back.

  6. javadjafari1 commented on Apr 26, 2025

    @javadjafari1
    Author

    @ffgiraldez's workaround worked for me too.

  7. bolebolo commented on Jun 22, 2025

    @bolebolo

    Hi, I had the same issue as you. I was using:

    kapt(libs.hilt.compiler) // for Hilt
    ksp(libs.room.compiler.ksp) // for Room
    

    Versions:

    Room: 2.7.2
    Kotlin: 2.1.21
    KSP: 2.1.21-2.0.1
    WorkManager: 2.10.2
    Hilt Work: 1.2.0
    

    Everything started working properly once I replaced:

    kapt(libs.hilt.compiler)
    with
    ksp(libs.hilt.compiler)

    It took me a while to figure out the issue, but it’s finally resolved.

    If you must use kapt, the solution provided by @ffgiraldez works as well.

    Hope this helps someone in the future!

  8. Antimonit commented on Aug 28, 2025

    @Antimonit

    We fixed this issue by adding kapt(androidx.room:room-compiler-processing:2.7.2) to our scripts.

    AFAIK, androidx.hilt:hilt-work trips up because the androidx.hilt:hilt-compiler processor depends on the room-compiler-processing:2.6.0 at the moment:

    https://github.com/androidx/androidx/blob/b39b0b0dd8222ea87e9176ce3fc8a1166e1cef65/hilt/hilt-compiler/build.gradle#L38


    @danysantiago, would you be so kind as to ping someone to bump the version in hilt-compiler?

    The latest RC version of androidx.hilt does not seem to contain it.

  9. jyotinishad-gmp commented on Dec 2, 2025

    @jyotinishad-gmp

    hi i am very new in android development. currently facing gradle issue when increasing kotlin version from 1.9.0 to 2.1.0 so for this using :-

    1. AGP - 8.5.0
    2. kotlin - 2.1.0
    3. hilt - 2.55
    4. room - 2.6.1
    5. in wrapper - 8.9

    now getting error-

    Execution failed for task ':app:kaptDebugKotlin'.

    A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction

    can anybody help on it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions