I am getting the following duplicate class error when I run my Android application (I didn't include all the errors, but the duplicate errors are all coming from org.apache.commons.lang3.* and org.apache.commons.logging.*):
Duplicate class org.apache.commons.lang3.AnnotationUtils found in modules commons-lang3-3.4.jar (org.apache.commons:commons-lang3:3.4) and commons-lang3-3.7.jar (commons-lang3-3.7.jar)
Duplicate class org.apache.commons.lang3.AnnotationUtils$1 found in modules commons-lang3-3.4.jar (org.apache.commons:commons-lang3:3.4) and commons-lang3-3.7.jar (commons-lang3-3.7.jar)
...........
Duplicate class org.apache.commons.logging.impl.WeakHashtable found in modules commons-logging-1.2.jar (commons-logging-1.2.jar) and commons-logging-1.2.jar (commons-logging:commons-logging:1.2)
Duplicate class org.apache.commons.logging.impl.WeakHashtable$1 found in modules commons-logging-1.2.jar (commons-logging-1.2.jar) and commons-logging-1.2.jar (commons-logging:commons-logging:1.2)
Duplicate class org.apache.commons.logging.impl.WeakHashtable$Entry found in modules commons-logging-1.2.jar (commons-logging-1.2.jar) and commons-logging-1.2.jar (commons-logging:commons-logging:1.2)
Duplicate class org.apache.commons.logging.impl.WeakHashtable$Referenced found in modules commons-logging-1.2.jar (commons-logging-1.2.jar) and commons-logging-1.2.jar (commons-logging:commons-logging:1.2)
Duplicate class org.apache.commons.logging.impl.WeakHashtable$WeakKey found in modules commons-logging-1.2.jar (commons-logging-1.2.jar) and commons-logging-1.2.jar (commons-logging:commons-logging:1.2)
The error stems from this line of code in the gradle (I need to use the docx4j library because my app has to read in the contents of MS Word files selected by the user):
implementation "org.docx4j:docx4j:3.3.0"
Below is the complete code of my gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.diffchecker"
minSdkVersion 21
targetSdkVersion 29
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'io.github.java-diff-utils:java-diff-utils:4.5'
// For developers using AndroidX in their applications
implementation 'pub.devrel:easypermissions:3.0.0'
// For developers using the Android Support Library
implementation 'pub.devrel:easypermissions:2.0.1'
implementation 'com.google.android.gms:play-services-ads:18.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation files('libs/commons-text-1.2.jar')
//Thanks for using https://jar-download.com
implementation 'org.webjars.bowergithub.telecomsante:pdf-viewer:2.2.0'
implementation 'com.tom_roush:pdfbox-android:1.8.10.1'
implementation 'com.bskim:maxheightscrollview:1.0.0#aar'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation files('libs/commons-logging-1.2.jar')
implementation files('libs/commons-lang3-3.7.jar')
// Docx4j is the library used to read Word documents
// https://mvnrepository.com/artifact/org.docx4j/docx4j
implementation "org.docx4j:docx4j:3.3.0"
}
How do I use the docx4j library in my gradle without running into duplicate conflicts with the commons-lang3 and commons-logging libraries?
I think I found a similar way of what we did at the beginning but this time with both exclusions.
Try this:
implementation ('org.docx4j:docx4j:3.3.0') {
['org.apache.commons','commons-logging'].each {
exclude group: "$it"
}
}
Erase local lib and put this on the gradle
https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
Related
I upgraded Android studio and gradle to the latest version and also updated all project dependencies to the latest verison. Today, I discovered an error that 2 dupclicate classes exist in gradle dependencies.
I got this error:
Duplicate class androidx.lifecycle.ViewModelLazy found in modules jetified-lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1) and lifecycle-viewmodel-2.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)
I tried to fix the error as suggested on the Android developer's official webiste, but can't seem to fix the error. The fix at here didn't work
I also tried some stackoverflow answers but it didn't fix it for me, some didn't suite my case.
This is my grade file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 33
buildToolsVersion "31.0.0"
defaultConfig {
applicationId "com.astrro.timely"
minSdkVersion 16
targetSdkVersion 33
multiDexEnabled true
versionCode 5
versionName "1.3.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
// changing the default apk build name from app-debug to proper name
applicationVariants.all {
variant ->
variant.outputs.each {
output ->
output.outputFileName = "TimeLY_v${variant.versionName}.apk"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'org.jetbrains:annotations:15.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.appcompat:appcompat-resources:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.fragment:fragment:1.5.5'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.preference:preference:1.2.0'
implementation "androidx.multidex:multidex:2.0.1"
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'com.google.code.gson:gson:2.8.8'
implementation 'com.kevalpatel2106:ringtonepicker:1.2'
implementation 'net.cachapa.expandablelayout:expandablelayout:2.9.2'
implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
implementation 'com.airbnb.android:lottie:3.7.0'
implementation 'com.github.javiersantos:AppUpdater:2.7'
implementation 'me.zhanghai.android.materialprogressbar:library:1.1.6'
implementation ('com.wdullaer:materialdatetimepicker:4.2.3') {
exclude group: 'androidx.appcompat'
exclude group: 'androidx.recyclerview'
}
// debugImplementation because all these dependencies should only run in debug builds.
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
}
}
I'm programming Androidjava application displaying the map. Everything worked fine, until I decided to connect the application to Firebase. I followed the steps to edit the two gradle files.
Top gradle 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:7.2.0'
classpath 'com.google.gms:google-services:4.3.10' // Google Services plugin
// 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
}
App gradle file:
plugins {
id 'com.android.application'
}
apply plugin: 'com.google.gms.google-services' // Google Services plugin
android {
compileSdk 32
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.afs"
minSdkVersion 23
targetSdkVersion 30
versionCode 3163
versionName "3.0.163"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lint {
checkReleaseBuilds false
}
namespace 'com.afs'
}
dependencies {
// Firebase
implementation platform('com.google.firebase:firebase-bom:30.0.2')
implementation 'com.google.firebase:firebase-analytics'
// Play-services
implementation 'com.google.android.gms:play-services-maps:18.0.2'
implementation 'com.google.android.gms:play-services-base:18.0.1'
implementation 'com.google.android.gms:play-services-tasks:18.0.1'
implementation 'com.google.android.gms:play-services-ads:20.6.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'org.osmdroid:osmdroid-android:6.1.10'
implementation 'org.osmdroid:osmdroid-third-party:6.0.1'
implementation 'com.android.support:support-compat:28.0.0'
implementation 'androidx.work:work-runtime:2.7.1'
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Error messages
Duplicate class com.google.android.gms.measurement.AppMeasurement found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-21.0.0-runtime (com.google.android.gms:play-services-measurement-impl:21.0.0)
Duplicate class com.google.android.gms.measurement.AppMeasurement$ConditionalUserProperty found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-21.0.0-runtime (com.google.android.gms:play-services-measurement-impl:21.0.0)
Duplicate class com.google.android.gms.measurement.AppMeasurement$EventInterceptor found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-21.0.0-runtime (com.google.android.gms:play-services-measurement-impl:21.0.0)
Duplicate class com.google.android.gms.measurement.AppMeasurement$OnEventListener found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-21.0.0-runtime (com.google.android.gms:play-services-measurement-impl:21.0.0)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-21.0.0-runtime (com.google.android.gms:play-services-measurement-api:21.0.0)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Event found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-21.0.0-runtime (com.google.android.gms:play-services-measurement-api:21.0.0)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Param found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-21.0.0-runtime (com.google.android.gms:play-services-measurement-api:21.0.0)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$UserProperty found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-21.0.0-runtime (com.google.android.gms:play-services-measurement-api:21.0.0)
Do you have any ideas how I can solve it? I stuck for two days and completely lost ideas of what to change :|
I am encounter a problem when I try to build the Android app and it appear error. The error appear after I add the last line in Gradle Build file (the natural language library).
Below is my gradle build file code
plugins {
id 'com.android.application'
id 'com.google.secrets_gradle_plugin' version '0.5'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myvolunteer"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
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.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-firestore:23.0.3'
implementation 'com.firebaseui:firebase-ui-firestore:8.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.firebase:firebase-database:20.0.2'
implementation 'com.google.firebase:firebase-storage:20.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Import the BoM for the Firebase platform
// Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation 'com.google.firebase:firebase-analytics:19.0.1'
//Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
//Circle Image View
implementation 'de.hdodenhof:circleimageview:3.1.0'
//Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation 'com.karumi:dexter:6.2.3'
implementation 'com.google.android.gms:play-services-location:18.0.0'
//Cloud-lang,but it causes duplicate classes occur.
implementation 'com.google.cloud:google-cloud-language:2.1.2'
}
Some of the error that I get when try to build the project in Android Studio (it's too much I can't put all of them here)
Duplicate class com.google.api.Advice found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
Duplicate class com.google.api.AuthProvider$1 found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
Duplicate class com.google.cloud.audit.AuthenticationInfo$Builder found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
Duplicate class com.google.longrunning.Operation$1 found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
How can I resolve this problem? I really need to add the Google Natural Language library to my app.
Updated: The attempt that I have tried but failed:
Firebase Android: Duplicate Protobuf classes found in modules
Duplicate Class while using firebase and google-cloud-texttospeech
Duplicate classes exception means that one of your dependencies uses implicitly the older or newer (with +) version of some library you also use in your project,
To resolve this issue you may add such block of code (put your library version after 'force') to your build.gradle file (Module:app):
configurations {
all {
resolutionStrategy {
// do not upgrade above 3.12.0 to support API < 21 while server uses
// COMPATIBLE_TLS, or okhttp3 is used in project
force 'com.squareup.okhttp3:okhttp:3.12.0'
force 'com.squareup.okhttp3:logging-interceptor:3.12.0'
}
}
}
You may also exclude some group from your dependencies. For a single dependency you way write:
dependencies {
// example
implementation('log4j:log4j:1.2.15') {
exclude group: 'javax.jms', module: 'jms'
}
}
I added firebase to android. It used to work fine but after pulling from github it shows the errors below:
Duplicate class com.google.android.gms.measurement.AppMeasurement found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.2.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics found in modules classes.jar (com.google.android.gms:play-services-measurement-api:17.2.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Event found in modules classes.jar (com.google.android.gms:play-services-measurement-api:17.2.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Param found in modules classes.jar (com.google.android.gms:play-services-measurement-api:17.2.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$UserProperty found in modules classes.jar (com.google.android.gms:play-services-measurement-api:17.2.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
I tried deleting a few lines in gradle file but it doesn't seem to work.
My gradle file is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.agrismart"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.firebaseui:firebase-ui-database:6.0.2'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation'com.google.firebase:firebase-auth:18.1.0'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
implementation 'com.google.firebase:firebase-database:19.1.0'
implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.firebase:firebase-client-android:2.4.0'
implementation 'com.google.android.gms:play-services:10.0.1'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
How can I resolve these problems?
Update the following:
implementation 'com.google.firebase:firebase-core:15.0.0'
into this:
implementation 'com.google.firebase:firebase-core:17.2.0'
Remove the following dependency:
implementation 'com.firebase:firebase-client-android:2.4.0'
Since this is used in the old firebase version.
According to the docs:
Note: Don't use the combined play-services target. It brings in dozens of libraries, bloating your application. Instead, specify only the specific Google Play services APIs your app uses.
Therefore remove:
implementation 'com.google.android.gms:play-services:10.0.1'
And use the specific service that you need in the app (Also use the versions found in the following page):
https://developers.google.com/android/guides/setup
I am trying to add ads in the build.gradle. However, it doesn't seem to be working.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "br.com.alessanderleite.catchtheballgame"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-
optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
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.gms:play-services-ads:9.4.0'
}
Error:
Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-v4:23.0.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-v4:23.0.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-v4:23.0.0)
Go to the documentation to learn how to Fix dependency resolution errors.
You are using
implementation 'com.google.android.gms:play-services-ads:9.4.0'
This version uses the support libraries and you can't use androidx and support libraries together.
Use an update version of ads migrated to androidx.
implementation 'com.google.android.gms:play-services-ads:18.2.0'