Execution failed for task ':app:checkDebugDuplicateClasses'. Ionic4 Android - android

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…

Related

Android Studio Chipmunk duplicate class error

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 com.google.zxing.Binarizer found in modules jetified-com.google.zxing.client.android.captureactivity.jar and jetified-core-3.3.3.jar

So I tried running ionic cordova run android but I get a build failed with an exception.
Duplicate class com.google.zxing.Binarizer found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.BinaryBitmap found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.ChecksumException found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.DecodeHintType found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.EncodeHintType found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.FormatException found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.LuminanceSource found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.MultiFormatReader found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.MultiFormatWriter found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.MultiFormatWriter$1 found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.NotFoundException found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.PlanarYUVLuminanceSource found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.RGBLuminanceSource found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
Duplicate class com.google.zxing.Reader found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
And the list goes on and finishes with :
Duplicate class com.google.zxing.qrcode.encoder.QRCode found in modules jetified-com.google.zxing.client.android.captureactivity.jar (com.google.zxing.client.android.captureactivity.jar) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
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
Deprecated Gradle features were used in this build, making it
incompatible with Gradle 7.0. Use '--warning-mode all' to show the
individual deprecation warnings. See
https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
Here is my build.gradle file :
buildscript {
ext.kotlin_version = '1.3.50'
apply from: 'repositories.gradle'
repositories repos
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
apply from: 'repositories.gradle'
repositories repos
project.ext {
defaultBuildToolsVersion="29.0.2" //String
defaultMinSdkVersion=22 //Integer - Minimum requirement is Android 5.1
defaultTargetSdkVersion=29 //Integer - We ALWAYS target the latest by default
defaultCompileSdkVersion=29 //Integer - We ALWAYS compile with the latest by default
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I Tried :
Adding : configurations {compile.exclude group: 'com.google.zxing'} to build.gradle
removed the android platform from cordova and then adding it.
removed the barcodescanner plugin then adding it.
I have been stuck with this one for almost a week.
The problem was caused because of a conflict between facebook4 plugin and barcodeScanner plugin. Both use a library called ZXing which will cause a conflict.
The easy fix (hard to find) was to remove the facebook plugin and add the same one without the zxing library.
ionic cordova platform rm android
ionic cordova plugin rm cordova-plugin-facebook4 --save --variable APP_ID="ID" --variable APP_NAME="NAME"
ionic cordova plugin add https://github.com/AndreiTelteu/cordova-plugin-facebook4-no-zxing --save --variable APP_ID="ID" --variable APP_NAME="NAME"
ionic cordova platform add android
ionic cordova platform rm android
This fixed my problem. Note that there is nothing to edit in your code.
Check the git repo for more info: https://github.com/AndreiTelteu/cordova-plugin-facebook4-no-zxing
For me, the solution was to remove implementation files('libs/core.jar') from my build.gradle:
dependencies {
..........
implementation files('libs/core.jar') // Remove this line
implementation 'com.facebook.android:facebook-login:latest.release' // Conflicting with libs/core.jar.
..........
}

Updated firebase dependency and got duplicated protobuf classes error

I'm getting this error after updating one of my firebase SDKs
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 com.google.protobuf.AbstractMessageLite found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractParser found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractProtobufList found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.BooleanArrayList found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.ByteBufferWriter found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
...
My app now depends on protobuf-lite and protobuf-javalite, which triggers the duplicate class error.
Recently, Firebase Android has migrated from depending on the old protobuf-lite to depend on protobuf-javalite (github issue | PR implementing the change).
You need to update all the firebase SDKs affected by this change together, otherwise the old SDKs will pull the wrong dependency into your app.
Here is the list of affected SDKs and their versions supporting protobuf-javalite
- com.google.firebase:firebase-firestore:21.5.0
- com.google.firebase:firebase-inappmessaging:19.1.0
- com.google.firebase:firebase-inappmessaging-display:19.1.0
- com.google.firebase:firebase-config:19.2.0
- com.google.firebase:firebase-abt:19.1.0
- com.google.firebase:firebase-perf:19.0.8
EDIT: Added firebase-perf to the list, as it transitively depends on config and also needs to be updated.
In my case the problem was androidx.security:security-crypto:1.0.0-alpha02 library that depends on protobuf-lite which conflicts with protobuf-java-lite being used by Firebase. Updating this library helped.
You can check if other libraries depend on conflicting protobuf-lite by calling ./gradlew app:dependencies in Terminal. Then cmd+f and search for proto.
This burned me because com.google.android.gms:play-services-cast-framework:17.1.0 through at least com.google.android.gms:play-services-cast-framework:19.0.0 transitively depends on com.google.protobuf:protobuf-lite:3.0.1 through its dependency on com.google.android.datatransport:transport-backend-cct:2.0.1 through com.google.android.datatransport:transport-backend-cct:2.1.0.
Someone from Spotify filed an issue about this: https://issuetracker.google.com/issues/161831470
This error means that you are importing two packages that use Protobuf for your project, one of them has a distribution that's conflicting with the other.
If you encountered this problem on Flutter, you can reconsider the version number of your dependencies in pubspec.yaml, and replace "any" by an exact version number. For example, under "dependencies:" change:
barcode_scan: any
To:
barcode_scan: ^2.0.0
I hope I helped.
try to degrade
implementation 'com.google.firebase:firebase-firestore:21.4.3'
implementation 'com.google.firebase:firebase-config:19.1.4'
It works with
implementation 'androidx.mediarouter:mediarouter:1.1.0'
implementation 'com.google.android.gms:play-services-cast-framework:18.1.0'
For me I just downgraded my com.google.firebase:firebase-firestore:21.5.0 -> com.google.firebase:firebase-firestore:21.4.3
I solved this problem by manually searching in the Gradle dependency tree and updating the problematic SDK afterward.
For Android, use this line
gradle app:dependencies > dependency_tree.txt
or if you have a gradle wrapper:
./gradlew app:dependencies > dependency_tree.txt
where app is your project module.
Then manually search for proto for problematic SDK within the dependency_tree.txt file.
The easiest solution just add the boom library for firebase and remove library version for libraries it will resolve the library conflicts
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:29.3.1')
// When using the BoM, you don't specify versions in Firebase library dependencies
// Declare the dependency for the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-analytics'

How to fix "Duplicate class android.support.v4.app.INotificationSideChannel found in modules "

Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-v4:23.4.0)
In your app's build.gradle file, remove references to com.android.support if you are using androidx. Posting your app module's build.gradle file would be helpful if that doesn't work.
Reference:
https://developer.android.com/jetpack/androidx/migrate/artifact-mappings

Duplicate class in modules dagger-1.2.2.jar and dagger-2.22.jar

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'
}

Categories

Resources