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

Open
@javadjafari1

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

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