Search code examples
androidandroid-studioandroid-gradle-pluginfacebook-android-sdk

Error when adding Facebook SDK to Android Studio build.gradle


I have tried manually adding a module and have followed a number of guides to add the facebook sdk. Nothing has worked! Currently, I am simply trying to add it to my build.gradle file but this also produces an error. Any help would be great! Have also tried it with previous facebook versions that others have reported working.

The error:

Execution failed for task ':Selfies:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_05\bin\java.exe'' finished with non-zero exit value 2

Some more things possibly related to the error:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs;

build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 18
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.domelz.pix"
    minSdkVersion 15
    targetSdkVersion 19
}

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

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

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

repositories {
    mavenCentral()
}

dependencies {
    compile project(':googleplayservices_lib')
    compile files('libs/android-support-v4.jar')
    compile files('libs/commons-io-2.4.jar')
    compile files('libs/Parse-1.4.3.jar')
    compile files('libs/picasso-2.1.1.jar')
    compile files('libs/joda-time-2.8.1.jar')
    compile 'com.facebook.android:facebook-android-sdk:4.6.0'
}

Solution

  • It appears there is a conflict in the support library used by the Facebook Android SDK and the Support library provided by your SDK!

    If you are using the latest Android Studio, adding the support library (jar) is unnecessary.

    Please try removing that support library from your dependencies clause and it should just fix your issue!

    Good luck!