WorkManager 2.3.4 - new lint rule
Asked Answered
C

1

8

I increased the version of my WorkManager to 2.3.4 and there is new lint rule called SpecifyJobSchedulerIdRange with description: "Warn when an app uses JobService but does not specify jobIds for WorkManager." and explanation:

When using JobScheduler APIs directly, WorkManager requires that developers specify a range of JobScheduler ids that are safe for WorkManager to use so the ids do not collide. For more information look at androidx.work.Configuration.Builder.setJobSchedulerJobIdRange(int, int).

I specified the range of ids WorkManager can use by function setJobSchedulerJobIdRange as I should but I still get that lint warning. It's weird that a get that lint warning by my custom JobService and not by the Configuration.Builder.

In my Application class:

override fun getWorkManagerConfiguration(): Configuration {
    return Configuration.Builder()
       .setWorkerFactory(workerFactory)
       .setJobSchedulerJobIdRange(100000, 101000)
       .build()
}
Crocoite answered 6/5, 2020 at 7:42 Comment(3)
Same problems here. Looks like a lint issue.Grinder
Facing the same issue. Was forced to use @SuppressLint("SpecifyJobSchedulerIdRange") on the sevice classLeticia
Did you also remove the default initializer with the merge rule: tools:node="remove" in AndroidManifest? <provider android:name="androidx.work.impl.WorkManagerInitializer" android:authorities="${applicationId}.workmanager-init" tools:node="remove" />Circumlunar
W
1

I came across this issue as well and spent some time looking at the code for the lint issue here, https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/work/workmanager-lint/src/main/java/androidx/work/lint/SpecifyJobSchedulerIdRangeIssueDetector.kt

If Im not mistaken, the lint check looks for all classes which extend JobService, then makes sure that at least 1 of those classes calls androidx.work.Configuration.Builder.setJobSchedulerJobIdRange

I updated my 1 extension of JobService to provide the config as a static method to my application class and this solved the lint issue.

I am not really sure if its really a lint issue or not - it seems weird to have to declare the config for work manager in a JobService class, especially when its the Application class which needs it, but maybe that was their point? Make sure that the class using Job Ids sets it for everyone?

Wheresoever answered 2/11, 2020 at 20:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.