I've just started using Android Studio and Gradle and I'm facing a conflict error when I try to run my app. I've already done some research and the problem is that HoloEverywhere uses a custom support-v4 library (some internal classes have its visibility changed) that differs from the support-v4 library used by other libs, in this case Google Play Services. I've read in some posts like here to use the same support-v4 library across all modules, but in this case I can't do it because without the custom support-v4 library, the HoloEverywhere doesn't work and I can't touch the support-v4 library used by Google Play Services. I hope someone has already experienced this and found a solution, because this is driving me nuts :)
Here is the error log:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/diego/Documents/android-sdk-macosx/build-tools/19.0.1/dx --dex --output
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/libs/app-debug.dex
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/classes/debug
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/dependency-cache/debug
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/classes-2c9d7b640eaa13481d9d1c220b95094b847d6825.jar
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/classes-2edf2d8c7b1a7575431e0269a325d54bdc9fc798.jar
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/classes-bc16442b2fdfdfc88911109da1e6baf89a7938a0.jar
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/nineoldandroids-2.4.0-1e541581bdb9515af0d791ecbc51193b05f1c93a.jar
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/support-v4-13.0.0-2f3822466a4631d8fa7d69b3fd104b27f4df0298.jar
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/support-v4-19.0.1-a98845f591723a85fad8ed448a9cc0ced3cb3194.jar
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/support-v4-19.0.1a-f1f3d357780dd5b4d33c6ca1830109136769ef22.jar
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
settings.gradle:
include ':app'
include 'Volley'
include 'Facebook'
include 'ViewPagerIndicator'
include 'HoloEverywhere'
project(':Volley').projectDir = new File(settingsDir, 'libraries/volley')
project(':Facebook').projectDir = new File(settingsDir, 'libraries/facebook-android-sdk/facebook')
project(':ViewPagerIndicator').projectDir = new File(settingsDir, 'libraries/Android-ViewPagerIndicator/library')
project(':HoloEverywhere').projectDir = new File(settingsDir, 'libraries/HoloEverywhere/library')
build.gradle in the 'app' directory:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile project(':Volley')
compile project(':Facebook')
compile project(':ViewPagerIndicator')
compile project(':HoloEverywhere')
}
build.gradle in the 'HoloEverywhere/library' directory:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
dependencies {
compile files ('libs/support-v4-19.0.1.jar')
compile files ('libs/nineoldandroids-2.4.0.jar')
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
After some trial and error and thanks to @pyus13 and @Prototik tips, I was able to run my project using Android Studio. I removed all local copies of the dependency libraries, except for the ViewPagerIndicator. Here are the working gradle files:
settings.gradle:
include ':app'
include 'ViewPagerIndicator'
project(':ViewPagerIndicator').projectDir = new File(settingsDir, 'libraries/Android-ViewPagerIndicator/library')
build.gradle in the 'app' directory:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
classpath 'org.holoeverywhere:plugin:0.2.+'
}
}
apply plugin: 'holoeverywhere'
apply plugin: 'android'
repositories {
mavenCentral()
}
holoeverywhere {
addons {
create 'preferences'
create 'slider'
}
library {
version '2.1.0'
}
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.google.code.gson:gson:2.2.+'
compile 'com.mcxiaoke.volley:library-aar:1.0.+@aar'
compile 'fr.avianey:facebook-android-api:3.6.+@aar'
compile project(':ViewPagerIndicator')
}