Duplicate class in protobuf lite and protobuf java - android

I'm using grpc with protobuf lite in android implementation. but protobuf lite doesn't have google time stamp, and my protos has import "google/protobuf/timestamp.proto". so i added implementation 'com.google.protobuf:protobuf-java:3.7.1' to gradle that contains google time stamp. but after that code compilaition has errors. such as :Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1).
any idea to fix this would be appreciated.
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 28
buildToolsVersion "29.0.0"
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
proto {
srcDir 'src/main'
}
java {
srcDir 'src/main'
}
}
}
}
protobuf {
protoc { artifact = 'com.google.protobuf:protoc:3.7.1' }
plugins {
javalite { artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0" }
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.20.0' // CURRENT_GRPC_VERSION
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {}
grpc { // Options added to --grpc_out
option 'lite'
}
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.0.0'
// You need to build grpc-java to obtain these libraries below.
implementation 'io.grpc:grpc-okhttp:1.20.0'
implementation 'io.grpc:grpc-protobuf-lite:1.22.1'
implementation 'io.grpc:grpc-stub:1.20.0'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'com.google.protobuf:protobuf-java:3.7.1'
}
given error is:
Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and 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 protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractParser found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractProtobufList found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.BooleanArrayList found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.ByteBufferWriter found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.ByteOutput found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.ByteString found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.ByteString$1 found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)

The missing classes is a known issue. Full proto and lite proto can't be mixed; they use different generated code. Do not depend on protobuf-java as an implementation dependency, but as a protobuf dependency which will cause gradle-protobuf-plugin to generate code for the .protos.
dependencies {
...
protobuf 'com.google.protobuf:protobuf-java:3.7.1'
}
Note that this solution only really works for an application. If you are a library, it is dangerous because users of your library may then see multiple copied of the generated code for the well-known protos.

It happened to me because I added this dependency:
implementation 'com.google.firebase:firebase-firestore-ktx:21.5.0'
There was a problem with the latest version of firestore. Use version 21.4.2 instead of 21.5.0 as of August 2020.

In my case this happened because of mixed package dependencies specifically barcode_scan
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.

Related

Android Studio showing Duplicate class found

When generating release build android studio throwing below errors. Which i am not able to resolve. I tried many way which related issue mentioned but didn't succeed.
Duplicate class com.google.android.gms.internal.measurement.zzhx found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzmz found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzna found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.internal.measurement.zznb found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.internal.measurement.zznc found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.internal.measurement.zznd found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzga found in modules jetified-play-services-measurement-19.0.0-runtime (com.google.android.gms:play-services-measurement:19.0.0) and jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2)
Duplicate class com.google.android.gms.measurement.internal.zzhe found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzhf found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzhg found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzhh found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzhi found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzhj found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzio found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzit found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
I also added android.useAndroidX=true android.enableJetifier=true inside gradle.properties file.
My build.gradle file looks like below
apply plugin: 'com.android.application'
android {
namespace 'com.pp.prescriptionpatriot'
compileSdkVersion 32
defaultConfig {
applicationId "com.pp.prescriptionpatriot"
minSdkVersion 29
targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir{
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
// Branch: required for all Android apps
implementation 'io.branch.sdk.android:library:5.2.3'
// Branch: required if your app is in the Google Play Store (tip: avoid using bundled play services libs)
implementation 'com.google.firebase:firebase-appindexing:20.0.0' // App indexing
implementation 'com.google.android.gms:play-services-ads:21.2.0' // GAID matching
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation project(':capacitor-android')
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
implementation project(':capacitor-cordova-android-plugins')
implementation 'com.android.support:multidex:1.0.3'
//implementation 'com.google.firebase:firebase-appindexing:19.1.0'
//implementation 'androidx.work:work-runtime:2.7.1'
}
apply from: 'capacitor.build.gradle'
try {
def servicesJSON = file('google-services.json')
if (servicesJSON.text) {
apply plugin: 'com.google.gms.google-services'
}
} catch(Exception e) {
logger.warn("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}
I fixed this replacing below implementation as per #VineshChauhan comment.
From
implementation 'com.google.android.gms:play-services-ads:21.2.0'
To
implementation 'com.google.android.gms:play-services-ads:20.4.0'
In your gradle.properties file, Add below line then rebuild your project.
android.enableJetifier=true

Duplicate class in build.gradle file

I have included following dependencies in build.gradle file. I get the following errors. How to fix them.I have included following dependencies in build.gradle file. I get the following errors. How to fix them.I have included following dependencies in build.gradle file. I get the following errors. How to fix them.I have included following dependencies in build.gradle file. I get the following errors. How to fix them.I have included following dependencies in build.gradle file. I get the following errors. How to fix them.I have included following dependencies in build.gradle file. I get the following errors. How to fix them.
build.gradle:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.testimageuploadhttp"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
def butterKnifeVersion = "8.4.0"
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.jakewharton:butterknife:${butterKnifeVersion}"
annotationProcessor "com.jakewharton:butterknife-compiler:${butterKnifeVersion}"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.annotation:annotation:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:4.10'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
//noinspection DuplicatePlatformClasses,DuplicatePlatformClasses
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
//Volley Library - You need to add this line
implementation 'com.mcxiaoke.volley:library-aar:1.0.0'
//Add this line
implementation 'net.gotev:uploadservice:3.4'
}
error:
Duplicate class org.hamcrest.BaseDescription found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.BaseMatcher found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.CoreMatchers found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Description found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Factory found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Matcher found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.SelfDescribing found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.StringDescription found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.AllOf found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.AnyOf found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.DescribedAs found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.Is found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsAnything found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsEqual found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsInstanceOf found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNot found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNull found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsSame found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.ArrayIterator found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValue found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValueIterator found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Go to the documentation to learn how to Fix dependency resolution errors.
testImplementation 'junit:junit:4.+'
testImplementation 'junit:junit:4.12'
are duplicated, but it is not because of that. I tried commenting out 1. It happens only when I add
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
else things compile fine.
The problem is that the org.hamcrest:hamcrest-core: classes are bundled in Junit also .So to fix the problem follow these steps:---->
----> 1) Click on build and clean the project
clean project
----> 2) add code in buid.gradle
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module('org.hamcrest:hamcrest-core:1.1') with module('junit:junit:4.10')
}
}
So for anyone same problem to fix but can't exclude JUnit.
Well the solution is very pretty simple but very strange
You have duplicated your dependencies. Entries:
testImplementation 'junit:junit:4.+'
testImplementation 'junit:junit:4.12'
Are pointing to the same library

Implementation of library giving duplicate error

im trying to implement the 'com.github.barteksc:android-pdf-viewer:2.8.2' into my project and i am able to sync the gradle files but when i try to start the app it gives me this error
Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.5.0-
runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Go to the documentation to learn how to Fix dependency resolution errors
i do not get why i will post my build.gradle below
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.jenson.resumeapp"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
i do not seem to find anything on this that works?
Add these lines in gradle.properties file
android.useAndroidX = true
android.enableJetifier = true
I was running into the same issue when I was implementing :
com.github.shts:StoriesProgressView:3.0.0
The problem, in my case at least, was that StoriesProgessView dependency was retrieving the same class from com.android.support:support-compat which is now already present in the androidx core package, causing the conflict to rise up.
This is how I went about it:
By checking out the Dependency tree, I found out that the StoriesProgressView was bringing in these dependencies, to remove those dependencies, I added the exlusion rule to the dependency like so:
implementation ('com.github.shts:StoriesProgressView:3.0.0') {
exclude group: "com.android.support", module: "support-compat"
exclude group: "com.android.support", module: "support-media-compat"
}
this stopped pulling the classes from the old package.
In your case though, there doesn't seem to be any third-party dependency so probably following Malik Ali's answer should suffice. If it doesn't, give this one a go!
Add this line in gradle.properties
android.enableJetifier = true

Can't resolve "Duplicate Class com.google.android.gms.internal.vision.zzdt found in module" error,

I saw a similar question asked in here but the solution didn't help me and the error is still same. I tried to make new project, but the error is still the same and I don't what's bugging! Please help me with this error, I can't deploy my app just because of this error.
Here is the error log:
Duplicate class com.google.android.gms.internal.vision.zzdt found in modules jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0) and jetified-play-services-vision-image-labeling-internal-16.0.0-runtime (com.google.android.gms:play-services-vision-image-labeling-internal:16.0.0)
Duplicate class com.google.android.gms.internal.vision.zze found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzf found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzg found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzh found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzi found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzs found in modules jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0) and jetified-play-services-vision-image-labeling-internal-16.0.0-runtime (com.google.android.gms:play-services-vision-image-labeling-internal:16.0.0)
Duplicate class com.google.android.gms.internal.vision.zzt found in modules jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0) and jetified-play-services-vision-image-labeling-internal-16.0.0-runtime (com.google.android.gms:play-services-vision-image-labeling-internal:16.0.0)
Duplicate class com.google.android.gms.internal.vision.zzu found in modules jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0) and jetified-play-services-vision-image-labeling-internal-16.0.0-runtime (com.google.android.gms:play-services-vision-image-labeling-internal:16.0.0)
Duplicate class com.google.android.gms.internal.vision.zzv found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzw found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Go to the documentation to learn how to Fix dependency resolution errors.
Here is my build.gradle(:app) file
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.finalapp"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.firebase:firebase-ml-vision:24.1.0'
implementation 'com.google.firebase:firebase-ml-vision-image-label-model:20.0.2'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
and here is my build.gradle(Final App) file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Lower the version of dependency from 24.1.0 to 24.0.0
implementation 'com.google.firebase:firebase-ml-vision:24.0.0'

Why I'm Getting Duplicate Class When Running My Android Project

I'm in the process of adding a navigation drawer to my app. and I'm getting errors. The app gradle synchs just fine. but when I run the app I get a bunch of duplicate class error. I think it might be because I have conflicting dependencies added and that I'm using v7 28.0.0 and some of the errors mention app: v4. all the examples I've seen online use v7 28.0.0 eventhough I have this in main_activity.xml which uses v4. don't know if it's got something to do with the error. android.support.v4.widget.DrawerLayout
Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$Delegate found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$DelegateProvider found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$SlideDrawable found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat$1 found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat$OnRequestPermissionsResultCallback found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "org.pctechtips.netdroid"
minSdkVersion 21
targetSdkVersion 28
versionCode 8
versionName "1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled = false
signingConfig signingConfigs.config
}
buildTypes {
release {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
/*androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
firebase
implementation 'com.google.firebase:firebase-core:10.2.1'
})*/
// compile 'com.android.support:appcompat-v7:25.3.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
/*google play plugin for adMob*/
implementation 'com.google.android.gms:play-services:10.2.1'
implementation 'commons-net:commons-net:3.6'
implementation 'org.samba.jcifs:jcifs:1.3.3'
}
The exception means, There were duplicated classes in 2 or more different dependencies and the compiler wouldn't be able to distinguish which of them should be used at run-time and the exception was thrown.
Most often, Duplicity happens when you are trying to import modules that carrying their required libraries. (transitive dependencies)
You have to exclude duplicated classes from libraries in the build.gradle.
As Log shows, support-core-ui and support-compat modules have duplicated classes.
apply plugin: 'com.android.application'
android {
...
defaultConfig {
...
}
buildTypes {
...
}
configurations {
all { // You should exclude one of them not both of them
exclude group: "com.android.support", module: "support-core-ui"
exclude group: "com.android.support", module: "support-compat"
}
}
}
Sometimes you don't need to exclude anything and you only need to change the imported module to that one that does not bring its dependencies.
Other situation that causes duplicated classes is when you have added *.jar to the project libs directory. Therefore, You need to delete them if they are not begin used in the project.
project->app->libs->*.jar
I see there are some solutions mentioned using these 2 lines will resolve the problem But if you've migrated to Androidx it would be enabled by default.
android.useAndroidX=true
android.enableJetifier=true
Jetifier is
Jetifier tool migrates support-library-dependent libraries to rely on
the equivalent AndroidX packages instead. The tool lets you migrate an
individual library directly, instead of using the Android gradle
plugin bundled with Android Studio.
And for more information take a look at Exclude transitive dependencies
As an app grows in scope, it can contain a number of dependencies
including direct dependencies and transitive dependencies (libraries
which your app's imported libraries depend on). To exclude transitive
dependencies that you no longer need, you can use the exclude
keyword
If you have problems excluding classes, check this thread: How do I exclude...
See if adding this dependency works:
implementation 'com.android.support:support-v4:28.0.0'
Go to gradle.properties and write these two lines of code:
android.useAndroidX=true
android.enableJetifier=true
Please update com.google.android.gms:play-services to latest version. it wil work.
I tried all above solution, but nothing worked in my case. What worked for me is.
I got this problem resolved by creating a new project with the same project and package name and then copying files from the previous project to new one.

Categories

Resources