Gradle github 和 facebook 依赖无法解析

Gradle github and facebook dependencies can't resolve

我是 gradle 的新手,想知道当我尝试从主 Maven 存储库加载依赖项时我是否做错了什么

这是我的 build.gradle:

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

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.github.clans:fab:1.6.2'
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.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')
    }
}

我得到的错误是

Error:(15, 17) Failed to resolve: com.facebook.android:facebook-android-sdk:4.7.0

Error:(14, 17) Failed to resolve: com.github.clans:fab:1.6.2

这是怎么回事?为什么我会看到这些错误?此处的文字只是为了让 Whosebug 停止抱怨。

更新:

这是gradle-wrapper.settings:

#Tue Nov 17 20:36:30 GMT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip

这些是我在 Android Studio 中的依赖项。它甚至通过搜索找到它....

试试这个:

apply plugin: 'com.android.application'

allprojects {
    repositories {
        jcenter()
        mavenCentral()
       }
     dependencies { classpath 'com.android.tools.build:gradle:1.5.0' }
}



android {
    compileSdkVersion 21
    buildToolsVersion "21.0.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']
        }

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.github.clans:fab:1.6.2'
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
}

或尝试:

Gradle 设置 -> 然后取消选中离线工作

您似乎忘记将存储库添加到您的项目中。根据您的 build.script,您只是在构建脚本中添加了 repo。在声明依赖项之前,只需将存储库添加到 build.script 根目录中,如:

repositories {
    mavenCentral()
}

dependencies {...