last day (15 days later) » 

7:34 PM
0
Q: Intellij: Avoiding 'Multiple Dex Files Defined'

bcorsoProblem: Up until now I've been using Gradle to handle all of my dependencies, and it seems to take care of any duplicate dependencies between other Gradle modules. However, this does not seem to be the case when a duplicate dependency exists within a jar. Question: Considering that I have con...

 
Why are you using jars? Post your build.gradle.
 
@JaredBurrows Basically, I have a Java project in Intellij that I build into a jar, and then import the jar as a module in Android Studio. The module is included in the build.gradle using compile project(':jarModule')
 
Post your all of your build.gradle.
 
@JaredBurrows okay posted it.
 
We all need to see your "jarModule" build.gradle. How else can we help determine what is conflicting?
 
7:34 PM
@JaredBurrows, Oh I know what is conflicting. In this case it's that I had Gson defined in the apps build.gradle and included in the jar. I have fixed the problem by removing Gson from my build.gradle, but my question is what is the best way to handle this.
 
Then what is the problem? I have the same dependencies in android library projects and android apps. Make sure they are the same version.
Hey
 
Hey
I'm not really sure What the problem is. It fails on the build saying that there are multiple dex files defined for Gson
 
Can you not post both build.gradle files so I can see?
 
hey, interesting question you have here, this part is usually messed up and people figure it out by experiment :)
 
What?
Question is very common.
 
7:37 PM
configurations.create("default")
artifacts.add("default", file('myJarFile.jar'))
that is all I have in the module that includes the jar
it was included automatically when I imported the jar as a module using Android Studios gui
 
i thought you have a separate build.gradle for the java module.
What is the jar?
Wait, did you just export your project from eclipse?
 
the jar is a Java project that I have built in Intellij (no android just pure java)
 
Ok, I woulg suggest creating a build.gradle for it.
 
Well, I guess this is where I'm confused
 
You can write java modules in Android Studio, it must be a pain to export the jar from another IDE everytime.
Do you have a build.gradle for the jar in Intellij?
 
7:40 PM
I have a build.gradle for the project in Intellij
and then I build the jar as an artifact
 
Well there you go.
 
The problem is the Intellij project needs to be in Intellij
 
If I were you, you can easily create a module for the java jar in your current android project.
why?
 
It started out as a Java project, and will continue to be used as a java project
but I need to use it in android and I dont want to rewrite the code
so that's why im packaging it as a jar and just using that
 
Why would you "re-write" the code?
It is all java.
You are confusing yourself.
The easiest solution is to create a module in your current project, add the code there, and copy the build.gradle over.
 
7:43 PM
Yes, but will they continue to be synced if I make changes to the intellij version
 
configure("MY_JAVA_PROJECT") {
// your current build.gradle form intellij in here
}
Why are you using two different IDEs if this is going to be used in Android.
 
The intellij project is the main project and code will be maintained/changed there. I simply want to use that code in Android Studio
The code is primarily used to build a jar and run on our server
 
Are both GSON versions the same?
 
yes they were
 
Also, where the exceptoin for the conflicting versions?
I do not see gson in your build.gradle you posted
 
7:46 PM
yes, that was because I fixed the problem by removing the gson from my Android studio build.gradle (since it was already included in the jar)
 
Ok, I was jsut about to say that
So there is no problem anymore.
 
No, but I don't feel like this is the best way to do it
 
because say i include another jar file that also contains gson
 
Main Java library -> Android project
This is what build.gradles are for. You want to use jars.
 
7:47 PM
it seems better to me to include a jar with no dependencies included and somehow use gradle to include them
 
is your jar open source?
 
no
 
I was going to say, you could push to jcenter and add it to your build.gradle as a gradle/maven depdendency.
So your best bet is to remove the dependency from your app and leave it in your jar.
With gradle dependencies, you can exclude dependencies from other dependencies. With jars, you can not.
 
Alright, thank you sir for your help
 
So what is your plan now? ha
 
7:51 PM
Well it seems to be working as is; i.e. by including all of the dependencies in the jar.
 
Do you mind if I create an answer?
 
Yeah sure
 
Ok thanks.
Hey
Are you going to update your app `build.gradle`? compileSdkVersion 19
buildToolsVersion '19.1.0'
To target the latest?
And are you using instrumentTest.setRoot('tests')?
You still there?
 

last day (15 days later) »