I have two libs in my gradle file that require slf4j. Pusher and Gimbal. Both of these jars have slf4j in them. So even when I tell gradle to ignore them (multiDexEnabled true) I still receive a namespacing error.
Does anyone know how to fix this?
com.android.dex.DexException: Multiple dex files define Lorg/slf4j/impl/StaticLoggerBinder;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
The error I receive with (multiDexEnabled true):
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
>java.util.zip.ZipException: duplicate entry: org/slf4j/helpers/BasicMarker.class
Multidex solves a very different problem from the one you describe. Multidex fixes the issue of being limited to ~65,000 methods per dex file. You can find the documentation for multidex here.
Instead, what you want to do is exclude sl4j from one of your libraries, here's an example of what that might look like, depending on what dependencies are causing the issue:
compile ('com.example.library:library-with-sl4j:1.0') {
exclude group: 'org.sl4j', module: 'sl4j-simple'
}
You will have to identify which library is causing the issue and which sl4j module you need to exclude.
Ideally you would inform the library author(s) using older versions that they should update so that all your dependency are using the same (latest) version.
Related
I have a project structure as:
- app module
- multiple library modules..
- ...
- common library module (commonlib) consumed by the library modules above^ (has realm (compile 'io.realm:realm-android:0.82.2') included as dependency)
now the commonlib is included as dependency in many modules and when I tried to run the project then I got the multiple dex files found error:
:app:preDexDebug UP-TO-DATE
:app:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lio/realm/DefaultRealmModule;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/user/java/jdk1.7.0_75/bin/java'' finished with non-zero exit value 2
Can anyone help me in how I can include the realm library but at the same time include it and the commonlib module in all the dependent modules as well? Thanks
It looks some of your library projects haven't defined their Schemas as library modules. If they do not, they will also create the file DefaultRealmModule which is why you get the conflict in the app project.
All your libraries should have a class that looks something like this:
#RealmModule(library = true, allClasses = true)
public class MyLibraryModule() {
}
You can read more how to include Realm in both library and app projects here: https://realm.io/docs/java/latest/#sharing-schemas
I have imported project from Eclipse to Android studio. It builds successfully, but when I try to execute the project in android studio I am getting following exception .
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple
dex files define Landroid/support/annotation/AnimRes; at
com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at
com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at
com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303) at
com.android.dx.command.dexer.Main.run(Main.java:246) at
com.android.dx.command.dexer.Main.main(Main.java:215) at
com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command
'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with
non-zero exit value 2
And here is my Build.gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.heal4me_app"
minSdkVersion 11
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile files('libs/android-support-v13.jar')
}
I have tried all the posted solution for the above problem, which is available on stackoverflow. But I couldn't find any right answer for this problem.
I had the same issue after adding the library com.amazonaws:aws-java-sdk:1.8.0 to my gradle dependencies. After removing the dependencie, everything seems to be fine. I don't know why, if I find a solution I report it.
After the many efforts I have to finally do the hard work to migrate from eclipse to android studio.
I have copied all the java classes and xml file one by one to the android studio. And finally I am done. I think this is not the good solution but I have to do this compulsorily to resolve above error.
I have read so many blogs and stackoverflow questions regarding this issue. but unfortunately that didn't help me, that's why I have to come up with this hard work.
I am using render script in support library in my gradle file.
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
After I added these 2 lines, I am getting this error
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
UNEXPECTED TOP-LEVEL EXCEPTION:com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command 'C:\Program
Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2
I've had similar issue. Try add to your gradle file
multiDexEnabled true
just to be sure you are not exceeding the 65K methods dex limit imposed by Android (Java finished with non-zero exit value 2 - Android Gradle). If you are using some other android-support libraries like appcompat or design or support-v4/v7... add another line to your gradle file
configurations {
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
Renderscript library already includes support-annotations library, which then may collide with those other support libraries, I suppose. Anyway, these gradle commands fixed it for me.
Edit: It was supposedly fixed in 23.1.0 revisions of Android support libraries, therefore after updating to 23.1.0 you'd need to remove that all*.exclude command. Otherwise your app would not compile due to missing support-annotations library.
https://code.google.com/p/android/issues/detail?id=181697 is the bug for this, along with a temporary workaround.
dexOptions {
preDexLibraries = false
}
In your build.gradle file try adding the following block inside your android block.
Use
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
I have configured the following dependencies in Gradle, inside Android Studio.
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/android-support-v13.jar')
compile files('libs/apache-mime4j-storage-0.7.2.jar')
compile files('libs/commons-cli-1.1.jar')
compile files('libs/commons-io-1.2.jar')
compile files('libs/httpclient-4.3.4.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.3.4.jar')
compile files('libs/rabbitmq-client.jar')
compile files('libs/retrofit-1.7.1.jar')
compile files('libs/universal-image-loader-1.9.3-with-sources.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.google.android.gms:play-services:7.0.0'
But Gradle gives me the following error:
Execution failed for task ':app:dexDebug'.
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
D:\AS sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Users\ttuser\ASProjects\MyProject\app\build\intermediates\dex\debug --input-list=C:\Users\ttuser\ASProjects\MyProject\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
How can I solve it?
app:dexDebug error in general means that you've tried to link in the duplicate class to your project more than once. So remove your Duplicate Library
I don't know if you figured it out yet, but seeing as all of those are publicly available libraries, I suggest getting rid of the JARs and getting them as a dependency from JCenter/Maven Central. If you are not sure how to do this, here is an example. One library you are using is Retrofit, so you would go to a website like Maven Central (http://search.maven.org/) and search for the library and get the Gradle dependency for your version (http://search.maven.org/#artifactdetails|com.squareup.retrofit|retrofit|1.7.1|jar):
compile 'com.squareup.retrofit:retrofit:1.7.1'
Do this for all of your dependencies. Once you have them set up as Gradle dependencies instead of JARs, you can do what is explained here: https://stackoverflow.com/a/21100040/2245921
Basically, go into your :app folder through a terminal, and run the following:
../gradlew -q dependencies
And Gradle will draw a dependency tree. There you will be able to see duplicate dependencies and more easily deal with them.
I am a new Android Developer and build files always scare me. :D
I am using some third part libraries in the project
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.github.flavienlaurent.datetimepicker:library:0.0.2'
}
In addition to this I am also using MPAndroidChart(the only jar in the lib folder) which is only available as a jar file and not a gradle dependency.
MPAndroidChart uses NineOldAndroids as a dependency and I suspect one of my other libraries also uses it and it is causing a build fail.
Any idea how to make both these libraries behave?
I checked the similar questions and found one that was exactly my problem-
Gradle error - Execution failed for task ':app:dexDebug'
But he was including the NineOldAndroids library on his own. So he just removed that line and it was working.
One idea that I had was to strip apart the jar and include them as java files in my project, but that seemed like overkill for this problem. I'm sure there must be an easier way?
This is my entire error
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/nineoldandroids/animation/ValueAnimator$AnimatorUpdateListener;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\manu.joseph\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Users\manu.joseph\AndroidStudioProjects\WriteTrack\app\build\intermediates\dex\debug --input-list=C:\Users\manu.joseph\AndroidStudioProjects\WriteTrack\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/nineoldandroids/animation/ValueAnimator$AnimatorUpdateListener;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Add this to your build.gradle :
configurations {
all*.exclude group: 'com.nineoldandroids'
}
Works fine for me ;)
Remove the following line and try again
compile 'com.android.support:support-v4:21.0.3'
I'm a new android developer and not long before I post this answer, I'm facing the same problem too. Googling and only 2 stackoverflow question showed up. Your question, and the stackoverflow question you provided there.
Somehow, after I remove the unused dependency library via project structures (ctrl+alt+shift+s), in my case, it is
compile 'com.rengwuxian.materialedittext:library:1.8.2'
sync the gradle and then poof! I hope it works for you too.
In the end, I ended up adding the library as an external project which did the trick for me.
Detailed instructions here..
How do I add a library project to Android Studio?
Hope this helps someone..