Yet another zip duplicate entry - java

I've use Kryo libs and it's pretty good. However, when I want to create a signed APK, it keeps failing to build because of the error:
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
java.io.IOException: Can't write [C:\AndroidProjects\App\app\build\intermediates\transforms\proguard\release\jars\3\1f\main.jar] (Can't read [C:\AndroidProjects\App\app\importLibs\minlog-1.3.0.jar(;;;;;;**.class)] (Duplicate zip entry [minlog-1.3.0.jar:com/esotericsoftware/minlog/Log$Logger.class]))
build gradle (module app)
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-ads:9.4.0'
compile 'com.android.support:design:24.1.1'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile files('importLibs/kryo-2.23.0.jar')
compile files('importLibs/minlog-1.3.0.jar')
compile files('importLibs/objenesis-2.1.jar')
compile files('importLibs/reflectasm-1.10.1-shaded.jar')
}
proguard file
proguard-rules.pro
-dontwarn com.esotericsoftware.**
-dontwarn org.objenesis.**
-keep class com.esotericsoftware.**{*;}
What exactly do I need to write to make it work?

There can be case where a library is part of another library that you have imported in your project
Check the lib dependency tree using following command
For Android, use this line
gradle app:dependencies
or if you have a gradle wrapper:
./gradlew app:dependencies
Or else there is a less popular Android studio plugin called GradleView that can give you entire lib tree used in your application and also where it might be clashing with some other library.

I had similar problem, and I solved it with just including retrofit:
'com.squareup.retrofit:retrofit:1.9.0'
I hope it will help you too.

Related

Error: json defines classes that conflict with classes now provided by Android

I got the following error when doing a release build on Android Studio 3
Error:Error: json defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
The following is my dependencies:
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:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.evernote:android-job:1.2.0'
compile 'com.amitshekhar.android:android-networking:1.0.0'
compile 'com.facebook.stetho:stetho:1.5.0'
compile "me.tatarka.redux:redux-core:0.10"
compile "me.tatarka.redux:redux-android:0.10"
compile "me.tatarka.redux:redux-android-lifecycle:0.10"
compile "me.tatarka.redux:redux-thunk:0.10"
annotationProcessor "org.immutables:value:2.5.5" // <-- for annotation processor
provided "org.immutables:value:2.5.5" // for annotations
provided "org.immutables:builder:2.5.5" // for annotations
compile "me.tatarka.redux:redux-monitor:0.10"
testCompile 'junit:junit:4.12'
}
It's saying json but I can't find which of the the above dependencies is causing the problem.
Here is what I get when I run
gradlew assembleRelease
Task :app:lintVitalRelease
/Users/kruyvanna/Projects/key/HappyKey_Android2/app/build.gradle: Error: json defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
Explanation for issues of type "DuplicatePlatformClasses":
There are a number of libraries that duplicate not just functionality of
the Android platform but using the exact same class names as the ones
provided in Android -- for example the apache http classes. This can lead
to unexpected crashes.
To solve this, you need to either find a newer version of the library which
no longer has this problem, or to repackage the library (and all of its
dependencies) using something like the jarjar tool, or finally, rewriting
the code to use different APIs (for example, for http code, consider using
HttpUrlConnection or a library like okhttp.)
1 errors, 0 warnings
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:lintVitalRelease'.
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
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
}
}
...
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org
I fixed it by adding:
configurations {
all {
exclude group: 'org.json', module: 'json'
}
}
to module gradle file, no removal of dependencies was needed.
Add this in your app/build.gradle
configurations {
all {
exclude module: 'commons-logging'
}
}
Go to the commandline and look at the dependency tree. This will give you a list of everything that your app uses:
./gradlew dependencies
I added dependencies one by one and found this one causing the error
compile "me.tatarka.redux:redux-monitor:0.10"

Getting a DuplicateFileException when adding a module to my Android app

I am trying to add the Paho MQTT service (and client) to my Android app, but I am running into a com.android.builder.packaging.DuplicateFileException runtime exception, when running my app.
It appears to me that everything is setup right, and when I clean/build, I get no errors at all.
My app build.gradle file looks like:
dependencies {
compile fileTree(dir: '../org.eclipse.paho.android/service/libs', excludes: ["org.eclipse.paho.client.mqttv3-1.1.0.jar"], include: '')
compile fileTree(include: ['*.jar'], dir: 'libs', excludes: ["*org.eclipse.paho.client.mqttv3-1.1.0.jar"])
compile (project(':org.eclipse.paho.android.service')){
// exclude module: "org.eclipse.paho.client.mqttv3"
transitive=true
}
// Uncommenting the below (when commenting out the above) WORKS.
// However, I need to be able to alter the source, to I do need to be able
// to import the Paho MQTT service as a module to my app.
// compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
// compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
...
However, when I run, I receive a DuplicateFileException exception:
* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK org/eclipse/paho/client/mqttv3/internal/nls/messages_zh_TW.properties
File1: /Users/me/.gradle/caches/modules-2/files-2.1/org.eclipse.paho/org.eclipse.paho.client.mqttv3/1.1.0/89d827ffa47c241f2627421ef1d6c7a8c207a341/org.eclipse.paho.client.mqttv3-1.1.0.jar
File2: /Users/me/myapp/code/myapp-android/org.eclipse.paho.android.service/build/intermediates/bundles/default/classes.jar
My file hierarchy looks like:
which appears ok to me.
Does anyone have any pointers on how to resolve this? The error claims that org.eclipse.paho.client.mqttv3-1.1.0.jar is clashing with classes.jar, but my gradle file explicitly excludes the compiling of org.eclipse.paho.client.mqttv3-1.1.0.jar (or so I think it does).
I'm at a loss here; any pointers are welcomed.
This happens because two of your dependencies are using Eclipse Paho MQTT library.
Following should fix the issue
Add following to your app level gradle file
packagingOptions {
exclude 'META-INF/ECLIPSE_.SF'
exclude 'META-INF/ECLIPSE_.RSA'
}
compile("one-of-your-dependency:1.0.0"){
exclude group: 'org.eclipse.paho'
}

Gradle DSL method not found: exclude()

i am using a lot of library in my project. And some libraries using same jar file therefore i writed this on build.gradle :
dependencies {
compile fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.twotoasters.jazzylistview:library:1.2.1'
compile 'com.google.firebase:firebase-core:10.2.4'
compile 'com.google.firebase:firebase-database:10.2.4'
compile 'com.orhanobut:dialogplus:1.11#aar'
compile 'com.github.recruit-lifestyle:FloatingView:2.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.nineoldandroids:library:2.4.0'
compile ('com.specyci:residemenu:1.6+'){
exclude group: 'com.nineoldandroids', module: 'library' }
compile files('libs/poppyview.jar'){
exclude group: 'com.nineoldandroids', module: 'library' }
}
And i am getting error :
Error:(54, 0) Gradle DSL method not found: 'exclude()'
Possible causes:The project 'DopingEng' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 2.3.1 and sync projectThe project 'DopingEng' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
Gradle already update , how can i solve this problem ?
Here's the problem
compile files('libs/poppyview.jar'){
exclude ...
}
A file based dependency does not work in the same way as a dependency coming from a repository. There is no meta data associated with it (eg no dependency information) so there's also nothing to exclude (since there's no transitive dependencies).
Do you have the pom/ivy meta-data for libs/poppyview.jar? If so then you shouldn't declare it like this (I suggest a local maven repository folder). If you don't then there's nothing to exclude

Manifest Merger Error - Different versions of support library

I'm adding the stepper indicator library - https://github.com/badoualy/stepper-indicator - to my project. To do so, I added jitpack to my project gradle file and the stepper-indicator library to my app gradle file. However, I'm getting the following build error:
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute meta-data#android.support.VERSION#value value=(25.4.0) from [com.android.support:preference-v14:25.4.0] AndroidManifest.xml:25:13-35
is also present at [com.android.support:appcompat-v7:26.0.0-beta2] AndroidManifest.xml:28:13-41 value=(26.0.0-beta2).
Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:23:9-25:38 to override.
The other dependencies in my app include:
compile 'com.android.support:preference-v7:25.4.0'
compile 'com.android.support:preference-v14:25.4.0'
compile 'eu.davidea:flexible-adapter:5.0.0-rc2'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:recyclerview-v7:25.4.0'
compile 'com.android.support:cardview-v7:25.4.0'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-gcm:11.0.2'
compile 'com.google.android.gms:play-services-auth:11.0.2'
compile 'com.google.android.gms:play-services-ads:11.0.2'
compile 'com.google.firebase:firebase-messaging:11.0.2'
compile 'com.google.firebase:firebase-auth:11.0.2'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
Without upgrading all of the android support libraries to an alpha version, is there a solution to this problem?
In build.gradle you can exclude conflicting dependencies. For example:
compile ('com.github.badoualy:stepper-indicator:1.0.7'){
exclude group: 'com.android.support', module: 'appcompat-v7'
}
To inspect dependencies, you can use Gradle toolbar in Android Studio -> application module -> tasks -> android -> androidDependencies
Update:

Using Java Native (Class Library) Jar in Android Studio project

I have class libraries I've developed in Netbeans, for java native applications. I would like to use this functionalities in Android app project, instead of writing the whole code again.
I know how to create Jar in netbeans and add it as a dependency(or even a separate module) in the android project.
but it seems I cannot use the code when I call the related function explicitly.
Let's say I have the following Scheme in Netbeans:
CommonLogicLayer (Class Library)
--->SourcesPackages
---><default package>
--->FileTest
Inside fileTest.java I have function named: Test(String fullPath) that gets the path of a file and print its content. very simple.
After building the library (for Jar file), I insert the jar in libs folder, compile the android app, and in onCreate function I tried to call the jar like that:
CommonLogicLayer.FileTest.Test("c:\\text.txt")
Even though, the builder (Gradle File) add CommonLogicLayer as a dependency:
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.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile project(':utilitiesandroid')
compile project(':commonutilities')
compile project(':CommonLogicLayer')
}
I cannot use its functions as I desire.
I also tried adding the jar as a Module, and add this module as a dependency, but still no results.
So my question is:
Can Android studio has java native libraries that are not (android studio/Eclipse)
If 1 is 'Yes', what am I doing wrong?
If 1 is 'No', what is the work around for it instead of replicate the code?
Much Obliged!

Categories