Gradle error: Could not find org.apache.httpcomponents:httpclient-android:4.3.5.1

Gradle error: Could not find org.apache.httpcomponents:httpclient-android:4.3.5.1

我正在尝试在我的 Gradle 项目中为 Android 使用 Apache httpclient,但我不明白为什么在 运行 ./gradle build 时出现此错误:

Could not find org.apache.httpcomponents:httpclient-android:4.3.5.1.

我的顶级 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.12.+'
    }
}

我的项目 build.gradle 开始于:

apply plugin: 'com.android.application'

dependencies {
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':workspace:google_play_services:libproject:google-play-services_lib')
}

这有什么问题?

在Maven的中央仓库浏览器中列出了我需要的包: http://search.maven.org/#browse|-305040853

您必须在您的项目中添加 build.gradle

 repositories {
        mavenCentral()
 }

如果您想将它放在顶层文件中,您可以将其添加到 顶层 build.gradle:

allprojects {
     repositories {
        mavenCentral()
    }
}