Problem compiling to Android 4 after migrating to AndroidX - java

I have an Android (Java) project and after migrating to AndroidX I have received the following error (d8 errors):
Program type already present: com.enterprisedt.BaseIOException
Note that gradle synchronization occurs normally. This error appears only at compile time for the device. And the weirdest thing, it only happens when I'm compiling for an Android 4 device.
When trying to compile for Android 5+, the compilation succeeds and the app runs smoothly.
build.gradle
[...]
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
applicationId "br.com.example"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
}
dependencies {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.android.support', module: 'support-annotations'
all*.exclude group: 'com.android.support', module: 'appcompat-v7'
all*.exclude group: 'com.android.support', module: 'support-v13'
}
implementation project(':mylib')
// These 3 libraries are required for the project.
implementation files("libs/activation.jar")
implementation files("libs/mail.jar")
implementation files("libs/edtftpj.jar")
implementation files("libs/commons-net-3.0.1.jar")
implementation files("libs/commons-validator-1.4.0.jar")
implementation files("libs/itextpdf-5.4.0.jar")
implementation('com.appsee:appsee-android:2.3.3#aar') {
transitive = true
}
implementation('com.optimizely:optimizely:1.4.2#aar') {
transitive = true
}
implementation('io.fabric.sdk.android:fabric:1.4.8#aar') {
transitive = true
}
implementation('com.crashlytics.sdk.android:crashlytics:2.10.1#aar') {
transitive = true
}
implementation "com.onesignal:OneSignal:$oneSignalVersion"
implementation "androidx.percentlayout:percentlayout:$percentLayoutVersion"
implementation "androidx.legacy:legacy-support-v4:$legacyVersion"
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation "androidx.recyclerview:recyclerview:$recyclerViewVersion"
implementation "androidx.annotation:annotation:$androidxAppCompatVersion"
implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.guava:guava-collections:r03'
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation "com.google.android.material:material:$materialVersion"
implementation "com.google.android.gms:play-services-maps:$gmsVersion"
implementation "com.google.android.gms:play-services-analytics:$gmsVersion"
implementation 'com.google.dagger:dagger:2.24'
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
implementation 'com.squareup:otto:1.3.8'
implementation 'org.jetbrains:annotations:17.0.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.squareup.picasso:picasso:2.71828', {
exclude group: 'com.android.support', module: 'support-annotations'
}
implementation 'com.lapism:searchview:4.0'
implementation 'com.sromku:simple-storage:1.2.0'
implementation 'me.dm7.barcodescanner:zxing:1.9.8', {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
implementation 'com.nononsenseapps:filepicker:2.5.2'
implementation 'io.github.yavski:fab-speed-dial:1.0.6'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.1'
implementation 'com.github.arimorty:floatingsearchview:2.1.1'
implementation 'net.i2p.android.ext:floatingactionbutton:1.10.1'
implementation 'org.zakariya.stickyheaders:stickyheaders:0.7.11'
implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'
implementation 'com.prolificinteractive:material-calendarview:1.4.3'
implementation 'uk.co.chrisjenx:calligraphy:2.3.0', {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
// debug
debugImplementation 'com.facebook.stetho:stetho:1.5.1'
debugImplementation 'com.gu.android:toolargetool:0.1.5#aar'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-all:1.10.19'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02', {
exclude group: 'com.android.support', module: 'support-annotations'
}
}
[...]
build.gradle (project)
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://maven.google.com' }
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.5'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath 'io.fabric.tools:gradle:1.31.1'
classpath 'com.google.gms:google-services:4.3.2'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://www.jitpack.io" }
maven { url 'http://dl.bintray.com/optimizely/optimizely' }
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://maven.google.com' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots"}
maven { url 'https://dl.bintray.com/guardian/android' }
}
}
build.gradle (local lib: "mylib")
[...]
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
[...]
dependencies {
// here, I repeat those 3 libraries mentioned (activation, mail, edtftpj)
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.browser:browser:1.0.0'
implementation "com.google.android.gms:play-services-location:17.0.0"
implementation "com.google.android.gms:play-services-maps:17.0.0"
implementation "com.google.android.gms:play-services-analytics:17.0.0"
implementation "com.google.android.material:material:1.0.0"
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.annotation:annotation:1.1.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
api 'br.com.concretesolutions:canarinho:1.1.0'
api 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
}
gradle.properties
org.gradle.jvmargs=-Xmx2048M
org.gradle.configureondemand=false
android.enableJetifier=true
android.useAndroidX=true
The 3 libraries I mentioned (activation, mail, edtftpj) need to be in both lib and project, because it is actually used.
This I already tried:
./gradlew clean
Android Studio -> File -> invalidate cache and restart
Android Studio -> Build -> Clean Project
Remove one of the duplicate libraries (this generated another error because I use the library tools in both modules)
Add the following code to build.gradle:
packagingOptions {
exclude 'com/sun/mail/dsn/mailcap'
exclude 'dsn.mf'
exclude 'javamail.charset.map'
exclude 'javamail.default.address.map'
exclude 'javamail.default.providers'
exclude 'javamail.imap.provider'
exclude 'javamail.pop3.provider'
exclude 'javamail.smtp.address.map'
exclude 'javamail.smtp.provider'
exclude 'mailcap'
exclude 'mimetypes.default'
exclude 'mailcap.default'
exclude 'com.enterprisedt.BaseIOException'
exclude 'javax.activation.*'
}
Can anybody help me ?

Related

duplicate classes or library dependency conflicts [duplicate]

When I build the android project, it show "Duplicate class" exception,
1 exception was raised by workers: java.lang.RuntimeException:
java.lang.RuntimeException:
Duplicate class android.arch.core.executor.DefaultTaskExecutor found in modules classes.jar (android.arch.core:core:1.0.0-alpha1) and classes.jar(android.arch.core:runtime:1.1.1)
Duplicate class android.arch.core.executor.TaskExecutor found in modules classes.jar (android.arch.core:core:1.0.0-alpha1) and classes.jar (android.arch.core:runtime:1.1.1)**
How could I find and fix what lib use duplicate class in my project?
app.Gradle
android {
compileSdkVersion 28
buildToolsVersion ’28.0.3’
defaultConfig {
minSdkVersion 18
targetSdkVersion 28
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
dependencies {
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation ’org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31’api('com.google.maps:google-maps-services:0.9.3') {
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}
implementation 'com.android.support:appcompat-v7:28.0.0’
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.android.exoplayer:exoplayer:2.8.2’
implementation 'android.arch.persistence.room:runtime:1.0.0-alpha1'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-alpha1'
implementation 'com.jakewharton.rxbinding:rxbinding:1.0.1'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.8'
implementation 'com.google.android.gms:play-services-places:16.1.0'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation 'com.facebook.android:facebook-android-sdk:5.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.1'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.3.8'
implementation 'com.artemzin.rxjava:proguard-rules:1.3.3.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.1'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation ('com.github.bumptech.glide:glide:4.9.0') {
exclude group: "com.android.support"
}
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.10.11'
implementation project(':lib-zxing')
implementation 'com.googlecode.mp4parser:isoparser:1.1.22'
implementation 'com.github.lassana:continuous-audiorecorder:1.3.1'
implementation 'me.leolin:ShortcutBadger:1.1.22#aar'
implementation 'com.timehop.stickyheadersrecyclerview:library:0.4.3'
implementation 'org.jsoup:jsoup:1.11.3'
testImplementation 'junit:junit:4.13-beta-2'
}
lib-zxing
android {
compileSdkVersion 28
buildToolsVersion ’28.0.3’
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0’
testImplementation 'junit:junit:4.13-beta-2'
}
You need to exclude the arch Jar. First of all check where the duplicate comes from. You can see it if you print your dependency tree with a gradle task:
./gradlew -q dependencies app:dependencies --configuration compile
Then exclude the older arch Jar like you did for glide but with the correct exclude, for example:
implementation ('android.arch.persistence.room:runtime:1.0.0-alpha1') {
exclude group: "android.arch.core"
}
You can use search everywhere dialog(Dialog that opens on pressing shift twice).
Simply copy class name and paste it in search dialog and it will show results in drop down. You can browse result and check for duplicate entries, Complete path of class will be displayed next to class name so you can find relative libraries and can safely exclude it from anyone of the library.

Could not run build action using Gradle distribution / all gms/firebase libraries must be exact the same

After Updating my gradle-version to 3.3.1 and my google-services-version to 4.2.0, I'm getting the following error while building:
Error:Internal error:
org.gradle.tooling.BuildException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.10.1-all.zip'.
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:51)
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:29)
at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:41)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:57)
My build-gradle-project-file looks like this:
buildscript {
repositories {
google()
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
// 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
}
My build-module-gradle-file looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
aaptOptions {
additionalParameters '--utf16'
}
defaultConfig {
applicationId "XXX.XXXX.XXX"
minSdkVersion 15
targetSdkVersion 26
versionCode 140
versionName "14.5"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
jumboMode = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation files('libs/amazon-mobile-associates-1.0.73.0.jar')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation "com.android.support:customtabs:28.0.0"
implementation 'com.androidadvance:topsnackbar:1.1.1'
implementation 'com.yuyakaido.android:card-stack-view:1.0.0-beta5'
implementation 'com.roughike:bottom-bar:2.3.1'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.android.gms:play-services-ads:17.1.3'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.google.android.gms:play-services-plus:16.0.0'
implementation 'com.google.android.gms:play-services-basement:16.2.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
//
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
implementation 'com.facebook.android:facebook-share:4.38.1'
implementation 'com.facebook.android:audience-network-sdk:5.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.commit451:PhotoView:1.2.4'
implementation 'com.crystal:crystalrangeseekbar:1.1.1'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.3.+'
//compile 'com.appnext.sdk:native-ads2:2.+' // New Native Ads
implementation 'com.android.support:multidex:1.0.2'
androidTestImplementation 'com.android.support:multidex:1.0.2'
androidTestImplementation 'com.android.support:multidex-instrumentation:1.0.2'
testImplementation 'junit:junit:4.12'
apply plugin: 'com.google.gms.google-services'
}
I tried to delete the user-gradle-directory and the project-gradle-directory and relaunch android studio without any help. I tried to invalidate cache / restart, as well, but nothing helped.
I also can't fix the issue (all gms/firebase libraries must be exact the same...). And I realize that in all of my files the "package.R" is not recognized any more.
I have no clue to fix these problems.
It would be great if someone could help me or give me an idea.

Program type already present: com.google.common.annotations.GwtCompatible

I'm getting the following error when building my android project :
Program type already present:
com.google.common.annotations.GwtCompatible Message{kind=ERROR,
text=Program type already present:
com.google.common.annotations.GwtCompatible, sources=[Unknown source
file], tool name=Optional.of(D8)}
gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.www.www"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// multi-dex support (When your app and the libraries it references exceed 65,536 methods)
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/INDEX.LIST'
}
}
dependencies {
// multi-dex support (When your app and the libraries it references exceed 65,536 methods)
implementation 'com.android.support:multidex:1.0.3'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//this is for the google "text recognizer"
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.google.apis:google-api-services-customsearch:v1-rev63-1.23.0'
//for firebase database connection
implementation 'com.google.firebase:firebase-database:16.0.1'
//implementation 'com.google.firebase:firebase-core:16.0.0'
// for firebase authentication
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
// for Google Natural Language Processing (part of google cloud services)
implementation ('com.google.cloud:google-cloud-language:1.31.0')
// {
// exclude group: 'com.google.guava'
// }
}
apply plugin: 'com.google.gms.google-services'
The following resolves THAT issue :
implementation ('com.google.cloud:google-cloud-language:1.31.0') {
exclude group: 'com.google.guava'
}
But then I am missing guava functions, because the following error will be thrown at runtime :
Didn't find class "com.google.common.base.MoreObjects"
Caused by: java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/common/base/MoreObjects;
When I run the following code :
public void testSomething(View view){
// Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient
try {
InputStream inputStream = getAssets().open("www.json");
GoogleCredentials googleCredential = GoogleCredentials.fromStream(inputStream);
}
catch (Exception e){
Log.e(TAG,e.getMessage());
e.printStackTrace();
}
I'm going in circles here. I'm desperate to find the answer.
I have checked other questions/topics, no answers that help me.
I solved same problem by making below changes:
implementation ('com.google.apis:google-api-services-drive:v2-rev105-1.17.0-rc'){
exclude module: 'guava-jdk5'
}
implementation ('com.google.api-client:google-api-client-android:1.20.0'){
exclude module: 'guava-jdk5'
}
Change Gradles To This :
implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0' exclude module: 'guava-jdk5'
implementation 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'guava-jdk5' exclude module: 'httpclient'
implementation 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
This Worked For Me

Unable to build apk or run the app

The gradle build completes successfully , but while running the application or trying to build the apk I am getting an error:
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't write [F:\TravEz\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\hp.gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.0.aar\51b8cdc0bcfc98652d9ae95f70697b30\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/design/widget/CoordinatorLayout$Behavior.class]))
I have tried all the methods mentioned here
Here is my project level gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io"}
//Glomadrian maven for animated switch
maven { url "https://dl.bintray.com/glomadrian/maven"}
maven { url "http://dl.bintray.com/lukaville/maven"}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is my app level gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.travez.travez"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dexOptions {
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
compile 'com.github.florent37:materialtextfield:1.0.7'
//library for cardview
implementation 'com.android.support:cardview-v7:26.1.0'
//library for dialog box
implementation 'com.github.d-max:spots-dialog:0.7#aar'
//library for animated switch
implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//Firebase authentication library
implementation 'com.google.firebase:firebase-auth:11.0.4'
//Firebase database library
implementation 'com.google.firebase:firebase-database:11.0.4'
//Google play services and maps libraries
implementation 'com.google.android.gms:play-services-maps:11.0.4'
implementation 'com.google.android.gms:play-services:11.0.4'
implementation 'com.google.android.gms:play-services-location:11.0.4'
//Geofire library
compile 'com.firebase:geofire-android:2.3.0'
//Runtime perission library
compile 'com.github.karanchuri:PermissionManager:0.1.0'
//Material Edit Text library
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
//Calligraphy library
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
// CircleView library
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'id.zelory:compressor:2.1.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
compile 'com.android.support:multidex:1.0.0'
compile 'com.nbsp:library:1.8'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
Is written twice, remove one of them.
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
Replace the + with the current version of the library
The problem is because you have duplicated support library in your dependencies.
android-image-cropper is using support library 27+, you can check its build.gradle. MaterialEditText is using support library 22.2.0. Material Animated Switch is using support library 22.2.0. You need to exlude the support libraries from them.
So, instead using the following:
compile 'com.github.florent37:materialtextfield:1.0.7'
implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
use the following:
implementation 'com.android.support:support-annotations:26.1.0'
implementation ('com.github.florent37:materialtextfield:1.0.7') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
exclude module: 'support-annotations'
}
implementation ('com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
}
implementation ('com.theartofdev.edmodo:android-image-cropper:2.6.0') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
}
You can check the dependencies tree if you still found the conflicted libraries with:
./gradlew app:dependencies

duplicate entry error when using POI with gradle

I started a project which needed the Apache POI library. I pasted them in my build.gradle file and everything seemed fine. Until I build the debug app.
I am getting the following error:
Error:Execution failed for task
':mobile:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
org/apache/xmlbeans/xml/stream/Location.class
I have tried removing and adding exclude group and module, but nothing has helped. When I do get the debug apk to build, and run the app, the app crashes because org.apache.xmlbeans.XmlOptions is not found when opening a DOCX file. The DOC files work fine.
Here is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "{application_id}"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
encoding "UTF-8"
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
// set to true to turn off analysis progress reporting by lint
quiet false
// if true, stop the gradle build if errors are found
abortOnError true
// if true, only report errors
ignoreWarnings false
// turn off checking the given issue id's
disable 'TypographyFractions', 'TypographyQuotes'
// if true, generate a text report of issues (false by default)
textReport true
// location to write the output; can be a file or 'stdout'
textOutput 'stdout'
// if true, generate an HTML report (with issue explanations, sourcecode, etc)
htmlReport true
// optional path to report (default will be lint-results.html in the builddir)
htmlOutput file("lint-report.html")
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/services/org.apache.sis.storage.DataStoreProvider'
exclude 'META-INF/BCKEY.SF'
exclude 'META-INF/spring.handlers'
exclude 'META-INF/spring.schemas'
exclude 'META-INF/services/org.apache.tika.detect.Detector'
exclude 'META-INF/BCKEY.DSA'
exclude 'META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration'
exclude 'META-INF/services/org.apache.tika.parser.Parser'
exclude 'META-INF/cxf/bus-extensions.txt'
}
}
repositories{
mavenCentral()
maven {url "https://github.com/karussell/mvnrepo/raw/master/releases"}
maven {url "http://dl.bintray.com/lukaville/maven"}
maven {url "http://dl.bintray.com/dasar/maven"}
}
configurations {
all*.exclude group: 'ch.qos.logback'
all*.exclude group: 'org.slf4j', module: 'jcl-over-slf4j'
all*.exclude group: 'org.slf4j', module: 'jul-to-slf4j'
all*.exclude group: 'org.slf4j', module: 'log4j-over-slf4j'
all*.exclude group: 'org.slf4j', module: 'jcl-over-slf4j'
all*.exclude group: 'org.slf4j', module: 'slf4j-log4j12'
all*.exclude group: 'org.slf4j', module: 'slf4j-simple'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile ('org.slf4j:slf4j-android:1.7.13'){
exclude group: 'net.sf.log4jdbc'
exclude group: 'org.slf4j.logger'
}
compile 'org.jsoup:jsoup:1.7.3'
compile 'de.jetwick:snacktory:1.1'
compile 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
// The material design file browser library
compile 'com.nbsp:library:1.02'
// Epub library
compile 'nl.siegmann.epublib:epub-core:1.0#aar'
// Begin for Office documents dependencies
compile 'org.apache.xmlbeans:xmlbeans:2.6.0'
compile ('org.apache.poi:poi:3.13'){
transitive = false
exclude group: 'org.apache.xmlbeans'
exclude module: 'org.apache.xmlbeans'
}
compile ('org.apache.poi:poi-ooxml:3.13'){
transitive = false
exclude group: 'org.apache.xmlbeans'
exclude module: 'org.apache.xmlbeans'
}
compile ('org.apache.poi:poi-scratchpad:3.13'){
transitive = false
exclude group: 'org.apache.xmlbeans'
exclude module: 'org.apache.xmlbeans'
}
compile ('org.apache.tika:tika-core:1.11'){
transitive = false
exclude group: 'org.apache.xmlbeans'
}
compile ('org.apache.tika:tika-parsers:1.11'){
transitive = false
exclude group: 'org.apache.xmlbeans'
exclude module: 'org.apache.xmlbeans'
}
// End for Office documents dependencies
// PDF document library
compile 'com.itextpdf:itextpdf:5.5.8'
}
I have checked if there are any other dependencies using the org.apache.xmlbeans dependency, but I haven't found one.
If anybody would have a solution, please feel free to answer the question, but I would appreciate it if you tell us how you come to the answer.
Tim
EDIT:
When executing this command:
gradlew -q dependencies mobile:dependencies --configuration compile
(output here: http://pastebin.com/7TugFR3J)
The org.apache.xmlbeans dependency is only listed once. Might there be a problem relating to any default java component?
EDIT NO.2:
I found that Java has a component like this: javax/xml/stream/Location.class
So I think I need to remove it from the build, but I don't know how.
You can try something like this.
Unzip the jar file. (Simply change .jar extension to .zip
This will remove the duplicate files.
Recreate the jar using jar cf xmlbeans.jar -C (path to unzipped folder) . (Mind it, there is a dot in the end of command)
Use this regenerated jar

Categories

Resources