ZipException duplicate entry: android/support/v4/widget/CursorAdapter$MyDataSetObserver.class - android

Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/widget/CursorAdapter$MyDataSetObserver.class - List item
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.omairm.hoops"
minSdkVersion 14
targetSdkVersion 23
multiDexEnabled true
ndk {
moduleName "player_shared"
}
}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile ('com.google.android.gms:play-services:+'){exclude module: 'Support-v4'}
compile files('libs/PTAdRevMob.jar')
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
}
Do I need to delete the CursorAdapter.class?

You should add something similar to this to your build.gradle, where the duplicate file is added to exclude
android {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
}

do i need to delete the cursoradapter.class
It's good that you are reading the error and recognize a least part of what it's telling you, but you can't just delete a class from a JAR file. The build process that Gradle goes through is only throwing the error at the first class conflict it found, and there would be more if you were to only focus on that one.
My suggestion would be to find the correct and current libraries for each of the JAR files you have and remove the jar files as you go.
Also, try to actually use a number value rather than only a plus for the version because you don't want to be using alpha / beta releases of a library that'll change every few weeks
If you search around Maven you can replace most of those JAR files
dependencies {
compile "com.android.support:appcompat-v7:26+"
// Don't use just a plus here
compile ('com.google.android.gms:play-services:+'){exclude module: 'support-v4'}
compile files('libs/PTAdRevMob.jar')
compile group: 'com.squareup.dagger', name: 'dagger', version: '1.2.2'
// compile group: 'com.nineoldandroids', name: 'library', version: '2.4.0'
}
It's also worth mentioning that nineoldandroids is deprecated. Since you're using minSdkVersion 14, I don't think you even need it.
Dagger has also had many releases since version 1.2 but it already includes javax inject framework (see compiled dependencies https://mvnrepository.com/artifact/com.squareup.dagger/dagger/1.2.2)
You'll definitely want to take a look at Google Play | Selectively compiling APIs into your executable too.
Note that if PTAdRevMob.jar has any classes that still conflict with any other library here, you'll still get an error, and will probably need to switch to a different Ad provider

Related

Build Apk Error - Duplicate entry : android/support/v4/database/DatabaseUtilsCompat.class?

My Gradle is :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.belajarku.gamelari"
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
}
dexOptions {
// Prevent OutOfMemory with MultiDex during the build phase
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jni.srcDirs = []// <-- disable automatic ndk-build call
}
}
dependencies {
compile ('com.google.android.gms:play-services:+'){exclude module: 'support-v4'}
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
compile ('com.android.support:multidex:1.0.1'){exclude module: 'support-v4'}
}
But when I build apk the project say me :
Error:Execution failed for task
':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
android/support/v4/database/DatabaseUtilsCompat.class
Please help me for fix it.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/database/DatabaseUtilsCompat.class
You are adding twice the same class with different versions.
compile ('com.google.android.gms:play-services:+'){exclude module: 'support-v4'}
compile files('libs/support-v4-19.0.1.jar')
Using com.google.android.gms:play-services:+ you are adding all packages of play services libraries which have a dependency with the support-v4.
You should update your support dependencies to the same version of compileSdkVersion. Your compileSdkVersion is 25, hence your support library should also be 25.
Don't use the whole package of Google Play service, choose what you need read from Set Up Google Play Services. For example, if you want to use google ads, add only com.google.android.gms:play-services-ads:11.0.4. You need to change your dependencies like this:
dependencies {
...
// only use google ads from google service.
compile 'com.google.android.gms:play-services-ads:11.0.4'
compile 'com.android.support:support-v4:25.3.1'
...
}
Then you can disable your multidex by setting multiDexEnabled false or commenting it and removing compile ('com.android.support:multidex:1.0.1') from your dependencies.

Apache POI Libraries error in Android Studio..?

I added 5 jar files of Apache POI so that I can save an text as .docx document but I can't run the application first I had 210 error in the grade now i have this error can someone please help me ..!? i followed this example
https://www.tutorialspoint.com/apache_poi_word/apache_poi_word_quick_guide.htm
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.mike.textword"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile files('libs/dom4j-1.6.jar')
compile files('libs/poi-3.16-beta2.jar')
compile files('libs/poi-ooxml-3.16-beta2.jar')
compile files('libs/poi-ooxml-schemas-3.16-beta2.jar')
compile files('libs/xmlbeans-2.6.0.jar')
compile 'com.android.support:multidex:1.0.1'
}
and now i have this error!
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/xmlbeans/xml/stream/Location.class
Currently Apache POI will not work on your Android Phone out of the box due to various problems that you will run into when using the libraries from Apache POI directly. Android is more strict about duplicate classes as part of the jar-files and unfortunately XmlBeans has such duplicate classes in it's jar-file.
There are two projects that try to make it possible to use Apache POI on Android:
https://github.com/andruhon/android5xlsx (for Android 5) and https://github.com/andruhon/AndroidReadXLSX (for Android 4), both are currently still based on Apache POI 3.12
https://github.com/centic9/poi-on-android/ (for Android 5, maintained by me), which can be more easily recompiled with newer versions of POI, e.g. it uses 3.16-beta2 currently
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/xmlbeans/xml/stream/Location.class
It means that you are adding this class twice or more.
Check all you jars files to remove it.

java.util.zip.ZipException with spongycastle LICENSE.class

I am trying to include two different 3rd party libs that both seem to include different versions of Spongy castle. Both are included via compile statements in my build.gradle and one is included as an AAR (#aar) while the other is included as normal.
When I try to compile the debug buildType with these 2 libs (sync doesnt show a problem). I see the following,
Error:Execution failed for task
':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
org/spongycastle/LICENSE.class
Been searching around for how to resolve this issue while keeping both the libraries (as both are needed) but have been unable to find a way to do that. Any help from an advanced Android dev or a gradle expert would be greatly appreciated.
Thanks!
[build.gradle]
apply plugin: 'com.android.application'
repositories {
maven { url 'http://mobile-sdk.jumio.com' }
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
packagingOptions {
pickFirst 'org/spongycastle/x509/CertPathReviewerMessages.properties'
pickFirst 'org/spongycastle/x509/CertPathReviewerMessages_de.properties'
}
defaultConfig {
applicationId "com.example.me.license"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile "com.jumio.android:jumio-mobile-sdk:1.9.0#aar"
compile 'com.worldpay:cse-android-sdk:1.0.2'
}
This is what happens if developers include their dependencies directly. The bad guy here is jumio-mobile-sdk. This package includes classes of com.madgag.spongycastle directly, instead of specifying them in a pom as it should be done.
Luckily for you, the other package is set up correctly, so you should be able to exclude spongycastle from it:
compile ('com.worldpay:cse-android-sdk:1.0.2'){
exclude group: 'com.madgag.spongycastle'
}
Now imagine both packages would've included the classes directly. The would've been no other possibility then to manually edit the files. This is why I hate it if someone does what the guys of jumio are doing. If you have the contacts, tell them to prepare their package for dependency systems, so this problem won't arise again.

Guava library duplicate entry error

I am trying to use guava library in my application. But I am also using chromium_webview project from github. This webview project contains guava library.
And I get the following error:
Error:Execution failed for task
':app:packageAllDebugClassesForMultiDex'. java.util.zip.ZipException:
duplicate entry: com/google/common/annotations/GwtIncompatible.class
I've looked at this and this answers already and nothing seems to work.
Here's my module's build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "my.package.name"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
jumboMode = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile files('libs/svgAndroid2-3Jan2014.jar')
compile project(':chromium_webview')
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.guava:guava:18.0'
}
I've tried the exclude method on the chromium_webview project like this:
compile (project(':chromium_webview')) {
exclude group: 'com.google.guava', module: "guava_javalib.jar"
}
and like this:
compile (project(':chromium_webview')) {
exclude module: "guava_javalib.jar"
}
Can I not use the same library again?
Is there a way to use the same library for both modules?
// ======================= EDIT:
Like #petey's comment mentioned, I tried removing just the guava library from my module and my module doesn't read the library in another module.
compile 'com.google.guava:guava:18.0'
that's the line I tried removing.
Any ideas will be really appreciated.
Thank you!!
I actually did fix this problem, forgot to post it.
So the issue here was I was using maven/gradle dependency in my project BUT the chromium_webview library was using an actual JAR file as a library.
I modified the library to use the maven/gradle dependency. Android Studio and Gradle did all the work for me and excluded the necessary classes.
So make sure they both (library and your module) use the same method.
compile 'com.google.guava:guava:18.0'
I really hope this helps someone.
Thank you.

JavaCV + Android Studio + gradle- possible?

I'm trying use JavaCV with Android Studio and Gradle. I wrote such code fragment:
repositories {
mavenCentral()
maven {
url "http://maven2.javacv.googlecode.com/git/"
}
}
dependencies {
compile files('libs/android-support-v4.jar')
compile group: 'com.googlecode.javacpp', name: 'javacpp', version: '0.5'
compile group: 'com.googlecode.javacv', name: 'javacv', version: '0.5'
}
and I see imported libraries in dir External Libraries. So I tried to run this:
...
IplImage zdjecie=cvLoadImage(Environment.getExternalStorageDirectory().getPath()+ "/1.bmp");
cvSaveImage(Environment.getExternalStorageDirectory().getPath()
+ "/2.bmp", zdjecie);
...
and I got error:
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load jniopencv_core: findLibrary returned null
...because I don't know what should I do with opencv's (and others) .so files.
So how should we use JavaCV in Android Studio?
1.WARNING:
That's not enough!:
dependencies { compile group: 'org.bytedeco', name: 'javacv', version: '0.9'}
2.EDIT: Sorry for mistake, my recent solution which
I posted here and which told only about line above was wrong. But I checked it out and this works for me:
a)Add dependencies
dependencies {
compile group: 'org.bytedeco', name: 'javacv', version: '0.9'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.9-0.9', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.3-0.9', classifier: 'android-arm'
}
b) Create jniLibs dir inside your project (on the same level as normal libs dir. EDIT: If
you have some troubles try moving jniLibs to app/src/main).
c) Add required .so files extracted from opencv-android-arm.jar and ffmpeg-android-arm.jar (or only this files which you really need) to created jniLibs dir. (If you don't know about what
I'm talking you can download javacv-0.9-bin.zip from JavaCV page and inside it
you can find these 2 .jars).
Inserting inside the build.gradle dependencies worked for me:
compile ‘org.bytedeco:javacv:+’
compile group: ‘org.bytedeco.javacpp-presets’, name: ‘opencv’, version: ‘2.4.10–0.10', classifier: ‘android-arm’
compile group: ‘org.bytedeco.javacpp-presets’, name: ‘ffmpeg’, version: ‘2.5.1–0.10', classifier: ‘android-arm’
For an up-to-date solution (JavaCV 1.1 and Android Studio 2.1.1) please see my step-by-step instructions in my Gist. JavaCV 1.2 currently doesn't like Android 6.
This tut will use JavaCV 1.1, version 1.2 currently has SIGSEGV issue. JavaCV 1.1 comes with FFmpeg 2.8.1.
Obtain the prebulit binaries here.
Extract it and copy these files:
javacpp.jar (essential).
javacv.jar (essential).
ffmpeg.jar (essential if you use FFmpeg).
ffmpeg-android-arm.jar (for arm CPU).
ffmpeg-android-x86.jar (optional for x86 CPU).
into the libs folder of your project (app/libs in my case).
Click on app -> F4 -> Dependencies -> + -> File dependencies -> choose all the previous .jar.
Temporarily, because of this issue, we need to set targetSdkVersion 22 the app's build.gradle.
Possibly need to set these packagingOptions in the build.gradle:
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.test"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
//might need these if you use openCV
//exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
//exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
}
}
Unfortunately, I had some problems with user2645214's solution (still getting java.lang.UnsatisfiedLinkError), but I found another one, so I decided to share it with those who would have the same problem.
Since release 0.7.3 there is another way to include your *.so files - you can just put them in /src/main/jniLibs (just create jniLibs directory if you don't have it) and it should work.
Also my build.gradle file looks like:
apply plugin: 'android'
repositories {
mavenCentral()
maven { url 'http://maven2.javacv.googlecode.com/git/' }
}
dependencies {
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.googlecode.javacpp:javacpp:0.7'
compile 'com.googlecode.javacv:javacv:0.7'
}
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.example.agp.testapplication2"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
I faced this issue on Windows 7 x64.
Here is a section from my gradle.build file which resolved the problem:
compile("org.bytedeco:javacv:0.11")
compile("org.bytedeco.javacpp-presets:opencv:2.4.11-0.11:windows-x86_64")
compile("org.bytedeco.javacpp-presets:ffmpeg:2.6.1-0.11:windows-x86_64")
EDIT. Solution in this post is deprecated and may contain some errors. Please see recent, correct post at the bottom of the page.
Ok, I did it on my own :). So here is what we should do to use JavaCV in Android Studio:
1) First we should add such dependencies to build.gradle inside project:
dependencies {
compile group: 'com.googlecode.javacpp', name: 'javacpp', version: '0.7'
compile group: 'com.googlecode.javacv', name: 'javacv', version: '0.7'}
(I mean: build.gradle inside our module directory)
Thanks that we get javacv.jar and javacpp.jar inside external libraries (if not, we
should restart Android Studio).
2) If we follow the Eclipse instruction on
javacv official site
we are now in point 4.:
Extract all the *.so files rom javacv-android-arm.jar,
opencv-2.4.8-android-arm.jar, and ffmpeg-2.1.1-android-arm.jar
directly into the newly created "libs/armeabi" folder, without
creating any of the subdirectories found in the JAR files.
We have to extract all *.so files which we need, but then we should join them to our project in other special way:
3rd answer here says about it,
but generally, we should:
Create new 'armeabi' directory
Put interesting .so files into 'armeabi' directory
Create armeabi.zip
Change extension of armeabi.zip to armeabi.jar
Put armeabi.jar to 'libs' directory
Make sure that build.gradle of our module contains such dependency:
compile fileTree(dir: 'libs', include: ['*.jar'])
3) Enjoy your OpenCV and JavaCv in Android Studio (and don't forget to add
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
to your AndroidManifest.xml if you want to read/save image from/to sdcard and try thanks this,
that your project works well).
/////////////////////////////////////////////////////////
If something is wrong, please write about it in comments.
If you try out with javacv 1.2, we have to do some additional steps so at to get this working. Here is my build.gradle file
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "org.audiorecording"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
//might need these if you use openCV
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
}
}
repositories {
mavenCentral()
}
configurations {
all*.exclude group: 'org.bytedeco', module: 'javacpp-presets'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'org.bytedeco:javacv:1.2'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.1.0-1.2', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.0.2-1.2', classifier: 'android-arm'
}

Categories

Resources