我正在使用 androidx.test 库在我的 java 库 gradle 项目中设置仪器测试。我在 build.gradle 文件中添加了以下依赖项:
plugins {
id 'java-library'
}
repositories {
google()
mavenCentral()
}
dependencies {
implementation 'androidx.test:runner:1.6.2'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
但是,Gradle 无法解决其某些传递依赖项,从而导致构建失败。我是 Gradle 新手,不知道如何解决这些缺失的依赖项。
这是我收到的错误消息:
:lib:test: Could not resolve androidx.tracing:tracing:1.1.0.
Required by:
project :lib > androidx.test:runner:1.6.2
project :lib > androidx.test:runner:1.6.2 > androidx.test:monitor:1.7.2
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
我尝试过的:
这些步骤都没有解决问题。
问题:
./gradlew :lib:依赖项的输出
> Task :lib:dependencies
------------------------------------------------------------
Project ':lib'
------------------------------------------------------------
annotationProcessor - Annotation processors and their dependencies for source set 'main'.
No dependencies
api - API dependencies for the 'main' feature. (n)
No dependencies
apiElements - API elements for the 'main' feature. (n)
No dependencies
compileClasspath - Compile classpath for source set 'main'.
\--- androidx.test:runner:1.6.2
+--- androidx.annotation:annotation:1.7.0-beta01
| \--- androidx.annotation:annotation-jvm:1.7.0-beta01
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.10 -> 1.8.20
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.20
| \--- org.jetbrains:annotations:13.0
+--- androidx.test.services:storage:1.5.0
| +--- androidx.annotation:annotation:1.7.0-beta01 (*)
| \--- androidx.test:monitor:1.7.0 -> 1.7.2
| +--- androidx.annotation:annotation:1.7.0-beta01 (*)
| +--- androidx.tracing:tracing:1.1.0 FAILED
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.20 (*)
+--- androidx.test:monitor:1.7.2 (*)
+--- androidx.tracing:tracing:1.1.0 FAILED
\--- junit:junit:4.13.2
\--- org.hamcrest:hamcrest-core:1.3
compileOnly - Compile-only dependencies for the 'main' feature. (n)
No dependencies
compileOnlyApi - Compile-only API dependencies for the 'main' feature. (n)
No dependencies
default - Configuration for default artifacts. (n)
No dependencies
implementation - Implementation dependencies for the 'main' feature. (n)
\--- androidx.test:runner:1.6.2 (n)
mainSourceElements - List of source directories contained in the Main SourceSet. (n)
No dependencies
runtimeClasspath - Runtime classpath of source set 'main'.
\--- androidx.test:runner:1.6.2
+--- androidx.annotation:annotation:1.7.0-beta01
| \--- androidx.annotation:annotation-jvm:1.7.0-beta01
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.10 -> 1.8.20
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.20
| \--- org.jetbrains:annotations:13.0
+--- androidx.test.services:storage:1.5.0
| +--- androidx.annotation:annotation:1.7.0-beta01 (*)
| \--- androidx.test:monitor:1.7.0 -> 1.7.2
| +--- androidx.annotation:annotation:1.7.0-beta01 (*)
| +--- androidx.tracing:tracing:1.1.0 FAILED
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.20 (*)
+--- androidx.test:monitor:1.7.2 (*)
+--- androidx.tracing:tracing:1.1.0 FAILED
\--- junit:junit:4.13.2
\--- org.hamcrest:hamcrest-core:1.3
runtimeElements - Runtime elements for the 'main' feature. (n)
No dependencies
runtimeOnly - Runtime-only dependencies for the 'main' feature. (n)
No dependencies
testAnnotationProcessor - Annotation processors and their dependencies for source set 'test'.
No dependencies
testCompileClasspath - Compile classpath for source set 'test'.
\--- androidx.test:runner:1.6.2
+--- androidx.annotation:annotation:1.7.0-beta01
| \--- androidx.annotation:annotation-jvm:1.7.0-beta01
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.10 -> 1.8.20
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.20
| \--- org.jetbrains:annotations:13.0
+--- androidx.test.services:storage:1.5.0
| +--- androidx.annotation:annotation:1.7.0-beta01 (*)
| \--- androidx.test:monitor:1.7.0 -> 1.7.2
| +--- androidx.annotation:annotation:1.7.0-beta01 (*)
| +--- androidx.tracing:tracing:1.1.0 FAILED
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.20 (*)
+--- androidx.test:monitor:1.7.2 (*)
+--- androidx.tracing:tracing:1.1.0 FAILED
\--- junit:junit:4.13.2
\--- org.hamcrest:hamcrest-core:1.3
testCompileOnly - Compile only dependencies for source set 'test'. (n)
No dependencies
testImplementation - Implementation only dependencies for source set 'test'. (n)
No dependencies
testRuntimeClasspath - Runtime classpath of source set 'test'.
\--- androidx.test:runner:1.6.2
+--- androidx.annotation:annotation:1.7.0-beta01
| \--- androidx.annotation:annotation-jvm:1.7.0-beta01
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.10 -> 1.8.20
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.20
| \--- org.jetbrains:annotations:13.0
+--- androidx.test.services:storage:1.5.0
| +--- androidx.annotation:annotation:1.7.0-beta01 (*)
| \--- androidx.test:monitor:1.7.0 -> 1.7.2
| +--- androidx.annotation:annotation:1.7.0-beta01 (*)
| +--- androidx.tracing:tracing:1.1.0 FAILED
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.20 (*)
+--- androidx.test:monitor:1.7.2 (*)
+--- androidx.tracing:tracing:1.1.0 FAILED
\--- junit:junit:4.13.2
\--- org.hamcrest:hamcrest-core:1.3
testRuntimeOnly - Runtime only dependencies for source set 'test'. (n)
No dependencies
(*) - Indicates repeated occurrences of a transitive dependency subtree. Gradle expands transitive dependency subtrees only once per project; repeat occurrences only display the root of the subtree, followed by this annotation.
(n) - A dependency or dependency configuration that cannot be resolved.
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 666ms
1 actionable task: 1 executed
这些 AndroidX 库并不真正适合在常见的 Java 项目中使用,
因为一般来说,
androidx.test
仅仅属于 androidTestImplementation
,androidTest
。
上面写着:
+--- androidx.tracing:tracing:1.1.0 FAILED
尝试提供较新的版本,类似:
androidTestImplementation "androidx.tracing:tracing:1.2.0"
虽然请求的版本
1.1.0
可以在存储库中找到google()
: