How to deal with "Duplicate class error" correctly

Viewed 55

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

0 Answers
Related