Martin
Martin

Reputation: 2914

Android Studio Dolphin 2021.3.1: Error while building project

I just recently upgraded from Arctic Fox to Dolphin and migrated my project from Gradle 7.0.3 to 7.3.0.

When I want to build project I got error:

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.4.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.4.0)
Duplicate class androidx.lifecycle.ViewModelProviderKt found in modules jetified-lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1) and lifecycle-viewmodel-2.4.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.4.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.4.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.4.0)

My entire project is non-usable and broken right now.

Upvotes: 1

Views: 1479

Answers (1)

M Ashhal
M Ashhal

Reputation: 467

This happened with me when I added the androidx.preference.preference-ktx:1.2.0 dependency in gradle.

Just add this dependency in build.gradle file to fix this.

Java -> implementation 'androidx.lifecycle:lifecycle-viewmodel:2.5.1'

Kotlin -> implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'

This error occurs due to one of the dependencies having an explicit dependency of lifecycle 2.3.1.

Google Tracker Issue Link -> https://issuetracker.google.com/issues/242384116

Hope this helps :)

Upvotes: 1

Related Questions