0

After I added compile 'com.facebook.android:facebook-android-sdk:3.21.1' in the dependences of my project I start getting this error when i try to build and run the application(pressing the play button in android studios): Output:

Error:Execution failed for task ':dexDebug'.
......
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: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)

Here is my complete gradle build file:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://repo1.maven.org/maven2' }
        maven { url 'http://download.crashlytics.com/maven' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'

    }
}
apply plugin: "eclipse"
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
repositories {
    mavenCentral()
    maven { url 'http://repo1.maven.org/maven2' }
    maven { url 'http://download.crashlytics.com/maven' }
}
android {

    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        compile project(":libraries:dialog-manager-lib")
        compile project(":libraries:google-play-services-lib")
        compile project(":libraries:pager-indicator-lib")
        compile project(":libraries:apphance-library-1.9.11")
        compile 'com.crashlytics.android:crashlytics:1.+'
    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
//        multiDexEnabled true
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }

    signingConfigs {
        release {
            storeFile file(RELEASE_KEYSTORE_FILE)
            storePassword System.getenv("PASSWORD_KEYSTORE_JB")
            keyAlias System.getenv("ALIAS_KEYSTORE_JB")
            keyPassword System.getenv("PASSWORD_KEYSTORE_JB")
        }

        debug {
            storeFile file(DEBUG_KEYSTORE_FILE_LOCAL)
        }

        beta {
            storeFile file(DEBUG_KEYSTORE_FILE_LOCAL)
        }

    }

    buildTypes {
        debug {
            debuggable true
            signingConfig android.signingConfigs.debug
            applicationIdSuffix ".debug"
        }
        release {
            signingConfig signingConfigs.release
        }

        beta {
            debuggable true
            signingConfig android.signingConfigs.debug
            applicationIdSuffix ".beta"
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        release {
            res.srcDirs = ['res_release']
        }

        beta {
            res.srcDirs = ['res_beta']
        }

        instrumentTest.setRoot('test')
        instrumentTest {
            java.srcDirs = ['test']
        }
    }

    lintOptions {
        abortOnError false
    }
}
task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}
dependencies {
    compile 'com.mixpanel.android:mixpanel-android:4.5.2'
    compile 'com.facebook.android:facebook-android-sdk:3.21.1'
//    compile 'com.android.support:multidex:1.0.0'
}
//allprojects {
//    repositories {
//        jcenter()
//    }
//    configurations.all((Closure) {
//        resolutionStrategy {
//            force 'com.android.support:support-v4:21.0.3' // your version of support library
//        }
//    })
//
//} 

Before I have used the facebook library by downloading it localy and referenceing it in the andeoid.dependeces section in the gradle document and this has worked just great. Any suggestions on how to fix the problem. here is also the dependency tree:

 _betaCompile - ## Internal use, do not manually configure ##
+--- project :libraries:dialog-manager-lib
|    \--- com.android.support:support-v4:21.0.3
|         \--- com.android.support:support-annotations:21.0.3
+--- project :libraries:google-play-services-lib
+--- project :libraries:pager-indicator-lib
|    \--- com.android.support:support-v4:21.0.3 (*)
+--- project :libraries:apphance-library-1.9.11
|    \--- com.android.support:support-v4:21.0.3 (*)
+--- com.crashlytics.android:crashlytics:1.+ -> 1.1.13
+--- com.mixpanel.android:mixpanel-android:4.5.2
+--- com.facebook.android:facebook-android-sdk:3.21.1
|    +--- com.parse.bolts:bolts-android:1.1.2
|    \--- com.android.support:support-v4:[20,21) -> 21.0.3 (*)
\--- com.android.support:multidex:1.0.0

Thanks.

user1796624
  • 3,665
  • 7
  • 38
  • 65
  • The `dependencies` block should go outside the `android` block; you've got two `dependencies` blocks, actually. How is the support library included in your `apphance-library` project? Do you have any copies of the support library jar in any of your `libs` folders? – Scott Barta Jan 26 '15 at 17:24
  • See also http://stackoverflow.com/questions/28149146/gradle-error-dexexception-after-adding-facebook-library – Scott Barta Jan 26 '15 at 17:51
  • So i don't have the support library in the main project as a jar. But I'm interested what are the two dependences that you can see from the file. And the dependencies block is out of the android block, you can see it at the end of the document. Thanks for your answer – user1796624 Jan 27 '15 at 08:59
  • You've got two `dependencies` blocks in the same build script. Have another look – Scott Barta Jan 27 '15 at 16:50

0 Answers0