8
votes

I didn't implement new libs but this problem occured while coding :

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

com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\android-sdk\build-tools\21.1.1\dx.bat --dex --no-optimize --output F:\Android_Donbas\ReDonbasIDEANew\app\build\intermediates\dex\debug --input-list=F:\Android_Donbas\ReDonbasIDEANew\app\build\intermediates\tmp\dex\debug\inputList.txt Error Code: 2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502) at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277) at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302) at com.android.dx.command.dexer.Main.run(Main.java:245) at com.android.dx.command.dexer.Main.main(Main.java:214) at com.android.dx.command.Main.main(Main.java:106)

my build.gradle :

 dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.google.code.gson:gson:2.2.2'
    compile 'com.google.guava:guava:18.0'
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile files('libs/android-async-http-1.4.6.jar')
    compile files('libs/AndroidSwipeLayout-v1.1.6.jar')
    compile files('libs/apache-mime4j-0.5.jar')
    compile files('libs/crashlytics.jar')
    compile files('libs/httpclient-4.2.1.jar')
    compile files('libs/httpcore-4.2.1.jar')
    compile files('libs/httpmime-4.2.1.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    compile files('libs/ormlite-android-4.48.jar')
    compile files('libs/ormlite-core-4.48.jar')
    compile files('libs/ormlite-jdbc-4.48.jar')
    compile files('libs/osmdroid-android-4.2.jar')
    compile files('libs/slf4j-android-1.6.1-RC1.jar')
    compile files('libs/universal-image-loader-1.9.3.jar')
}



packagingOptions {
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.t'
    }
4

4 Answers

9
votes

You may have hit the 65k methods limit. To use Google Play Services with more granularity, follow this guide, you can use only the parts that you want. This will possibly fix your problem.

4
votes

You can fix the limit issue by enabling multdex in your build.gradle by adding "multiDexEnabled true". For more information see http://android-developers.blogspot.com.es/2014/12/google-play-services-and-dex-method.html

Referred from Why did this happen? How do i fix this? Android: UNEXPECTED TOP-LEVEL EXCEPTION:.

2
votes

Adding multiDexEnabled true in defaultConfig in build.gradle solved my problem

defaultConfig {
        applicationId "com.example.project"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0.0"
        multiDexEnabled true
    }
0
votes

I solved my problem with adding these in build gradle:

    defaultConfig {
      multiDexEnabled true


    dependencies {
      compile 'com.android.support:multidex:1.0.0'

another solution can be removing unnecessary libraries