duplicate entry error when using POI with gradle - java

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

Related

Problem compiling to Android 4 after migrating to AndroidX

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 ?

How to solve this error ( duplicate entry: com/google/gson/annotations/Expose.class? )

each time I try to build an APK, this error keep showing !? I've tried almost all the soultoins mention on the site, but no luck!
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException:
java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.1'
lintOptions {
quiet true
abortOnError false
ignoreWarnings true
}
configurations {
all*.exclude group: 'commons-io'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'BinaryEncoder.java'
}
defaultConfig {
applicationId "com.xxxx.xxxxx"
minSdkVersion 15
targetSdkVersion 26
versionCode 3
versionName "1.2"
multiDexEnabled true
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
}
sourceSets {
main {
java {
exclude 'com.twilio:client-android:1.2.18.org.apache.http.lejacy.jar.org.apache.BinaryEncoder.java'
exclude 'org.apache.commons.codec.BinaryEncoder.java'
}
}
androidTest {
java {
exclude 'commons-codec-1.10/**'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.twilio:client-android:1.2.18') {
exclude group: 'org.apache.commons', module: 'commons-io'
}
compile project(':example')
compile project(':zoomcommonlib')
compile project(':zoommobilertc')
compile("com.github.hotchemi:permissionsdispatcher:2.4.0") {
exclude module: "support-v13"
}
compile('com.stripe:stripe-android:4.1.5') {
transitive = true;
exclude group: 'com.google.code.gson', module: 'gson'
}
compile('com.squareup.retrofit:retrofit:1.9.0') {
transitive = true;
exclude group: 'com.google.code.gson', module: 'gson'
}
compile 'com.google.android.gms:play-services-gcm:11.2.0'
compile 'lib.kingja.switchbutton:switchbutton:1.1.3'
compile 'com.orhanobut:hawk:2.0.1'
compile 'com.afollestad:material-camera:0.4.4'
compile 'com.werb.pickphotoview:pickphotoview:0.3.0'
compile 'com.github.Kennyc1012:BottomSheet:2.3.4'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:cardview-v7:26.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.google.android.gms:play-services-identity:11.2.0'
compile 'com.google.android.gms:play-services-plus:11.2.0'
compile 'com.google.android.gms:play-services-maps:11.2.0'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.paypal.sdk:paypal-android-sdk:2.14.4'
compile 'com.koushikdutta.ion:ion:2.1.8'
compile 'com.afollestad.material-dialogs:core:0.8.6.0'
compile 'com.amitshekhar.android:android-networking:1.0.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support:support-v4:26.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:2.4.0'
}
Here's some solutions that I've tried and did not work:
I've added those transitive = true; exclude group: 'com.google.code.gson', module: 'gson' forretrofitandstripe` dependencies
I deleted the gson dependency
I wanted to delete the jar file for gson library but I couldn't find it inside libs folder !?
multiDexEnabled true was already added and did no effect
I've deleted compile fileTree(dir: 'libs', include: ['*.jar'])
I think it has something to do with the Zoom module or with Stripe any help.. !?
You could try to get the dependency tree and figure out which package it is.
I figured it out, first.. thanks guys for ur help anyhow..! but I'm making this as the accepted answer since it's the one that worked out for me!
Step 1
I searched for the duplicated class in the whole project using (Double Shift)
and it showed me which library is also using the same class..! in my case it was zoommobilertc
Step 2
I tried excluding the gson module of that library like this:
compile project(':zoommobilertc'){
exclude group: 'com.google.code.gson', module: 'gson'
}
..but it didn't work, and it give me error that I think it has something to do with exclude . I tried a few solution but no luck!
So.. I did this instead ..
Open Project View
Open External Libraries
Find the library which's zoommobilertc and unfold its folder
Delete Gson jar file that shows.!
Step 3
After that, I synced the project and tried to build an apk, bu this error showed:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --num-threads=4 --multi-dex --main-dex-list E:\*****\*****\app\build\intermediates\multi-dex\debug\maindexlist.txt --output E:\*****\*****\app\build\intermediates\transforms\dex\debug\folders\1000\1f\main E:\*****\*****\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}
Then after searching I found a fix:
I added this inside build.gradle file within android section:
android{
//..
dexOptions {
javaMaxHeapSize "4g"
}
//..
}
..and this line inside local.properties file
org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m
Done
Find out the dependency that causes above Error and exclude gson
as follows from your dependency,
compile ('your_dependency'){
exclude group : 'com.google.code.gson'
}
In android studio terminal execute
./gradlew clean
and perform the following and rebuild
Try adding this to your dependencies
compile'com.android.support:multidex:1.0.1'
and in manifest add this
android:name="android.support.multidex.MultiDexApplication"
in the application tag
I had my gson.jar in my libs folder.
I fixed my duplicate entries by retaining the line below:
implementation fileTree(dir: "libs", include: ["*.jar"])
And deleting this entry here:
implementation 'com.google.code.gson:gson:2.8.7'

Gradle Build Failed - Duplicate files copied in APK META-INF

I get this error as soon as I enter the elasticsearch dependency,
compile 'org.elasticsearch.client:transport:5.0.0'
Detailed error logcat:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDevDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/io.netty.versions.properties
File1: C:\Users\Dell\.gradle\caches\modules-2\files-2.1\io.netty\netty-buffer\4.1.5.Final\b5fb6bccda4d63d4a74c9faccdf32f77ab66abc1\netty-buffer-4.1.5.Final.jar
File2: C:\Users\Dell\.gradle\caches\modules-2\files-2.1\io.netty\netty-handler\4.1.5.Final\6262900ee9487e62560030a136160df953b1cd6b\netty-handler-4.1.5.Final.jar
File3: C:\Users\Dell\.gradle\caches\modules-2\files-2.1\io.netty\netty-transport\4.1.5.Final\37126b370722ff9631ee13c91139aacec0a71d1d\netty-transport-4.1.5.Final.jar
File4: C:\Users\Dell\.gradle\caches\modules-2\files-2.1\io.netty\netty-codec-http\4.1.5.Final\87bda1b9ec7e3f75ca721fc87735cbedad2aa1a\netty-codec-http-4.1.5.Final.jar
File5: C:\Users\Dell\.gradle\caches\modules-2\files-2.1\io.netty\netty-resolver\4.1.5.Final\5f367bedcdc185a727fda3296b9a18014cdc22c4\netty-resolver-4.1.5.Final.jar
File6: C:\Users\Dell\.gradle\caches\modules-2\files-2.1\io.netty\netty-codec\4.1.5.Final\66bbf9324fa36467d041083f89328e2a24ec4f67\netty-codec-4.1.5.Final.jar
File7: C:\Users\Dell\.gradle\caches\modules-2\files-2.1\io.netty\netty-common\4.1.5.Final\607f8433d8782445e72abe34e43a7e57e86a5e6c\netty-common-4.1.5.Final.jar
Gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
applicationId "..."
minSdkVersion 18
targetSdkVersion 25
versionCode 6
versionName "20170616.06"
multiDexEnabled true
ndk {
abiFilter "armeabi-v7a"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// signingConfig signingConfigs.release
}
}
productFlavors {
dev {
applicationId "..."
minSdkVersion 21
}
prod {
applicationId "..."
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
lintOptions {
abortOnError false
}
}
repositories {
jcenter()
maven { url "https://dl.bintray.com/drummer-aidan/maven" }
mavenCentral()
}
configurations {
compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// https://mvnrepository.com/artifact/commons-io/commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile 'com.android.support:appcompat-v7:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:cardview-v7:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:recyclerview-v7:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:support-v4:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:design:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:percent:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:animated-vector-drawable:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:support-annotations:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:support-compat:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:support-core-ui:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:support-v13:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:support-v4:' + rootProject.ext.supportLibraryVersion'
compile 'com.google.firebase:firebase-storage:' + rootProject.ext.firebaseVersion
compile 'com.google.firebase:firebase-common:' + rootProject.ext.firebaseVersion
compile 'com.google.firebase:firebase-auth:' + rootProject.ext.firebaseVersion
compile 'com.google.firebase:firebase-database:' + rootProject.ext.firebaseVersion
compile 'com.google.firebase:firebase-crash:' + rootProject.ext.firebaseVersion
compile 'com.google.firebase:firebase-core:' + rootProject.ext.firebaseVersion
// this line must be included to integrate with Firebase
compile 'com.google.firebase:firebase-messaging:' + rootProject.ext.firebaseVersion
// this line must be included to use FCM
compile 'com.google.firebase:firebase-ads:' + rootProject.ext.firebaseVersion
compile 'com.google.android.gms:play-services-auth:' + rootProject.ext.firebaseVersion
compile 'com.google.android.gms:play-services-plus:' + rootProject.ext.firebaseVersion
compile 'com.google.android.gms:play-services-location:' + rootProject.ext.firebaseVersion
compile 'com.google.android.gms:play-services-places:' + rootProject.ext.firebaseVersion
compile "im.ene.toro2:toro-ext-exoplayer2:${toroVersion}"
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile 'com.jakewharton:butterknife:' + rootProject.ext.butterknifeVersion
apt 'com.jakewharton:butterknife-compiler:' + rootProject.ext.butterknifeVersion
//RxAndroid
compile 'io.reactivex:rxandroid:' + rootProject.ext.rxandroidVersion
compile 'io.reactivex:rxjava:' + rootProject.ext.rxjavaVersion
compile 'com.squareup.retrofit2:adapter-rxjava:' + rootProject.ext.retroRxAdapterVersion
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.firebaseui:firebase-ui-database:0.4.0'
compile 'com.google.firebase:firebase-invites:10.2.1'
compile 'com.firebase:firebase-client-android:2.5.2+'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:multidex:1.0.1'
compile 'pub.devrel:easypermissions:0.1.5'
compile 'com.github.bumptech.glide:glide:3.6.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
compile 'com.danikula:videocache:2.6.4'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.dinuscxj:circleprogressbar:1.1.1'
compile 'com.afollestad.material-dialogs:core:0.9.4.5'
compile 'com.afollestad:easyvideoplayer:0.3.0'
compile 'com.googlecode.mp4parser:isoparser:1.1.22'
compile 'javax.inject:javax.inject:1'
compile 'com.google.firebase:firebase-storage:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.google.api-client:google-api-client:1.21.0'
compile 'com.google.apis:google-api-services-people:v1-rev2-1.21.0'
compile 'org.elasticsearch.client:transport:5.0.0'
compile project(':ffmpeg4android_lib')
}
apply plugin: 'com.google.gms.google-services'
PS: There are a lot of similar posts already on SO, but none of them helped me
Can someone help me with this? Also, please tell me a generic way to solve these issues.
add the code below at the android section
packagingOptions {
pickFirst 'META-INF/*'
}
This github issue ticket suggests to use
packagingOptions {
pickFirst 'META-INF/INDEX.LIST'
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/io.netty.versions.properties'
}
It is not advisable to use ElasticSearch directly into the android application. The cons of doing so are:
Anyone can decompile your application and get your ElasticSearch instance REST API link and play with your indexes the way they want and even modify them or delete them. The API link has to be publicly accessible for users to access.
There will be dependency conflicts like this question has, between Android SDK dependencies and ElasticSearch dependencies.
If you want to customize the way your requests are being built, you will have to release an update for the Application.
A better way to go about this is, make your own API to handle requests for your ElasticSearch Instance. From the App, make requests on that instance, that instance in turn makes a request on your ElasticSearch instance. When someone hits your API, you can get the variables for the search and build your own query. Pros of this method are:
Your ElasticSearch link can be private and nobody can delete your indexes.
You do not need to update the code for the Apps when you want to modify the way your queries are being built.
You do not get dependency conflicts.
Do not forget to put
packagingOptions {
pickFirst 'META-INF/*'
}
to all build gradle files if You use modules.

java.util.zip.ZipException: duplicate entry: org/apache/commons/collections/ArrayStack.class

Spent almost a day searching the issue but no luck.Its due to the redundancy of dependencies.Which one is repeated couldn't find yet.
here in my build.gradle file
apply plugin: 'com.android.application'
android {
defaultConfig {
applicationId "com.ujjwalmainali.univhub"
minSdkVersion 16
targetSdkVersion 22
versionCode 8
versionName "1.1"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
configurations {
all*.exclude group: 'commons-logging', module: 'commons-logging'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ECLIPSE_.SF'
exclude 'META-INF/ECLIPSE_.RSA'
}
compileSdkVersion 25
buildToolsVersion '25.0.2'
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url "https://raw.githubusercontent.com/smilefam/SendBird-SDK-
Android/master/" }
}
dependencies {
testCompile 'junit:junit:4.12'
//iconify dependencies
compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2' // (v4.5)
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.sendbird.sdk:sendbird-android-sdk:3.0.25'
compile 'com.miguelcatalan:materialsearchview:1.4.0'
compile 'net.gotev:uploadservice-okhttp:3.0.3'
compile 'com.jaredrummler:material-spinner:1.1.0'
compile 'com.nononsenseapps:filepicker:4.1.0'
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.0'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'io.github.kobakei:ratethisapp:1.2.0'
compile 'com.github.paolorotolo:appintro:4.1.0'
//webview
compile 'com.thefinestartist:finestwebview:1.2.7'
//for android drawer
compile('com.mikepenz:materialdrawer:5.8.1#aar') {
transitive = true
}
compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.10.4#aar'){
transitive=true
}
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.3'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.googlecode.json-simple:json-simple:1.1'
compile 'com.ogaclejapan.smarttablayout:library:1.6.1#aar'
compile 'com.ogaclejapan.smarttablayout:utils-v4:1.6.1#aar'
compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'commons-validator:commons-validator:1.4.1'
//for the calender date picker supports other type picker also like radial time picker,recurrence picker
compile 'com.code-troopers.betterpickers:library:3.1.0'
compile 'com.mikepenz:actionitembadge:3.3.1#aar'
compile 'com.mobsandgeeks:android-saripaar:2.0.1'
compile 'com.nightonke:boommenu:2.0.9'
compile 'com.google.android.gms:play-services-location:9.2.0'
compile 'com.google.android.gms:play-services-maps:9.2.0'
compile 'com.google.android.gms:play-services-places:9.2.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:cardview-v7:25.0.0'
//circular progress bar
compile 'com.victor:lib:1.0.4'
//app crash report
compile 'ch.acra:acra:4.9.0'
ext.googlePlayServicesVersion='10.0.1'
ext.supportLibraryVersion='23.1.1'
provided 'org.glassfish:javax.annotation:10.0-b28'
apply plugin: 'com.google.gms.google-services'
}
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/commons/collections/ArrayStack.class
compile 'commons-validator:commons-validator:1.4.1'
The commons-validator dependency contains two versions of ArrayStack, because of a transitive dependency it has on commons-collections.
By excluding commons-collections in the declaration, you're effectively removing all classes associated with that library and what remains is only one ArrayStack class at runtime.
compile('commons-validator:commons-validator:1.4.1') {
exclude module: 'commons-collections'
}
In my case following solution work for me:
Just added in myProject/app/build.gradle inside android{}
configurations {
all*.exclude group: 'commons-collections', module: 'commons-collections'
}
And then: Sync -> Clean -> Rebuild, Project

Excluding .class files from Gradle dependency

I'm trying to import https://github.com/Kickflip/kickflip-android-sdk using gradle into my android build and I'm getting :
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/codec/binary/Base64;
Commons.codec is a dependency of my project, but not directly of the kick-flip project, I think its coming from one of the jars included there. I can see the .class files if I open Kickflip's classes.jar.
How can I exclude Base64.class from being imported from kickflip into the final build? I've looked at using ziptree to exclude things but haven't been able to get anything to work.
Thanks
My build.gradle is:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/ASL2.0'
}
android.applicationVariants.all{ variant ->
// This is an annoying hack to get around the fact that the Gradle plugin does not support
// having libraries with different minSdkVersions. Play Services has a min version of 9 (Gingerbread)
// but Android Maps Utils supports 8 (Froyo) still
variant.processManifest.doFirst {
File manifestFile = file("${buildDir}/exploded-aar/io.kickflip/sdk/0.9.9/AndroidManifest.xml")
if (manifestFile.exists()) {
println("Replacing minSdkVersion in Android Maps Utils")
String content = manifestFile.getText('UTF-8')
content = content.replaceAll(/minSdkVersion="18"/, 'minSdkVersion=\"10\"')
manifestFile.write(content, 'UTF-8')
println(content)
}
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'io.kickflip:sdk:0.9.9'
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':libs:typeface-textview:library')
compile project(':libs:gpuimage')
compile 'com.google.android.gms:play-services:4.3.23'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.koushikdutta.urlimageviewhelper:urlimageviewhelper:1.0.4'
compile ('fr.avianey:facebook-android-api:3.14.0') {
exclude module: 'support-v4'
}
compile 'com.github.japgolly.android:svg-android:2.0.1'
compile 'org.scribe:scribe:1.3.5'
compile 'commons-codec:commons-codec:1.8'
}
Probably the problem is Base64 class included twice. It is in the 'google-http-client' (view it). Try to exclude this class. If you're lucky, being an Util class, it isn't used in the code.
Try this in your build.gradle:
package com.google.api.client.util;
sourceSets {
main {
java {
exclude 'com.google.api.client.util.Base64.java'
exclude 'org.apache.commons.codec.binary.Base64.java'
}
}
}
NOTE: I don't tried it yet, but sounds as a possibility

Categories

Resources