I searched for a long time on the Internet how to solve this error but did not find it.I tried to do a search as written here, but I did not find anything, maybe because I do not understand how to use it. What is this error? How to solve it? Help me pls. P.S. Any necessary files or additional information I can add.
Duplicate class androidx.lifecycle.DefaultLifecycleObserver found in modules lifecycle-common-2.4.0.jar (androidx.lifecycle:lifecycle-common:2.4.0) and lifecycle-common-java8-2.3.0.jar (androidx.lifecycle:lifecycle-common-java8:2.3.0)
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
android {
dexOptions {
javaMaxHeapSize "4G"
}
}
compileSdkVersion 30
buildToolsVersion "31.0.0"
defaultConfig {
applicationId "com.###.###"
minSdkVersion 26
targetSdkVersion 31
versionCode 20
versionName "2.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
configurations.all {
resolutionStrategy {
force 'androidx.core:core-ktx:1.6.0'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.annotation:annotation:1.3.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'com.google.android.gms:play-services-maps:18.0.1'
implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.0-rc02'
implementation 'androidx.startup:startup-runtime:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation platform('com.google.firebase:firebase-bom:28.4.1')
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.android.gms:play-services-auth:20.0.0'
implementation 'com.google.firebase:firebase-analytics:20.0.2'
implementation 'com.google.firebase:firebase-database:20.0.3'
implementation 'com.google.firebase:firebase-firestore:24.0.0'
implementation 'com.google.firebase:firebase-messaging:23.0.0'
implementation 'com.google.android.play:core:1.10.2'
debugImplementation 'androidx.test:core:1.4.0'
debugImplementation 'androidx.test:monitor:1.5.0'
debugImplementation 'androidx.test.services:storage:1.4.1'
implementation 'com.github.florent37:expansionpanel:1.1.1'
implementation 'org.jsoup:jsoup:1.14.3'
implementation 'androidx.core:core-ktx:1.6.0'
}
CodePudding user response:
Lifecycle operates under a single version constraint - that means that every Lifecycle artifact you are using in your app should have the exact same version number (unfortunately, this is not something that Gradle will enforce for you).
Your error states that one of your dependencies is pulling in a dependency on androidx.lifecycle:lifecycle-common-java8:2.3.0
, which doesn't match the 2.4.0
version you are using of your other Lifecycle dependencies.
Therefore to fix your issue, add a dependency on the 2.4.0 version of lifecycle-common-java8
:
implementation 'androidx.lifecycle:lifecycle-common-java8:2.4.0'