gpt4 book ai didi

android - 如何设置与 AndroidJunitRunner 的依赖关系?

转载 作者:行者123 更新时间:2023-11-30 01:48:43 29 4
gpt4 key购买 nike

我使用 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 central。

谢谢!

最佳答案

更新:我认为问题是您需要在 buildscript 部分之外的另一个 repositories{mavenCentral()} 部分。我总是为此使用根脚本,但我不确定。你所有的脚本看起来都很奇怪,请阅读 this :

buildscript { ... } configures the code driving the build. In this case, this declares that it uses the Maven Central repository, and that there is a classpath dependency on a Maven artifact. This artifact is the library that contains the Android plugin for Gradle in version 0.11.1 Note: This only affects the code running the build, not the project. The project itself needs to declare its own repositories and dependencies. This will be covered later.

之前的回复:其他可能的问题:

替换

compileSdkVersion "android-22"

通过

compileSdkVersion 22

并且需要安装使用更高版本的build tools 22.0.1+

Note: Always use a build tools version whose major revision number is higher or equal to that of your compilation target and target SDK.

并将依赖项 block 移动到 android block 之外,如 here .

The dependencies element is outside and after the android element.

关于 Espresso 的更多信息 here .

我不知道确切的问题抱歉,请尝试 working sample首先,或者等待更好的响应。

关于android - 如何设置与 AndroidJunitRunner 的依赖关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33339287/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com