7

When I run ./gradlew assembleDebug I'm getting:

:app:dexDebug 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:
    /home/grub/Main/android-sdk-linux/build-tools/19.1.0/dx --dex --num-threads=4 --output 

List of merged classes and jars:

UNEXPECTED TOP-LEVEL EXCEPTION:
        com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

It's very similar to this question and problem should be in multiple support-v4 libraries. I cleaned up build.gradle :

repositories {
    maven { url "http://dl.bintray.com/populov/maven" }
    mavenCentral()
}

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.1.0'

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 8
        versionName "2.1.17"
    }
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:support-v4:20.+'
        compile ('com.google.android.gms:play-services:5+'){
            exclude group: 'com.android.support', module: 'support-v4'
        }
        compile(project(':libraries:com.typefacedwidgets')) {
            exclude group: 'com.android.support', module: 'support-v4'
        }
        compile(project(':libraries:com.truepagerindicator')) {
            exclude group: 'com.android.support', module: 'support-v4'
        }
        compile ('com.sothree.slidinguppanel:library:+'){
            exclude group: 'com.android.support', module: 'support-v4'
        }
        compile ('com.github.chrisbanes.pulltorefresh:sample:2.1.1+'){
            exclude group: 'com.google.android', module: 'support-v4'
        }
        compile 'com.thoughtworks.xstream:xstream:1.4.7'
        compile 'com.squareup.retrofit:retrofit:1.6.1'
        compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
        compile 'com.squareup.okhttp:okhttp:2.0.0'
        compile 'com.google.code.gson:gson:2.3'
        compile 'de.greenrobot:eventbus:2.2.1'
    }
}

To check dependencies I did ./gradlew -q -dependencies which is showing:

+--- com.android.support:support-v4:20.+ -> 20.0.0
|    \--- com.android.support:support-annotations:20.0.0
+--- com.google.android.gms:play-services:5+ -> 5.2.08
+--- project :libraries:com.typefacedwidgets
+--- project :libraries:com.truepagerindicator
+--- com.sothree.slidinguppanel:library:+ -> 2.0.1
|    \--- com.nineoldandroids:library:+ -> 2.4.0
+--- com.github.chrisbanes.pulltorefresh:sample:2.1.1+ -> 2.1.1
|    +--- com.github.chrisbanes.pulltorefresh:library:2.1.1
|    +--- com.github.chrisbanes.pulltorefresh:extra-listfragment:2.1.1
|    |    \--- com.github.chrisbanes.pulltorefresh:library:2.1.1
|    \--- com.github.chrisbanes.pulltorefresh:extra-viewpager:2.1.1
|         \--- com.github.chrisbanes.pulltorefresh:library:2.1.1
+--- com.thoughtworks.xstream:xstream:1.4.7
|    +--- xmlpull:xmlpull:1.1.3.1
|    \--- xpp3:xpp3_min:1.1.4c
+--- com.squareup.retrofit:retrofit:1.6.1
|    \--- com.google.code.gson:gson:2.2.4 -> 2.3
+--- com.squareup.okhttp:okhttp-urlconnection:2.0.0
|    \--- com.squareup.okhttp:okhttp:2.0.0
|         \--- com.squareup.okio:okio:1.0.0
+--- com.squareup.okhttp:okhttp:2.0.0 (*)
+--- com.google.code.gson:gson:2.3
\--- de.greenrobot:eventbus:2.2.1

It seems like it should be OK but problem remains the same.

UPDATE:

The problem was in apkLib dependency and confuse msg from Gradle. It was solved like in this answer putting Android-PullToRefresh into separate android library project in Gradle.

Community
  • 1
  • 1
ar-g
  • 3,417
  • 2
  • 28
  • 39
  • In my case similar error occurred because of multiple support-v4 jar files. To solve it, I went to Build Path > Configure Build Path > Libraries tab. Then locate Android private libraries and removed. Clean the project and run. – Satish Gadhave Aug 19 '14 at 13:16
  • @Satish Gadhave What do you mean by this? I'm exclude all other support-v4 libraries from other dependencies and left only one. But it steal occur. – ar-g Aug 19 '14 at 13:47
  • possible duplicate of [Pulltorefresh add to gradle](http://stackoverflow.com/questions/22007586/pulltorefresh-add-to-gradle) – Scott Barta Aug 19 '14 at 16:55
  • I think it's getting confused because you're trying to pull in the sample as a dependency, which has a transitive dependency on the apklib, and Gradle doesn't know what to do with apklibs. AS an aside, your exclude for pulltorefresh is set up wrong (com.android.support not com.google.android), but fixing it doesn't solve the problem – Scott Barta Aug 19 '14 at 16:56
  • 1
    I've filed https://code.google.com/p/android/issues/detail?id=75039 about this; Gradle should provide a better error message when you try to depend on an apklib. – Scott Barta Aug 19 '14 at 17:29
  • @Scott Barta Thanks! It really was the problem of confuse error msg, we migrate old code-base to gradle and didn't know about it. – ar-g Aug 20 '14 at 08:25

3 Answers3

2

This error appeared to me when I imported some libs that required Google Play services,

I just passed from:

compile 'com.google.android.gms:play-services:6.5.87'

to:

compile ('com.google.android.gms:play-services:6.5.87') {
    exclude module: 'support-v4'
}

Now it builds ok

htafoya
  • 18,261
  • 11
  • 80
  • 104
0

The problem was in apkLib dependency and confuse msg from Gradle. It was solved like in this answer putting Android-PullToRefresh into separate android library project in Gradle.

Community
  • 1
  • 1
ar-g
  • 3,417
  • 2
  • 28
  • 39
-1

I just rebuilded the Project. Solved

Boris
  • 9