6

我正在尝试在 Android Studio 的项目中使用 Facebook SDK。我正在遵循教程的第 3 步。当我尝试运行该应用程序时,我收到“Gradle:任务':FacebookApp:dexDebug'的执行失败”。错误。以下是错误时的输出

Gradle: Execution failed for task ':FacebookApp:dexDebug'.
> Failed to run command:
C:\android-sdk\build-tools\18.0.0\dx.bat --dex --output C:\Users\Brandon\AndroidStudioProjects\FacebookAppProject\FacebookApp\build\libs\FacebookApp-debug.dex C:\Users\Brandon\AndroidStudioProjects\FacebookAppProject\FacebookApp\build\classes\debug C:\Users\Brandon\AndroidStudioProjects\FacebookAppProject\FacebookApp\build\dependency-cache\debug C:\Users\Brandon\AndroidStudioProjects\FacebookAppProject\FacebookApp\build\exploded-bundles\FacebookAppProjectLibrariesFacebookUnspecified.aar\classes.jar C:\Users\Brandon\AndroidStudioProjects\FacebookAppProject\FacebookApp\build\exploded-bundles\FacebookAppProjectLibrariesFacebookUnspecified.aar\libs\android-support-v4.jar C:\android-sdk\extras\android\m2repository\com\android\support\support-v4\13.0.0\support-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

这是 facebook 模块的 build.gradle:

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']
        }
    }
}

以及项目的 build.gradle:

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
    }
}

难道我做错了什么?

4

3 回答 3

16

您添加了两次 android 支持库,导致 dex 合并冲突。您的主项目使用 maven 库引用,'com.android.support:support-v4:13.0.+'而您的 Facebook 项目使用files('libs/android-support-v4.jar'). Gradle 无法解决本地 jar 文件之间的冲突,所以必须通过 maven 引用。

dependencies将 Facebook build.gradle 的部分修改为:

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

and everything should work.

于 2013-08-05T22:41:51.573 回答
1

In android studio, this is how I include a support library and facebook SDK. I'm supporting API 15+.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'fr.avianey:facebook-android-api:+@aar'
    compile 'com.android.support:support-v13:20.0.0'
    ...
}
于 2014-08-27T23:17:14.620 回答
0

I had a similiar issue and it was just plain oversight on my part. I had conflicting versions of com.android.tools.build:gradle:1.1.2 and 1.1.1 inside two different gradle.build files.

app/gradle.build

dependencies {
    ...
    compile 'com.android.tools.build:gradle:1.1.2'
    ...
}

top-level gradle.build

dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    }

I commented out the line in my project's gradle.build file, ran gradlew clean from the command line, restarted Android Studio and then order was restored in the universe.

于 2015-03-02T23:10:44.753 回答