CodexBloom - Programming Q&A Platform

Uncaught IllegalArgumentException When Using WorkManager with One-Time Work Request in Android 14

πŸ‘€ Views: 0 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-15
android workmanager kotlin android-14 error Kotlin

I'm a bit lost with I can't seem to get I tried several approaches but none seem to work. I'm working with an `IllegalArgumentException` when trying to enqueue a one-time work request using WorkManager in my Android 14 application. The behavior message states, **"The task want to be run because the input data is invalid"**. I've verified that I'm passing a valid `Data` object to the `OneTimeWorkRequest`, but I need to pinpoint what might be going wrong. Here’s a snippet of my code: ```kotlin val workData = Data.Builder() .putString("input_key", "input_value") .build() val myWorkRequest = OneTimeWorkRequestBuilder<MyWorker>() .setInputData(workData) .build() WorkManager.getInstance(context).enqueue(myWorkRequest) ``` My `MyWorker` class looks like this: ```kotlin class MyWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { override fun doWork(): Result { val inputData = inputData.getString("input_key") // Perform the task using inputData return Result.success() } } ``` I've tried cleaning and rebuilding the project, as well as invalidating caches in Android Studio, but the scenario continues. Additionally, I've checked that the required dependencies for WorkManager are included in my `build.gradle`: ```gradle dependencies { implementation "androidx.work:work-runtime-ktx:2.7.1" } ``` I'm unsure if there are specific configurations required in Android 14 that might affect WorkManager. Has anyone experienced similar issues or can provide insights into what might be causing this behavior? This is part of a larger CLI tool I'm building. Am I missing something obvious? My development environment is Ubuntu 22.04. Has anyone else encountered this? I'm working on a service that needs to handle this. Is there a better approach? The stack includes Kotlin and several other technologies. Is there a simpler solution I'm overlooking?