2

I can not compile the project gets the following error compilation:

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

com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\Program Files (x86)\Android\android-studio\sdk\build-tools\21.0.2\dx.bat --dex --output C:\Users\Android Studio\Android Studio\myApp\build\intermediates\dex\debug --input-list=C:\Users\myApp\Downloads\Android Studio\Android Studio\myApp\build\intermediates\tmp\dex\debug\libraryList.txt 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:596)

Of course, this code solve my problem

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

but unfortunately does not satisfy me

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

    compile 'com.android.support:support-v4:21.+'
    compile project(':PullToRefreshListFragment')
    compile project(':validator')
    compile project(':AndroidBootstrap')

    compile 'com.google.android.gms:play-services:6.+'
    compile 'com.android.support:appcompat-v7:21+'

    compile 'com.github.codechimp-org.apprater:library:1.0.+'
    compile 'com.sothree.slidinguppanel:library:+'
    compile 'me.grantland:autofittextview:0.2.+'
    compile 'io.realm:realm-android:0.71.0'

    compile ('com.loopj.android:android-async-http:1.4.6')
    {
        exclude group: 'com.google.android', module: 'support-v4'
    }

    compile('de.keyboardsurfer.android.widget:crouton:1.8.5@aar') {
        exclude group: 'com.google.android', module: 'support-v4'
    }

    compile ('io.nlopez.smartlocation:library:2.+')
    {
        exclude(group: 'com.google.android', module: 'gms:play-services')
    }
    configurations {
      // all*.exclude group: 'com.android.support', module: 'support-v4'

    }

how can I compile the project?

Kamil Nękanowicz
  • 6,254
  • 7
  • 34
  • 51
  • I think there are different versions of support v4 being referenced. If you and your dependencies all reference the same version, it will compile without problems. – Christian Göllner Nov 12 '14 at 13:34
  • Of course you're right and I know that. But how to force the latest version of the support-v4 library for all conflicts? – Kamil Nękanowicz Nov 12 '14 at 13:44
  • 1
    If some of your libraries (android-async-http, crouton, smartlocation) are including support library classes, then they are mispackaged and the library authors should fix them. – Scott Barta Nov 12 '14 at 15:18

2 Answers2

6

This seems to be a common ADT to Android studio migration problem. ADT is looking for a copy of android-support-v4.jar in the libs/ dir while Android studio has it's own internal copy. When migrating the jar file is left in the libs dir which creates a duplicate jar most likely an older version. I deleted the jar in the libs dir and problem was solved.

user3259330
  • 448
  • 6
  • 9
3

the library authors should fix them

Kamil Nękanowicz
  • 6,254
  • 7
  • 34
  • 51
  • Can you please explain a bit? – Shajeel Afzal Jan 26 '15 at 21:57
  • If some of your libraries (android-async-http, crouton, smartlocation) are including support library classes, then they are mispackaged and the library authors should fix them. there are different versions of support v4 being referenced. If you and your dependencies all reference the same version, it will compile without problems. – Kamil Nękanowicz Mar 18 '15 at 08:43