Tony
Tony

Reputation: 2451

ClassNotFoundException: Didn't find class "androidx.work.Worker" on path: DexPathList

I have been trying to make an android library, whenin I'm making use of WorkManager's PeriodicWorkRequest. It works flawlessly as a module in the host development app. However, once I export it as an aar file and use it in another app, I get the following error,

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/work/Worker;
.
.
.
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.work.Worker" on path: DexPathList[[zip file "/data/app/com.example.testapp-0WusKIYjC1qsHRMASLjm1Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.testapp-0WusKIYjC1qsHRMASLjm1Q==/lib/arm64, /system/lib64, /vendor/lib64]]

Any idea how I can fix this?

Upvotes: 2

Views: 4345

Answers (2)

ianhanniballake
ianhanniballake

Reputation: 199805

An AAR by itself does not embed or otherwise encode anything about the transitive dependencies (such as your AAR's dependency on WorkManager), so it is expected that if you're just using an AAR as a local binary dependency that you'd need to redeclare all of the transitive dependencies.

As per the Gradle Declaring Dependencies documentation, a proper dependency is in the form of a maven repository (either local or remote). A maven repository, besides hosting the AAR itself, also includes a POM file that declares the transitive dependencies your library depends on. This ensures that there's only one version of each library included in your build (as it can deduplicate transitive dependencies across multiple libraries).

You don't see this same issue when locally using a project since those transitive dependencies are included as part of the build process.

Upvotes: 6

ismail alaoui
ismail alaoui

Reputation: 6073

you have a dependency error , the app your are trying to use your library use androidx support library , try to change WorkManager's dependency to androidx dependency

Upvotes: 0

Related Questions