尝试添加 facebook SDK 后无法构建 gradle 项目

cant build gradle project after trying to add facebook SDK

我尝试像这样将 facebook 添加到我的 gradle 文件中:

buildscript {
    repositories {
        maven { url 'http://download.crashlytics.com/maven' }
    }

    repositories { mavenCentral() }

    dependencies {
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
    }
}


apply plugin: 'com.android.application'
apply plugin: 'crashlytics'

repositories {
    maven { url 'http://download.crashlytics.com/maven' }
}


android {
    compileSdkVersion 22
    buildToolsVersion "21.1.3"

    defaultConfig {
        applicationId "com.beerportfolio.beerportfoliopro"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 59
        versionName "4.6.1"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile "com.android.support:appcompat-v7:21.0.+"
    compile 'com.google.android.gms:play-services:+'
    compile 'com.crashlytics.android:crashlytics:1.+'


}

另外,在 Facebook 的说明中它说:

A note for Android developers If you are using ProGuard on the release build of your app, you must add this snippet to your app's proguard-project.txt config file:

-keep class com.facebook.** { *; } -keepattributes Signature These flags are used to preserve generics signatures and to preserve type information used for reflection. Both flags are necessary for the SDK to function correctly in an Android app.

所以在我的 pro guard 文件中(我可能在错误的文件中这样做了..):

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/Mike/Documents/adt-bundle-mac-x86_64-20140321/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-keep class com.facebook.** { *; }
-keepattributes Signature

所以当我尝试构建我的项目时它抛出了这个错误:

当我点击它并尝试修复它时,我得到了这个:

您的 build.gradle 文件指定的构建工具版本 21.1.3 不是有效版本。

此时 (3/11/15),最新的构建工具版本是 22,所以更改此行

buildToolsVersion "21.1.3"

buildToolsVersion "22.0.0"

它会起作用。

只需从 SDK Manager 安装最新版本的 Android SDK Build-tools,我认为它是 22现在

然后在 build.gradle

中更改这一行
buildToolsVersion "21.1.3"

到正确的版本。

buildToolsVersion "22"