0

I am getting the following error when Gradle is set 7.2.2. 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.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1) 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.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1)

This is not in my program but in Android Studio.

How do I correct the problem?

Thanks, Bill

2 Answers2

0

In your build.gradle try adding this:

implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.1"

This worked for me.

I added it but no change.

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.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1)
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.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1)
patrick.elmquist
  • 2,113
  • 2
  • 21
  • 35
CSmith
  • 13,318
  • 3
  • 39
  • 42
-1

This error is caused by duplication of dependencies

To solve the same:

  1. You must open Gradle Scripts-->build.gradle(Module: YourApp)

Or

  1. You can just choose to search the builder:app file in Navigate--> Search Everywhere, type "build.gradle " and choose the option that appears build.gradle (: app)

Inside your build.gradle file it checks which of the implementations made in the dependencies tag was duplicated and deletes one of them. Now

rebuild your app and good work!