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
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)
This error is caused by duplication of dependencies
To solve the same:
You must open Gradle Scripts-->build.gradle(Module: YourApp)
Or
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!
Duplicate class kotlinx.android.parcel.IgnoredOnParcel
found in modules kotlin-android-extensions-runtime-1.3.72
org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.3.72)
and kotlin-parcelize-runtime-1.4.20-RC
(org.jetbrains.kotlin:kotlin-parcelize-runtime:1.4.20-RC)
I have removed kotlin-android-extensions and added kotilin-parcelize
I found the Answer
The problem was kotlin developers deprecated kotlin-android-extensions and added separate dependencies for each of them like kotilin-parcelize also they shifted the classes from
import kotlinx.android.parcel.Parcelize to kotlinx.parcelize.Parcelize
One of your dependency library is duplicating.
If you want to find the duplication dependency, you can use gradlew from Android Studio Terminal
task ':app:checkDebugDuplicateClasses'
or
you can follow
https://developer.android.com/studio/build/dependencies#resolution_errors
If you want to keep your library after you find it has duplicate references
you can check the following to exclude those
implementation ("duplicate dependency library") {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-reflect")
}
for example:
implementation ("com.daveanthonythomas.moshipack:moshipack:1.0.1") {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-reflect")
}
error like this:
Duplicate class com.google.android.exoplayer2.ui.AspectRatioFrameLayout found in modules jetified-VideoPlayModule-Lite-2.3.61-runtime.jar (com.ycjiang:VideoPlayModule-Lite:2.3.61) and jetified-exoplayer-ui-2.12.1-runtime.jar (com.google.android.exoplayer:exoplayer-ui:2.12.1)
Duplicate class com.google.android.exoplayer2.ui.AspectRatioFrameLayout$1 found in modules jetified-VideoPlayModule-Lite-2.3.61-runtime.jar (com.ycjiang:VideoPlayModule-Lite:2.3.61) and jetified-exoplayer-ui-2.12.1-runtime.jar (com.google.android.exoplayer:exoplayer-ui:2.12.1)
gradle:
implementation 'com.google.android.exoplayer:exoplayer:2.12.1'
implementation 'com.ycjiang:VideoPlayModule:2.3.61'
After upgrading all libraries to androidx and to the latest versions of Firebase libraries
I got error with 2 different versions of dagger java files, link in the error message doesn't work. Problem occurs at step :app:checkDebugDuplicateClasses.
I do not use dagger directly in my code, using
./gradlew app:dependencies
I found what com.google.android.gms:play-services-cast-framework:17.1.0 uses com.google.dagger:dagger:2.22, but no info about 1.2.2.
Cause 1: java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class dagger.Lazy found in modules dagger-1.2.2.jar (dagger-1.2.2.jar) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class dagger.MembersInjector found in modules dagger-1.2.2.jar (dagger-1.2.2.jar) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class dagger.Module found in modules dagger-1.2.2.jar (dagger-1.2.2.jar) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class dagger.Provides found in modules dagger-1.2.2.jar (dagger-1.2.2.jar) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class javax.inject.Inject found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Duplicate class javax.inject.Named found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Duplicate class javax.inject.Provider found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Duplicate class javax.inject.Qualifier found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Duplicate class javax.inject.Scope found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Duplicate class javax.inject.Singleton found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Go to the documentation to learn how to Fix dependency resolution errors.
The easiest way is to analyze dependencies.
SOLUTION #1 (console only)
Run in console:
./gradlew -q dependencies app:dependencies
After receiving list of dependencies in the console, go to Analyze part (below Solution #2).
SOLUTION #2 (generate html)
1) Add plugin to generate report
In to app/build.gradle (this with compileSdkVersion, targetSdkVersion or buildTypes), at the top add:
apply plugin: 'project-report'
near one of them:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
which are on top.
2) Generate report
Just from the console run:
./gradlew htmlDependencyReport
or from Android Studio
Tasks > other > htmlDependencyReport
3) Open report
In console you will find URL:
./gradlew htmlDependencyReport
> Task :app:htmlDependencyReport
See the report at: file:///Users/user_name/your_path/project_name/app/build/reports/project/dependencies/index.html
And go to the project ':app'
4) Analyze report
After clicking each of the position there are dependencies:
To expand all of them, you can in develper console such code:
$('#dependencies').html(function(index, html) {
return html.split('style="display: none;"')
.join('style="display: block;"')
.split('<h3 class="closed">')
.join('<h3>')
});
ANALYZE
1) Find old dependencies
In your case you are searching phrase dagger:1
Or in the console:
2) Exlude dependencies
Find in the report library name, and just exclude group from this import.
In your build.gradle (where you have all of dependencies) modify "problematic" library excluding dagger v1.
For example:
implementation("some.old.library.using.dagger1:1.0.0") {
exclude group: 'com.squareup.dagger', module: 'dagger'
}
I'm currently working on an ionic4 application, but recently it stopped working while building the application on an android reall device after adding https://ionicframework.com/docs/native/fcm plugin to the application.
At first it was complaining about fabric key, however I never aimed to use fabric crashlytic on my app.
The error logs:
* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Go to the documentation to learn how to Fix dependency resolution errors.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 21s
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
35 actionable tasks: 5 executed, 30 up-to-date
cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
Go to the documentation to learn how to Fix dependency resolution errors.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 21s
[ERROR] An error occurred while running subprocess cordova.
cordova run android exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
android/app/build.gradle
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' } // Fabrics Maven repository from cordova-plugin-firebase
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:3.4.0+'
classpath 'com.google.gms:google-services:4.2.0' // google-services dependency from cordova-plugin-firebase
classpath 'io.fabric.tools:gradle:1.+' // fabric dependency from cordova-plugin-firebase
}
}
allprojects {
repositories {
jcenter()
google() // Google's Maven repository from cordova-plugin-firebase
}
//This replaces project.properties w.r.t. build settings
project.ext {
defaultBuildToolsVersion="28" //String
defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
defaultTargetSdkVersion=28 //Integer - We ALWAYS target the latest by default
defaultCompileSdkVersion=28 //Integer - We ALWAYS compile with the latest by default
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
cordova-plugin-firebase/raihan-build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0+'
classpath 'com.google.gms:google-services:4.2.0'
}
}
dependencies {
compile 'me.leolin:ShortcutBadger:1.1.4#aar'
compile 'com.google.firebase:firebase-auth:+'
compile('com.crashlytics.sdk.android:crashlytics:2.9.1#aar') {
transitive = true
}
}
cdvPluginPostBuildExtras.add({
// apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
})
cordova-plugin-fcm-with-dependecy-updated/raihan-FCMPlugin.gradle
buildscript {
repositories {
google()
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0+'
classpath 'com.google.gms:google-services:4.2.0'
}
}
repositories {
google()
jcenter()
}
dependencies {
compile 'com.google.firebase:firebase-core:16.0.8'
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
// apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
android/project.properties
target=android-27
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.gradle.include.1=cordova-android-support-gradle-release/raihan-cordova-android-support-gradle-release.gradle
cordova.system.library.1=com.squareup.okhttp3:okhttp-urlconnection:3.10.0
cordova.system.library.2=com.android.support:support-v4:24.1.1+
cordova.system.library.3=com.soundcloud.android:android-crop:1.0.0#aar
cordova.system.library.4=com.google.firebase:firebase-core:16.0.8
cordova.system.library.4=com.google.firebase:firebase-iid:17.1.1
cordova.system.library.5=com.google.firebase:firebase-messaging:17.5.0
cordova.gradle.include.2=cordova-plugin-fcm-with-dependecy-updated/raihan-FCMPlugin.gradle
cordova.gradle.include.3=cordova-support-google-services/raihan-build.gradle
cordova.system.library.6=com.google.firebase:firebase-auth:16.2.0
cordova.system.library.6=com.google.firebase:firebase-perf:16.2.4
cordova.system.library.7=com.android.support:support-annotations:27.+
cordova.system.library.8=com.android.support:appcompat-v7:23+
cordova.system.library.8=com.google.firebase:firebase-iid:17.1.1
cordova.system.library.8=com.google.android.gms:play-services-tagmanager:16.0.8
cordova.system.library.8=com.google.firebase:firebase-config:16.4.0
cordova.gradle.include.4=cordova-plugin-telerik-imagepicker/raihan-ignorelinterrors.gradle
cordova.gradle.include.5=cordova-plugin-telerik-imagepicker/raihan-androidtarget.gradle
cordova.gradle.include.6=cordova-android-support-gradle-release/raihan-cordova-android-support-gradle-release.gradle
cordova.gradle.include.7=cordova-plugin-firebase/raihan-build.gradle
I have provided the above files, let me know if I need to upload anything else.
Go to gradle.properties(project properties)
Add
android.enableJetifier=true
And also most of time android.useAndroidX=true is present.Check your gradle.properties(Project Properties) and if it does not exist then add
android.useAndroidX=true -> Look Likes This Image
Your project (or one of its sub-projects) is referring to a dependency using a + (plus-sign) at its end, like com.google.firebase:firebase-auth:+, which means, use any higher version when possible, and that newer version is no longer using android.support libraries and instead is using androidx; to fix this issue, either follow the below steps, or, update to androidx by following the other answer.
Steps:
Ensure the ANDROID_HOME environment-variable is set, and then, open a console window (like git-bash, because it keeps the whole command output), and cd into your android directory (for Ionic projects it should be platforms/android).
First, List all dependencies by running below (in git-bash):
./gradlew :app:dependencies
Copy the result into your preferred text-editor, and search for androidx.
If you found something follow below steps, else you are done! (and you do not need to repeat these steps).
Scroll up until you see -> at the end of any line, like for example 16.0.8 -> 19.0.0 or + -> 19.0.0, which both mean that the version was auto-resolved (to something higher than specified by you because of +).
So, set the version down manually:
When possible, in your project find and replace the + sign with a specific version.
Or, force a specific version of the dependencies like mentioned below.
At last, repeat above steps (but instead of step one just clear the console).
To Force specific version of the dependencies add to your root build.gradle something like below (which is what worked for me) but edit and add your own rules (if these do not work for you):
allprojects {
// ...
configurations.all {
resolutionStrategy {
force 'com.google.firebase:firebase-common:17.0.0'
force 'com.google.android.gms:play-services-basement:16.2.0'
force 'com.google.firebase:firebase-iid:16.0.0'
force 'com.google.firebase:firebase-auth:17.0.0'
}
}
}
Simply add below lines into your gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
Note to check, to not repeat any line that already exists (and ensure existing are true).
Finally, just rebuild your project.
But sometimes you may need to manually delete the build folder.
Details
If you want to use androidx-namespaced libraries in a new project, you need to set the compile SDK to Android 9.0 (API level 28) or higher but below "API level 31", and set both of the mentioned Android Gradle plugin flags to true.
android.useAndroidX: When this flag is set to true, the Android plugin uses the appropriate AndroidX library instead of a Support Library. The flag is false by default if it is not specified.
android.enableJetifier: When this flag is set to true, the Android plugin automatically migrates existing third-party libraries to use AndroidX dependencies by rewriting their binaries. The flag is false by default if it is not specified.
I came across the same problem and My solution is as follows :
Go to gradle.properties files
Add these two lines :
android.useAndroidX=true
android.enableJetifier=true
Rebuild your project.
that's it.
Note: If your project already shows this android.useAndroidX=true then Just add android.enableJetifier=true and rebuild your project.
For me, just installing the plugins "cordova-plugin-androidx" and "cordova-plugin-androidx-adapter" solved this problem:
$ ionic cordova plugin add cordova-plugin-androidx
$ ionic cordova plugin add cordova-plugin-androidx-adapter
I had this issue when I migrated to Androidx using the Android Studio feature but at the first time the migration was not successful so each time I tried to compile I ran into this issue.
To resolve this issue, I did the following:
[1] Comment all androidx dependencies in the app bundle.gradle file
[2] Try the Migrate to Androidx. You can see this link in Refactor -> Migrate to Androidx. If the migration was successful, then
[3] Uncomment all androidx dependencies in the app bundle.gradle file
You may clean and build your project again, hopefully this error should disappear.
In my case, I removed this implementation under dependencies section in app level build.gradle file -
implementation 'com.google.android.gms:play-services-ads:19.2.0'
Remove or comment it out!!
I think you kept same tag multiple time in gradle.properties like following
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx4608m
In my Ionic project I needed to remove the line
cordova.system.library.19=com.google.android.gms:play-services-analytics:11.0.1
from my /platforms/android/project.properties to get a build
Experienced the same problem.
add this dependency to your gradle
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
In my case, i was creating a separate module and importing firebaseAnalytics into that module but it turns out that adding dependency on main module from IDE help caused the issue of duplicate class found.
i removed the dependency and injected it directly, that solved the problem.
hope that helps.
I had the same problem but I solved it as below.
implemetation code in build.gradle
def lifecycle_version = "2.4.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
Confirmed in this article
The issue I was facing was in the react-native something similar to
Execution failed for task ':app:checkDebugDuplicateClasses'.
1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.0.jar (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.6.21.jar (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21)
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules jetified-kotlin-stdlib-1.8.0.jar (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.6.21.jar (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21)
It means that there is a conflict between two different versions of the Kotlin standard library, specifically the "jetified-kotlin-stdlib-1.8.0.jar" and "jetified-kotlin-stdlib-jdk8-1.6.21.jar" versions. The error message specifically states that there is a duplicate class "kotlin.collections.jdk8.CollectionsJDK8Kt" found in both versions.
and the solution was here
there were two approaches but i found this one easier go to android/app/build.gradle and update the dependencies
dependencies {
constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
}
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
}
}
I had the same problem but i solved it as below.
Open Android studio>
File > Invalidate Caches/Restart…