3

I tried to implement the WorkManager API in one of my projects. The app compiles successfully, but when I try to execute some work using WorkManager, it throws the below runtime error:
Runtime Error
Failed resolution of: Landroidx/work/impl/utils/futures/AbstractFuture;

What I know of this error is that it occurs when some class that was available during compile time isn't available during runtime. But this doesn't seem to be the case with me, as when I decompiled my APK, all the necessary classes (including androidx.work.impl.utils.futures.AbstractFuture) were present there! I tried version 2.3.4, 2.4.0, and 2.5.0_Alpha01 of the work-runtime library, but none of them seemed to work. It'd be really helpful if someone could help me solve this issue. =)


Note: FYI, the project I'm working on is very old, and unfortunately, it still uses Apache Ant. Also, it won't be easy for us to migrate to Gradle anytime soon as it'll affect the whole architecture and take a huge amount of time. So, any solution suggesting changes in build.gradle won't be quite helpful. :)


EDIT: In case anyone needs to see the ADB log:

...
09-05 20:47:01.536 25688 25688 W System.err: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/work/impl/utils/futures/AbstractFuture;
09-05 20:47:01.536 25688 25688 W System.err:    at androidx.work.WorkManager.initialize(WorkManager.java:210)
09-05 20:47:01.536 25688 25688 W System.err:    at androidx.work.impl.WorkManagerInitializer.onCreate(WorkManagerInitializer.java:40)
09-05 20:47:01.537 25688 25688 W System.err:    at android.content.ContentProvider.attachInfo(ContentProvider.java:2102)
09-05 20:47:01.537 25688 25688 W System.err:    at android.content.ContentProvider.attachInfo(ContentProvider.java:2076)
09-05 20:47:01.537 25688 25688 W System.err:    at android.app.ActivityThread.installProvider(ActivityThread.java:7430)
09-05 20:47:01.537 25688 25688 W System.err:    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6934)
09-05 20:47:01.537 25688 25688 W System.err:    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6851)
09-05 20:47:01.537 25688 25688 W System.err:    at android.app.ActivityThread.access$1600(ActivityThread.java:242)
09-05 20:47:01.537 25688 25688 W System.err:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
09-05 20:47:01.537 25688 25688 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:107)
09-05 20:47:01.537 25688 25688 W System.err:    at android.os.Looper.loop(Looper.java:227)
09-05 20:47:01.537 25688 25688 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:7822)
09-05 20:47:01.537 25688 25688 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
09-05 20:47:01.537 25688 25688 W System.err:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
09-05 20:47:01.537 25688 25688 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026)
09-05 20:47:01.537 25688 25688 W System.err: Caused by: java.lang.ClassNotFoundException: androidx.work.impl.utils.futures.AbstractFuture
09-05 20:47:01.537 25688 25688 W System.err:    ... 15 more
...

2 Answers2

3

I fixed a similar issue today where the issue was actually a missing ListenableFuture, even though the exception head looked the same as yours.

I had added this to my build file previously:

implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'

I did this to avoid a class duplication error, since Guava was imported from elsewhere (also see this question). After that dependency stopped depending on Guava, the import that previously fixed an issue now caused an issue itself. Removing it again fixed the problem.

Namnodorel
  • 385
  • 5
  • 17
  • Thanks for your answer. Although, it didn't work for me. Now I get this error: `java.lang.NoClassDefFoundError: androidx.work.impl.utils.futures.SettableFuture`. – Shreyash Saitwal Nov 03 '20 at 17:40
  • I don't have much experience with using a non-Gradle build system for Android, but I think in any case it would be useful if you could share more details about what gets imported and how. – Namnodorel Nov 03 '20 at 21:08
  • I'm sorry, I didn't quite understand your question. What do you exactly mean by "what gets imported and how"? If you mean what libraries I'm using, it's everything that `androidx.work-runtime` depends on, plus a lot of other external dependencies required by the project. This project ain't an Android app instead, it's an open-source no-code app development platform maintained by MIT. Here's the link to it's GitHub repo: https://github.com/mit-cml/appinventor-sources – Shreyash Saitwal Nov 04 '20 at 15:34
1

I have faced the similar issue. This happens on dependency conflict.I'm sharing what I have done to resolve this. Using this dependency "implementation 'com.google.guava:guava:28.2-android" and make sure to remove this in build.gradle

      configurations.all {
            resolutionStrategy {
                exclude group: 'com.google.guava', module: 'listenablefuture'
            }
        }