我想在我的应用程序中包含FaceBook Sdk 4.2。当我导入这个模块时,这一切都很严格,但是当我的应用运行时,会发生以下情况:
Error:A problem occurred configuring project ':Glam Main'.
> Could not resolve all dependencies for configuration ':Glam Main:_debugCompile'.
> Could not find com.parse.bolts:bolts-android:1.2.0.
Searched in the following locations:
file:/C:/Users/JL9/AppData/Local/Android/sdk/extras/android/m2repository/com/parse/bolts/bolts-android/1.2.0/bolts-android-1.2.0.pom
file:/C:/Users/JL9/AppData/Local/Android/sdk/extras/android/m2repository/com/parse/bolts/bolts-android/1.2.0/bolts-android-1.2.0.jar
file:/C:/Users/JL9/AppData/Local/Android/sdk/extras/google/m2repository/com/parse/bolts/bolts-android/1.2.0/bolts-android-1.2.0.pom
file:/C:/Users/JL9/AppData/Local/Android/sdk/extras/google/m2repository/com/parse/bolts/bolts-android/1.2.0/bolts-android-1.2.0.jar
Required by:
Glam Main:Glam Main:unspecified > com.facebook.android:facebook:4.2.0
gradle.Module.Glam主要:Glam Main:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':appcompat_v7_21')
compile project(':appcompat_v7_21-cardview')
compile project(':appcompat_v7_21-recyclerview')
compile project(':httpmime-4.2.6')
compile project(':facebook')
}
android {
compileSdkVersion 21
buildToolsVersion "20.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
在我的模块Facebook中,我添加了com.parse.bolts:bolts-android:1.2.0
。此模块Facebook已正确导入,因为我可以使用他们的类。
这是我的 gradle.Module.Facebook
apply plugin: 'com.android.library'
repositories {
mavenCentral()
}
project.group = 'com.facebook.android'
dependencies {
compile 'com.android.support:support-v4:[22,23)'
compile 'com.parse.bolts:bolts-android:1.2.0'
}
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
apply plugin: 'maven'
apply plugin: 'signing'
def isSnapshot = version.endsWith('-SNAPSHOT')
def ossrhUsername = hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
def ossrhPassword = hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
task setVersion {
// The version will be derived from source
project.version = null
def sdkVersionFile = file('src/com/facebook/FacebookSdkVersion.java')
sdkVersionFile.eachLine{
def matcher = (it =~ /(?:.*BUILD = \")(.*)(?:\".*)/)
if (matcher.matches()) {
project.version = matcher[0][1]
return
}
}
if (project.version.is('unspecified')) {
throw new GradleScriptException('Version could not be found.', null)
}
}
uploadArchives {
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'Facebook-Android-SDK'
artifactId = 'facebook-android-sdk'
packaging 'aar'
description 'Facebook Android SDK'
url 'https://github.com/facebook/facebook-android-sdk'
scm {
connection 'scm:git@github.com:facebook/facebook-android-sdk.git'
developerConnection 'scm:git@github.com:facebook/facebook-android-sdk.git'
url 'https://github.com/facebook/facebook-android-sdk'
}
licenses {
license {
name 'Facebook Platform License'
url 'https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt'
distribution 'repo'
}
}
developers {
developer {
id 'facebook'
name 'Facebook'
}
}
}
}
}
uploadArchives.dependsOn(setVersion)
signing {
required { !isSnapshot && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
// JDK 1.8 is more strict then 1.7. Have JDK 1.8 behave like 1.7 for javadoc generation
if (org.gradle.internal.jvm.Jvm.current().getJavaVersion() == JavaVersion.VERSION_1_8) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
afterEvaluate {
androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath}
我已阅读以下帖子Android Studio 0.8.1 - how to use Facebook SDK?,但我没有解决我的问题。感谢。
更新1
我修改了 gradle.Module.Glam Main:Glam Main 。 我添加了这句话:
allprojects {
repositories {
jcenter()
}
}
现在我有这个错误
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
Error:Execution failed for task ':Glam Main:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 2
答案 0 :(得分:0)
您可以通过Gradle依赖添加最新的Facebook SDK:
compile 'com.facebook.android:facebook-android-sdk:4.2.0'
看看我的build.gradle文件:
https://github.com/lalongooo/permutas-sep/blob/master/app/build.gradle