question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No virtual method setInitialDelay() with WorkManager 2.2.0

See original GitHub issue

Using the latest stable releases of android-job and WorkManager:

implementation 'com.evernote:android-job:1.4.1'
implementation 'androidx.work:work-runtime:2.2.0'

I get this crash when I try to schedule a job:

 Caused by: java.lang.NoSuchMethodError: No virtual method setInitialDelay(JLjava/util/concurrent/TimeUnit;)Landroidx/work/OneTimeWorkRequest$Builder; in class Landroidx/work/OneTimeWorkRequest$Builder; or its super classes (declaration of 'androidx.work.OneTimeWorkRequest$Builder' appears in /data/app/com.youneedabudget.evergreen.app.develop-Kx7Jp9uBEt29bXoJWoCEcw==/base.apk)
    at com.evernote.android.job.work.JobProxyWorkManager.plantOneOff(JobProxyWorkManager.java:50)
    at com.evernote.android.job.JobManager.scheduleWithApi(JobManager.java:244)
    at com.evernote.android.job.JobManager.schedule(JobManager.java:199)
    at com.evernote.android.job.JobRequest.schedule(JobRequest.java:430)

This is the first time I have tried to add the WorkManager dependency, so I don’t know if it worked with older (or non-AndroidX) WorkManager versions. Previously I was just using android-job’s default implementation without WorkManager, and that has always worked fine.

If I remove the WorkManager dependency then everything works.

I am using Jetifier.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
strooookecommented, Oct 10, 2019

I was curious about the binary incompatibility, so took a closer look at that change between 2.0.1 and 2.2.0 - now I believe I’ve understood the issue and would like to share with the class.

Old:

abstract class WorkRequest {
    abstract static class Builder<B extends Builder, W extends WorkRequest> {
    }
}

class OneTimeWorkRequest extends WorkRequest {
   static class Builder extends WorkRequest.Builder<Builder, OneTimeWorkRequest> {
       public @NonNull Builder setInitialDelay(long duration, @NonNull TimeUnit timeUnit) {
          ....
       }
  }
}

New:

abstract class WorkRequest {
    abstract static class Builder<B extends Builder, W extends WorkRequest> {
         public @NonNull B setInitialDelay(long duration, @NonNull TimeUnit timeUnit) {
              ...
         }
    }
}

class OneTimeWorkRequest extends WorkRequest {
   static class Builder extends WorkRequest.Builder<Builder, OneTimeWorkRequest> {
  }
}

i.e., that method in question was pulled up into a super type. That’s fine. But the signature changed: the return type was previously OneTimeWorkRequest.Builder. In the new version, at compile time, it is still known to be exactly that, when called with a OneTimeWorkRequest as receiver. But during compilation, due to type erasure, that type parameter B gets erased to its upper bound: WorkRequest.Builder. So in 2.2.0, there is really no virtual method setInitialDelay(JLjava/util/concurrent/TimeUnit;)Landroidx/work/OneTimeWorkRequest$Builder; to be found on type OneTimeWorkRequest$Builder; it is setInitialDelay(JLjava/util/concurrent/TimeUnit;)Landroidx/work/WorkRequest$Builder; now.

Thanks for making me learn today. https://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html was enlightening.

0reactions
vRallevcommented, Oct 15, 2019

Thanks for confirming.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WorkManager 2.0.1 to 2.1.0 api change "setInitialDelay" when ...
Caused by: java.lang.NoSuchMethodError: No virtual method setInitialDelay(JLjava/util/concurrent/TimeUnit;)Landroidx/work/OneTimeWorkRequest$ ...
Read more >
WorkManager - Android Developers
setForegroundAsync() is called, when the app is subject to foreground service restrictions, this will throw the ForegroundServiceStartNotAllowedException. Bug ...
Read more >
WorkManager long-running work doesn't work specifying ...
The reason is that the work library still rely on the service manifest which has no foregroundServiceType attribute specified (0x00000000) and i'm requesting...
Read more >
OneTimeWorkRequest$Builder.setInitialDelay - Java - Tabnine
setInitialDelay (30, TimeUnit.SECONDS) .build(); WorkManager.getInstance().enqueueUniqueWork("UpdateEpg", ExistingWorkPolicy.REPLACE, updateEpgWorker);.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found