我使用gradle构建我的android应用程序。
我按照文档(https://developer.android.com/topic/libraries/testing-support-library/index.html)来定义依赖项。
但是,gradle build
总是说它找不到某些依赖项。
> Could not resolve all dependencies for configuration ':_debugAndroidTestCompile'.
> Could not find junit:junit:4.12.
Searched in the following locations:
file:/home/tumh/android-sdk-linux/extras/android/m2repository/junit/junit/4.12/junit-4.12.pom
file:/home/tumh/android-sdk-linux/extras/android/m2repository/junit/junit/4.12/junit-4.12.jar
file:/home/tumh/android-sdk-linux/extras/google/m2repository/junit/junit/4.12/junit-4.12.pom
file:/home/tumh/android-sdk-linux/extras/google/m2repository/junit/junit/4.12/junit-4.12.jar
Required by:
:myapp:unspecified
:myapp:unspecified > com.android.support.test:runner:0.4.1
> Could not find com.squareup:javawriter:2.1.1.
Searched in the following locations:
file:/home/tumh/android-sdk-linux/extras/android/m2repository/com/squareup/javawriter/2.1.1/javawriter-2.1.1.pom
file:/home/tumh/android-sdk-linux/extras/android/m2repository/com/squareup/javawriter/2.1.1/javawriter-2.1.1.jar
file:/home/tumh/android-sdk-linux/extras/google/m2repository/com/squareup/javawriter/2.1.1/javawriter-2.1.1.pom
file:/home/tumh/android-sdk-linux/extras/google/m2repository/com/squareup/javawriter/2.1.1/javawriter-2.1.1.jar
Required by:
:myapp:unspecified > com.android.support.test.espresso:espresso-core:2.2.1
> Could not find javax.inject:javax.inject:1.
Searched in the following locations:
file:/home/tumh/android-sdk-linux/extras/android/m2repository/javax/inject/javax.inject/1/javax.inject-1.pom
file:/home/tumh/android-sdk-linux/extras/android/m2repository/javax/inject/javax.inject/1/javax.inject-1.jar
file:/home/tumh/android-sdk-linux/extras/google/m2repository/javax/inject/javax.inject/1/javax.inject-1.pom
file:/home/tumh/android-sdk-linux/extras/google/m2repository/javax/inject/javax.inject/1/javax.inject-1.jar
Required by:
:myapp:unspecified > com.android.support.test.espresso:espresso-core:2.2.1
> Could not find org.hamcrest:hamcrest-library:1.3.
Searched in the following locations:
file:/home/tumh/android-sdk-linux/extras/android/m2repository/org/hamcrest/hamcrest-library/1.3/hamcrest-library-1.3.pom
file:/home/tumh/android-sdk-linux/extras/android/m2repository/org/hamcrest/hamcrest-library/1.3/hamcrest-library-1.3.jar
file:/home/tumh/android-sdk-linux/extras/google/m2repository/org/hamcrest/hamcrest-library/1.3/hamcrest-library-1.3.pom
file:/home/tumh/android-sdk-linux/extras/google/m2repository/org/hamcrest/hamcrest-library/1.3/hamcrest-library-1.3.jar
Required by:
:myapp:unspecified > com.android.support.test.espresso:espresso-core:2.2.1
> Could not find org.hamcrest:hamcrest-integration:1.3.
Searched in the following locations:
file:/home/tumh/android-sdk-linux/extras/android/m2repository/org/hamcrest/hamcrest-integration/1.3/hamcrest-integration-1.3.pom
file:/home/tumh/android-sdk-linux/extras/android/m2repository/org/hamcrest/hamcrest-integration/1.3/hamcrest-integration-1.3.jar
file:/home/tumh/android-sdk-linux/extras/google/m2repository/org/hamcrest/hamcrest-integration/1.3/hamcrest-integration-1.3.pom
file:/home/tumh/android-sdk-linux/extras/google/m2repository/org/hamcrest/hamcrest-integration/1.3/hamcrest-integration-1.3.jar
Required by:
:myapp:unspecified > com.android.support.test.espresso:espresso-core:2.2.1
> Could not find com.google.code.findbugs:jsr305:2.0.1.
Searched in the following locations:
file:/home/tumh/android-sdk-linux/extras/android/m2repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.pom
file:/home/tumh/android-sdk-linux/extras/android/m2repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.jar
file:/home/tumh/android-sdk-linux/extras/google/m2repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.pom
file:/home/tumh/android-sdk-linux/extras/google/m2repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.jar
Required by:
:myapp:unspecified > com.android.support.test.espresso:espresso-core:2.2.1
> Could not find javax.annotation:javax.annotation-api:1.2.
Searched in the following locations:
file:/home/tumh/android-sdk-linux/extras/android/m2repository/javax/annotation/javax.annotation-api/1.2/javax.annotation-api-1.2.pom
file:/home/tumh/android-sdk-linux/extras/android/m2repository/javax/annotation/javax.annotation-api/1.2/javax.annotation-api-1.2.jar
file:/home/tumh/android-sdk-linux/extras/google/m2repository/javax/annotation/javax.annotation-api/1.2/javax.annotation-api-1.2.pom
file:/home/tumh/android-sdk-linux/extras/google/m2repository/javax/annotation/javax.annotation-api/1.2/javax.annotation-api-1.2.jar
Required by:
:myapp:unspecified > com.android.support.test.espresso:espresso-core:2.2.1
Here is the gradle script
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileSdkVersion "android-22"
buildToolsVersion "20.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
}
androidTest.setRoot('tests')
}
dependencies {
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.4.1'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.4'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
}
}
即使我在androidTestCompile中指定了junit 4.12,它仍然会通过$android_sdk_home
搜索库,但不会按预期搜索maven。
谢谢!
答案 0 :(得分:1)
更新:我认为问题是您需要在buildscript部分之外的其他存储库{mavenCentral()}部分。我总是使用root脚本,我不确定。您的所有脚本看起来都很奇怪,请阅读this:
buildscript {...}配置驱动构建的代码。在这 case,这声明它使用Maven Central存储库,和 对Maven工件有一个类路径依赖。这个 artifact是包含Gradle in的Android插件的库 版本0.11.1注意:这仅影响运行构建的代码,而不是 该项目。 项目本身需要声明自己的存储库 和依赖关系。这将在稍后介绍。
之前的回复:其他可能的问题:
替换
compileSdkVersion "android-22"
通过
compileSdkVersion 22
您需要安装并使用更高版本的工具版本22.0.1 +
注意:始终使用主要修订号为的构建工具版本 与编译目标和目标SDK的更高或相等。
将依赖项块移到android块之外,如here。
依赖元素是在之后 android元素。
有关espresso here的更多信息。
我不知道确切的问题抱歉,先试试working sample,或等待更好的回复。