The problem:
Gradle error: "Multiple dex files define Lorg/apache/http/impl/conn/AbstractClientConnAdapter;"
The question:
The error message doesn't include much detail. Is there a way to find out which files it's referring to? How can I narrow this down? I'm hoping there's an easy way to do this.
What I've tried:
Putting this for each library in the Gradle file:
exclude module: 'org.apache.http.impl.conn.AbstractClientConnAdapter'
E.g.
implementation (group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2') {
exclude module: 'org.apache.http.impl.conn.AbstractClientConnAdapter'
}
However this doesn't seem to make a difference as I still get the error. I have a multi module project but I'm only running "assemble" on one module which I believe is the problem. There are only 4 library dependencies and no local jars for this module.
What am I not understanding about how "exclude works"? If they're all excluded then where is it coming from?
Other Info:
This is an Android project but the module I'm having the problem with is a pure Java module.
I'm using Android Studio 3.0.
p.s. what is the "L" before org in the error?
Related
I’m trying to use dl4j in my project which runs on openjdk-15.0.2.7 and I use gradle to manage my dependencies. The project builds with no errors but when the code is executed it crashes immediately with the error:
java.lang.module.InvalidModuleDescriptorException: Provider class com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderSpi not in module
I haven’t really worked with java modules, since I have only used java 8 so far but to me this looks like its missing a bunch of packages and I don’t know what to do about it. Do I need to put something into the module-info.java file? I have not used any dl4j classes or methods so far in the project.
Thanks in advance.
Here is how I added the dependencies:
implementation group: ‘org.deeplearning4j’, name: ‘deeplearning4j-core’, version: ‘1.0.0-beta6’
implementation group: ‘org.nd4j’, name: ‘nd4j-cuda-10.2-platform’, version: ‘1.0.0-beta6’
I've been having this issue on and off for the past few weeks after beginning to learn how to use Gradle.
I added the dependency to my build.gradle file
compile group: 'org.apache.xmlgraphics', name: 'batik-all', version: '1.12', ext: 'pom'
I used VSCode's command palette to "refresh", cleaned the server workspace and ran gradle build but the new dependency does not show up in my "Project and External Dependencies" and I cannot import org.apache.batik.*
Hoping to find a fix for this in VSCode as I have seen some other IDE specific fixes.
So the issue was that in the map notation you were specifying the ext: 'pom' part. This effectively told Gradle to only import the POM file and not treat the dependency as a regular one.
When you moved to the different notation, you did not keep that pom element in the coordinates and so you got the right behaviour.
Note: compile has been replaced by implementation for a while now and is even deprecated in Gradle 6.x. Have a look at the documentation for more information on this.
I have tried many different ways of getting Vimeo networking into my app, but nothing has worked. If I remove the implementation it works just fine so I know this is the issue.
compile 'com.vimeo.networking:vimeo-networking:1.1.1'
gives me this error
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
I have searched all over and have yet to find a solution (yes I have tried cleaning and rebuilding the project)
SOLUTION: anthonycr's answer was perfect, but I also had to do this:
implementation ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version") {
exclude group: 'org.jetbrains', module: 'annotations'
}
implementation ('com.vimeo.networking:vimeo-networking:1.1.1') {
exclude group: 'org.jetbrains', module: 'annotations'
}
I believe this is the result of the vimeo-networking library including a dependency which you are also separately including in your gradle file. Looking at the gradle file for a hint, a prime suspect is the intellij annotations jar 'com.intellij:annotations:12.0#jar' dependency, which I have seen cause similar problems when also included in your main project as well as a sub-projects.
The solution to this is to exclude the annotations jar when compiling in the vimeo-networking library as follows:
compile ('com.vimeo.networking:vimeo-networking:1.1.1') {
exclude group: 'org.jetbrains', module: 'annotations'
}
Try this and see if it fixes your build exception. Generally I've seen that the cause for the Unable to merge dex error is that there are multiple definitions of the same class in the final dex file, usually resulting from the inclusion of a jar file multiple times.
I am trying to use HtmlUnit which lists xml-apis-1.4.01.jar as a dependency. Though whenever I include this file in the libs/ directory I get the following error:
Error: trouble processing "javax/xml/XMLConstants.class":
Error: Ill-advised or mistaken usage of a core class (java.* or javax.*)
...
Could anyone help me resolve this.
Thanks!
First of all, don't put .jars into libs folder, as you will quickly run into dependency hell. Use gradle build system for that. In your app module build.gradle file declare such dependency:
compile ('net.sourceforge.htmlunit:htmlunit:2.23') {
exclude module: 'commons-logging'
exclude module: 'httpclient'
}
And everything will build correctly.
I'm not used to post questions so please excuse my mistakes.
I'm looking into moving to Gradle+Nexus for my company and I've hit a wall.
I will try to describe my problem as clearly as possible.
I wrote 2 simple java programms, one depends on the other, both depends on junit to run theirs tests.
I could compile, test and run them while I was using Maven repository but one of the goals of using Nexus is to have 3rd party libraries on it as well as ours. While using Maven I could upload my builds to Nexus and also use them to compile with (through the dependencies) so no problem there.
But when I downloaded junit and uploaded it to Nexus I could not compile anymore.
Here is the error message I got:
Could not resolve all dependencies for configuration ':Project2:testCompile'.
>Could not find junit.jar (junit:junit:4.12).
Searched in the following locations:
http://mycompany/nexus/content/repositories/TRUNK_3rdParty/junit/junit/4.12/junit-4.12.jar
So gradle looks at the right place but cannot find junit.
I should mention that I uploaded junit using the POM file provided by Maven so everything should work.
As it might be of help, here are some code fragments from my build.gradle file:
repositories {
maven {
url "http://mycompany/nexus/content/repositories/TRUNK/"
}
}
dependencies {
compile group: 'mycompany', name: 'project1Nexus', version: '1.0-TEST'
}
that tells project2 where to find project1 on Nexus in order to compile (it works).
repositories {
maven {
url "http://mycompany/nexus/content/repositories/TRUNK_3rdParty/"
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
and that should tell where to find junit but I get this error message.
Also the first repo/depend block is from the build.gradle file of project2 and the second one is from the one of the root folder. I doubt this could be an issue though as it worked fine when I used centralMaven.
If anyone had some insights to share, it would be amazing!
Cheers