我是Android开发的新手,我已经获得了恢复旧项目并修复一些错误的工作。当我在Android Studio中打开项目时,我发现与facebook包相关的错误不存在。项目结构如下:
build.gradle包含以下代码:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
我收到的错误如下所示:
我该怎么做才能解决问题?
更新:完成Build.gradle文件:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
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')
}
}
答案 0 :(得分:0)
您需要将您的库添加到Android Studio。
打开libs文件夹并右键单击facebook库,然后选择&#34; Add as library&#34;。然后也许重建项目。
答案 1 :(得分:0)
将Maven Central Repository添加到项目的build.gradle:
repositories {
jcenter()
mavenCentral()
}
现在在应用程序的build.gradle中将Facebook SDK添加到您的应用程序:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.facebook.android:facebook-android-sdk:3.23.1'
}
文档here。
修改:选项2(本地)
下载Facebook SDK表单here。
在项目根目录中创建一个“libs”文件夹。
将Facebook SDK的内容复制到“libs”文件夹。
打开settings.gradle并将库添加到您的应用中:
include ':app'
include ':libs:facebook-android-sdk-3.23.1'
现在将它添加到build.gradle文件中:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':libs:facebook-android-sdk-3.23.1')
}