7

I can integrate (add & work) with many libraries.

But as for ActionBarSherlock library, I have so many problems with it.

First Issue is the popular issue Multiple dex files define,

I know The duplicated android-support-v4.jar causes it, but I can not solve this issue now :

Error:Execution failed for task ':fitness:dexDebug'.

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)

I followed the answer in same error. It used :

dependencies {
    compile('...') {
      exclude module: 'support-v4'
    }

    compile 'com.android.support:support-v4:18.0.+'
}

But I received Second Issue : unsupported Gradle DSL method found: 'exclude()'! error. Therefore I changed build.gradle of main module like this:

//configurations {
//    all*.exclude group: 'com.android.support', module: 'support-v4'
//}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':google-play-services')
    compile files('/google-play-services/libs/google-play-services.jar')
    compile (project(':actionbarsherlock')) {
        exclude(module: 'support-v4')
    }
    compile 'com.android.support:support-v4:18.0.+'
}

Solved Second Issue, But still get First Issue Multiple dex files define error.

I read many topics, but can not solve First Issue now,

Please help me,

Thanks,

p/s : I can sync with Gradle successully, but when run, it get above errors.

I used Android studio 0.5.5

EDIT

build.gradle of ActionBarSherlock, it has only one android-support-v4.jar:

dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
}

setting.gradle like this :

include ':fitness', ':google-play-services',':actionbarsherlock'

@Garbriele : I updated new question, show build.gradle of project and build.gradle of main module build.gradle of project:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

build.gradle of main module after edited :

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' // Get following error in this line
} 

I got this error in below :

enter image description here

Okay, thanks for @Garbriele comment, I already fixed this by using this :

repositories {
            mavenCentral()
        }
dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' // Get following error in this line
    } 

EDIT 2 When I put like this :

repositories {
            mavenCentral()
        }
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.google.android.gms:play-services:+'
}

Still get First Issue Multiple dex files define error.

What I want now is how to add com.google.android.gms:play-services library via Maven successfully,

Please help me,

Thanks,

UPDATE

After followed these steps :

  • Put the library via Maven in build.gradle of main module : compile 'com.google.android.gms:play-services:+'

  • Restart Android Studio

  • Sync project with gradle

No longer get this error again.

Community
  • 1
  • 1
Huy Tower
  • 7,769
  • 16
  • 61
  • 86
  • You could use compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' and compile 'com.google.android.gms:play-services:4.3.23' to remove local libraries. – Gabriele Mariotti Apr 24 '14 at 09:34
  • When I put `compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'` (it means download this library via maven). My gradle can not sync anymore `Gradle project sync failed ...`. U can help me fix this? – Huy Tower Apr 24 '14 at 10:23
  • 1
    Did you add "repositories { mavenCentral() }" to your build.gradle? – Gabriele Mariotti Apr 24 '14 at 10:45
  • I'm finding it really hard to follow your question. Can you please edit it and highlight what you're currently having problems with? I'm confused by the parts where you were having trouble with something but then solved it. – Scott Barta Apr 24 '14 at 16:20
  • @ScottBarta : Updated new question for u to know more detail. Still get main error as title of question. Please tell me the solution? – Huy Tower Apr 25 '14 at 02:31

2 Answers2

4

So strange,

When I setup my dependencies like this :

repositories {
            mavenCentral()
        }
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.google.android.gms:play-services:+'
}

I still get the First Issue Multiple dex files define error.

But after following these steps:

  • Put the library via Gradle in build.gradle of main module : compile 'com.google.android.gms:play-services:+'

  • Restart Android Studio

  • Sync project with gradle

I no longer get this error.

PLNech
  • 3,087
  • 1
  • 23
  • 52
Huy Tower
  • 7,769
  • 16
  • 61
  • 86
1

I had duplicate libraries in my libs directory:

$ ls -la libs/
total 80
drwxr-xr-x   5  wheel    170 25 Sep 22:09 .
drwxr-xr-x  10  wheel    340 25 Sep 22:07 ..
-rw-r--r--   1  wheel   3736 25 Sep 21:36 ApiComponent.jar
-rw-r--r--   1  wheel  28741 25 Sep 21:36 DependencyService.jar
-rw-r--r--   1  wheel   3736 25 Sep 22:09 classes.jar

Removing classes.jar worked for me. I modified my DependencyService Project to produce DependencyService.jar instead of classes.jar causing the duplication.

Gary Davies
  • 920
  • 15
  • 12