问题描述
我正试图在Android Studio的项目中使用Facebook SDK。我正在遵循教程。当我尝试运行应用程序时,我得到一个Gradle:执行失败的任务:FacebookApp:dexDebug。错误。以下是输出,如果错误
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'.
这是Facebook模块的build.gradle:
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']
}
}
}
而build.gra该项目为:
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
}
}
我做错了什么?
推荐答案
您正在添加两次Android支持库,导致dex合并冲突。您的主要项目是指具有'com.android.support:support-v4:13.0。+'
的maven库,您的Facebook项目是以文件( '库/机器人支撑-v4.jar')
。 Gradle无法解决本地jar文件之间的冲突,因此您必须通过maven引用它们。
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.
修改依赖项
部分的Facebook build.gradle到:
Modify the dependencies
section of your Facebook build.gradle to:
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
,一切都应该可以工作。
and everything should work.
这篇关于当试图使用Facebook SDK时,Gradle构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!