Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

android - Gradle build failure when trying to use Facebook SDK

I am trying to use the Facebook SDK in a project in Android Studio. I am following step 3 of this tutorial. When I try to Run the app, I get a "Gradle: Execution failed for task ':FacebookApp:dexDebug'." error. Below is the output if the error

Gradle: Execution failed for task ':FacebookApp:dexDebug'.
> Failed to run command:
C:android-sdkuild-tools18.0.0dx.bat --dex --output C:UsersBrandonAndroidStudioProjectsFacebookAppProjectFacebookAppuildlibsFacebookApp-debug.dex C:UsersBrandonAndroidStudioProjectsFacebookAppProjectFacebookAppuildclassesdebug C:UsersBrandonAndroidStudioProjectsFacebookAppProjectFacebookAppuilddependency-cachedebug C:UsersBrandonAndroidStudioProjectsFacebookAppProjectFacebookAppuildexploded-bundlesFacebookAppProjectLibrariesFacebookUnspecified.aarclasses.jar C:UsersBrandonAndroidStudioProjectsFacebookAppProjectFacebookAppuildexploded-bundlesFacebookAppProjectLibrariesFacebookUnspecified.aarlibsandroid-support-v4.jar C:android-sdkextrasandroidm2repositorycomandroidsupportsupport-v413.0.0support-v4-13.0.0.jar
    Error Code:
        1
    Output:
        UNEXPECTED TOP-LEVEL EXCEPTION:
        java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl;
            at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
            at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
            at com.android.dx.command.dexer.Main.processClass(Main.java:490)
            at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
            at com.android.dx.command.dexer.Main.access$400(Main.java:67)
            at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
            at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
            at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
            at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
            at com.android.dx.command.dexer.Main.processOne(Main.java:422)
            at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
            at com.android.dx.command.dexer.Main.run(Main.java:209)
            at com.android.dx.command.dexer.Main.main(Main.java:174)
            at com.android.dx.command.Main.main(Main.java:91)
        1 error; aborting

Here is the build.gradle for the facebook module:

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android-library'

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }

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

And the build.gradle for the project:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile project(':libraries:facebook')
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

Am I doing something wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're adding the android support library twice, resulting in a dex merge conflict. Your main project refers to the maven library with 'com.android.support:support-v4:13.0.+' and your Facebook project refers to it with files('libs/android-support-v4.jar'). Gradle cannot resolve conflicts between local jar files, so you must refer to them through maven.

Modify the dependencies section of your Facebook build.gradle to:

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
}

and everything should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...