将Facebook SDK导入我的android项目 - Gradle错误

时间:2014-07-15 18:14:49

标签: android facebook intellij-idea android-gradle facebook-sdk-3.1

我有一个让我忙碌过去几天的问题,我想得到一些帮助......

我正在使用intellij 13.1.3,当我尝试将Facebook SDK添加为模块时,我收到错误

  

错误:Gradle:错误:包com.facebook不存在

我做了一切,正如@Scott Barta在这里解释的那样:https://stackoverflow.com/a/20221453/1018192

请帮帮我! :( 非常感谢你:))

编辑1: 我的build.gradle文件:

facebook - >的build.gradle

apply plugin: 'android-library'

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile files('libs/bolts.jar')
}

android {
    compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
    buildToolsVersion "19.0.0"

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

my_proj - >的build.gradle

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

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.android.support:support-v4:19.1.0'
}

My_proj - >的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

allprojects {
    repositories {
        mavenCentral()
    }
}

My_proj - > settings.gradle

include ':my_proj'
include ':libraries:facebook'

2 个答案:

答案 0 :(得分:5)

只需将其添加为依赖

    dependencies {
        compile 'com.facebook.android:facebook-android-sdk:3.22.0'
    }

使用http://gradleplease.appspot.com/#facebook获取最新版本

答案 1 :(得分:1)

我修好了!!!

我刚刚在my_proj.gradle中添加了行

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.android.support:support-v4:19.1.0'
    **compile project(':libraries:facebook')**
}

它修复了3天的头痛