I am working on a multi module Android project. One of the modules which was written previously used Paging library version-2, now I am trying to use the new paging v3 library in another module, but I am getting this error.
Duplicate class androidx.paging.LivePagedListKt found in modules jetified-paging-runtime-ktx-2.1.2-runtime.jar (androidx.paging:paging-runtime-ktx:2.1.2) and paging-runtime-3.0.0-alpha03-runtime.jar (androidx.paging:paging-runtime:3.0.0-alpha03)
The module hierarchy is this way:
app:
/ \
module-A module-B
(uses v2) (uses v3)
I have added dependencies of module A and module B in the app module build.gradle like this
implementation project(path: ':module-A')
implementation project(path: ':module-B')
Is there any way we can use different versions of the same library in the same project, provided that the different versions are used in separate modules.
Solutions tried so far:
I looked through similar answers and added this line in app level build.gradle file
configurations {
runtime.exclude group: 'androidx.paging', module: 'paging-runtime'
}
but still getting the same error.
The snippet:
configurations {
runtime.exclude group: 'androidx.paging', module: 'paging-runtime'
}
would only work if the v2 library was included in the runtime
configuration. You should adjust the configuration for whatever configuration you have the v2 library declared in (implementation
, api
, the deprecated compile
, whatever).
You're probably using implementation
, so try this snippet:
configurations {
implementation.exclude group: 'androidx.paging', module: 'paging-runtime-ktx'
}
with or without -ktx
.
Or use this snippet which should work regardless of the configuration you are using:
configurations.all {
exclude group: 'androidx.paging', module: 'paging-runtime-ktx'
}
Source: https://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html#sec:excluding-transitive-deps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With