0

In my build.gradle (app) I have added this dependency: implementation 'androidx.preference:preference:1.2.0'

When I compile and build my project with the previous dependency these errors are shown:

> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class androidx.lifecycle.ViewModelLazy found in modules jetified-lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1) and lifecycle-viewmodel-2.5.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.0)
     Duplicate class androidx.lifecycle.ViewTreeViewModelKt found in modules jetified-lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1) and lifecycle-viewmodel-2.5.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.0)

I have been searching for information to solve it and adding these both dependencies has solved it but I think that this solution is a botched solution and maybe it can be solved in a really better way.

def lifecycle_version = "2.5.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" 

Does it exist a better solution to solve it? Thanks for the help

Edric
  • 24,639
  • 13
  • 81
  • 91
  • I am not familiar with AndroidX, but it is not at all uncommon for classes to be moved between components during version updates, and you're trying to mix 2.3.1 and 2.5.0. If updating both of those to a consistent version fixes the problem, I see no reason that's a botch. – chrylis -cautiouslyoptimistic- Sep 15 '22 at 22:30
  • Does this answer your question? [Problem duplicate class androidx.lifecycle.viewmodel found in modules](https://stackoverflow.com/questions/69817925/problem-duplicate-class-androidx-lifecycle-viewmodel-found-in-modules) – Edric Sep 22 '22 at 09:02

0 Answers0