I'm trying to migrate an old IntelliJ project to use gradle. However, assembleDebug fails during the dx step:
java.lang.IllegalArgumentException: already added: Lcom/google/inject/AbstractModule;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
at com.android.dx.command.dexer.Main.processClass(Main.java:490)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
at com.android.dx.command.dexer.Main.access$400(Main.java:67)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
at com.android.dx.command.dexer.Main.processOne(Main.java:422)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
at com.android.dx.command.dexer.Main.run(Main.java:209)
at com.android.dx.command.dexer.Main.main(Main.java:174)
at com.android.dx.command.Main.main(Main.java:91)
My project is split into two subprojects: a main project and a library project. Both these project have Roboguice and Guice as dependencies.
I tried Xav's suggested workaround for including the support library in multiple projects as mentioned in this answer. The workaround should probably not even be necessary, given that roboguice/guice are both picked up from maven central. I created a dummy library project that's the only project that depends on roboguice/guice. I made it so that my main project and the (true) library project both depend on this dummy project. However, I get the same error.
How can this be fixed?
settings.gradle in the root directory:
include 'MainApp'
include 'library'
include 'common-library'
build.gradle in the root directory:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
allprojects {
version = '1.0'
repositories {
mavenCentral()
}
}
apply plugin: 'android-reporting'
build.gradle in the main project and the real library project:
apply plugin: 'android'
android {
compileSdkVersion 15
buildToolsVersion "17.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
dependencies {
compile project(':library') // only in main, not in real library
compile project(':common-library')
}
build.gradle in the dummy library project:
apply plugin: 'android-library'
android {
compileSdkVersion 15
buildToolsVersion "17.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
dependencies {
compile 'org.roboguice:roboguice:2.0'
compile 'com.google.inject:guice:3.0'
}