I'm trying to resuscitate an old codebase.
In one of the activities, the enqueue()
call represented in the code snippet below keeps crashing the app:
WorkManager
.getInstance(requireContext())
.enqueue(updateValues) // updateValues is a WorkRequest
Here's the exception:
java.lang.VerifyError: Verifier rejected class androidx.work.impl.OperationImpl: com.google.common.util.concurrent.ListenableFuture androidx.work.impl.OperationImpl.getResult() failed to verify: com.google.common.util.concurrent.ListenableFuture androidx.work.impl.OperationImpl.getResult(): [0x2] can't resolve returned type 'Unresolved Reference: com.google.common.util.concurrent.ListenableFuture' or 'Unresolved Reference: androidx.work.impl.utils.futures.SettableFuture' (declaration of 'androidx.work.impl.OperationImpl' appears in /data/app/~~KoZa3Uwv5hinF_EqVv8JEA==/com.flesson.tutor.uat-YOfhXEvtwlYyJ7ihgXtB_A==/base.apk)
I have:
- Updated the dependency version for WorkManager to
2.8.0-alpha02
which is the latest version - Updated minSdk to 21 (from 19)
- Used JDK 11
- Upgraded TARGET_SDK and COMPILE_SDK to 31
- Upgraded Kotlin version to 1.6.0
- Invalidate cache and restart
..but the crash still persists.
Here's the updateValues
WorkRequest:
private val updateValues: WorkRequest by lazy {
OneTimeWorkRequestBuilder<UpdateValuesWorker>()
.setConstraints(
Constraints
.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
)
.setBackoffCriteria(
BackoffPolicy.EXPONENTIAL,
5,
TimeUnit.MINUTES
)
.build()
}
UpdateValuesWorker
just makes a regular API call.
The solution was a tad weird, I admit.
My first step was to update the dependency versions for WorkManager as well as Coroutines to the latest versions (as stated in the question details). After that, I updated the provider<> tag in my AndroidManifest.xml file from this:
to this:
After that, everything just worked fine.