AsyncTask
AsyncTask

Reputation: 419

Unexpected Top-Level Exception after SDK build tools update to 23.1 rc1

I got an error after SDK build tools update to 23.1 rc1

Error message is:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
....

Gradle version is 1.3.0. I had been add this configuration script in project's gradle file (in buildscript block).

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

Here is my module's gradle script

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
    applicationId "com.example.android"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 8
    versionName "08.00.00"
}


buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

sourceSets {
    main.jniLibs.srcDirs = ['libs']
    test.jniLibs.srcDirs = ['libs']
}
}
repositories {
    mavenCentral()
}
dependencies {
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.android.support:gridlayout-v7:23.0.1'
    compile 'com.google.android.gms:play-services-gcm:8.1.0
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'ch.acra:acra:4.7.0-RC.1'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile 'com.github.shell-software:fab:1.0.5'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.wu-man:android-oauth-client:0.0.3'

    compile files('libs/disklrucache-2.0.2.jar')
    compile files('libs/spring-android-rest-template-2.0.0.M1.jar')
    compile files('libs/volley.jar')
    compile files('libs/zbar.jar')
}

As I know this error message about support-v4 library's version conflict, but I couldn't solve that. Do you have any suggestion? I tried to build after "invalidate cache/restart", clean project many times.

Upvotes: 1

Views: 258

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363785

This issue happens when you are using different versions of the same library.

Run gradle -q dependencies to check the dependency report.

In your case you will see that

compile 'com.wu-man:android-oauth-client:0.0.3'

has a very old dependency with

<dependency>
  <groupId>com.google.android</groupId>
  <artifactId>support-v4</artifactId>
  <version>r7</version>
  <scope>compile</scope>
</dependency>

You can check the pom file here.

The com.google.android:support-v4:r7 is different from the com.android.support:support-v4 that you are excluding from your script.

You can use an updated version of the same library (example 0.4.5) or you can exclude

compile('com.wu-man:android-oauth-client:0.0.3') {
      exclude module: 'support-v4'
    }

Otherwise you can update your script with:

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

Upvotes: 1

Related Questions