com.android.support:appcompat 在错误的地方搜索

com.android.support:appcompat searches in wrong place

我正在尝试 link 浓缩咖啡到项目中

这是我得到的错误

_MyProject:unspecified > com.android.support.test.espresso:espresso-core:2.0_

_> Could not find org.hamcrest:hamcrest-library:1.1._

在以下位置搜索:

C:/Users/username/AppData/Local/Android/sdk/extras/android/m2repository/org/hamcrest/hamcrest-library/1.1/hamcrest-library-1.1.jar_

并且无法找到编译 Espresso 所需的其他库

实际的 Espresso 库在这里,但是 gradle 看不到它

C:\Users\username\AppData\Local\Android\sdk\extras\android\m2repository\com\android\support\test\espresso

build.gradle 文件包含:

    buildscript {
    repositories {
        jcenter()       // This is the default repo
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
    }
    apply plugin: 'com.android.application'

    dependencies {
        compile 'com.android.support:appcompat-v7:22.0.0'
        compile fileTree(include: '*.jar', dir: 'libs')
        provided fileTree(include: '*.jar', dir: 'ext_libs')
        compile project(':third_party:facebook')

    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}

我做错了什么?

添加:

repositories {
  mavenCentral();
}

到你的 build.gradle 在顶层(即,作为你的 androiddependencies 闭包的同行)。

例如,在使用 JUnit4(虽然不是 Espresso)的 this sample project 中,我有:

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

apply plugin: 'com.android.application'

repositories {
    mavenCentral() // required for testing-support-lib dependencies
}

dependencies {
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"

    defaultConfig {
        testApplicationId "com.commonsware.android.gradle.hello.test"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    packagingOptions {
        exclude 'LICENSE.txt' // required for no good reason...
    }
}

按照 CommonsWare 的建议添加了存储库关闭。现在构建良好。

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

apply plugin: 'com.android.application'

repositories {
    mavenCentral() // required for testing-support-lib dependencies
}

我也遇到了这个问题,并通过在 Windows 机器的“< userhome >\.gradle\gradle.properties”文件中添加以下行来解决。

systemProp.ANDROID_HOME         = C:\android-sdk-windows