gpt4 book ai didi

java - 如何为 AndroidX Test 配置 Android 项目

转载 作者:行者123 更新时间:2023-12-04 04:56:53 28 4
gpt4 key购买 nike

我在配置我的 Android 应用程序以使用 AndroidX 进行测试时遇到了困难。

当我尝试运行我的初始测试时,我收到此错误:-

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:processDebugAndroidTestManifest'.
> Could not resolve all task dependencies for configuration ':app:debugAndroidTestRuntimeClasspath'.
> Could not resolve com.google.guava:listenablefuture:1.0.
Required by:
project :app
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:27.0.1-android' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.espresso:espresso-contrib:3.1.1' --> 'androidx.core:core:1.1.0-alpha05' --> 'com.google.guava:listenablefuture:1.0'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.espresso:espresso-contrib:3.1.1' --> 'androidx.core:core:1.1.0-alpha05' --> 'androidx.concurrent:concurrent-futures:1.0.0-alpha02' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'JayUnit:app:unspecified' --> 'com.google.guava:listenablefuture' strictly '1.0' because of the following reason: debugRuntimeClasspath uses version 1.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.guava:listenablefuture' strictly '1.0' because of the following reason: debugRuntimeClasspath uses version 1.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.guava:listenablefuture' strictly '1.0' because of the following reason: debugRuntimeClasspath uses version 1.0

> Could not resolve com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava.
Required by:
project :app > androidx.test.ext:truth:1.1.0 > com.google.guava:guava:27.0.1-android
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:27.0.1-android' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.espresso:espresso-contrib:3.1.1' --> 'androidx.core:core:1.1.0-alpha05' --> 'com.google.guava:listenablefuture:1.0'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.espresso:espresso-contrib:3.1.1' --> 'androidx.core:core:1.1.0-alpha05' --> 'androidx.concurrent:concurrent-futures:1.0.0-alpha02' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'JayUnit:app:unspecified' --> 'com.google.guava:listenablefuture' strictly '1.0' because of the following reason: debugRuntimeClasspath uses version 1.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.guava:listenablefuture' strictly '1.0' because of the following reason: debugRuntimeClasspath uses version 1.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.guava:listenablefuture' strictly '1.0' because of the following reason: debugRuntimeClasspath uses version 1.0

> Could not resolve com.google.guava:listenablefuture:1.0.
Required by:
project :app > androidx.core:core:1.1.0-alpha05
project :app > androidx.concurrent:concurrent-futures:1.0.0-alpha02
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:27.0.1-android' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.espresso:espresso-contrib:3.1.1' --> 'androidx.core:core:1.1.0-alpha05' --> 'com.google.guava:listenablefuture:1.0'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.espresso:espresso-contrib:3.1.1' --> 'androidx.core:core:1.1.0-alpha05' --> 'androidx.concurrent:concurrent-futures:1.0.0-alpha02' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'JayUnit:app:unspecified' --> 'com.google.guava:listenablefuture' strictly '1.0' because of the following reason: debugRuntimeClasspath uses version 1.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.guava:listenablefuture' strictly '1.0' because of the following reason: debugRuntimeClasspath uses version 1.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.guava:listenablefuture' strictly '1.0' because of the following reason: debugRuntimeClasspath uses version 1.0


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s

我的gradle类似于这样:-
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.research.jayunit"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '29.0.0 rc2'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
useLibrary 'android.test.runner'

useLibrary 'android.test.base'
useLibrary 'android.test.mock'
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.core:core-ktx:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'

// Core library
androidTestImplementation 'androidx.test:core:1.1.0'

// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'

// Assertions
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.ext:truth:1.1.0'
androidTestImplementation 'com.google.truth:truth:0.44'

// Espresso dependencies
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.1'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.1'

// The following Espresso dependency can be either "implementation"
// or "androidTestImplementation", depending on whether you want the
// dependency to appear on your APK's compile classpath or the test APK
// classpath.
androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.1.1'
}

我试图执行的测试类似于:-
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val context = ApplicationProvider.getApplicationContext<Context>()
assertEquals("com.research.jayunit", context.packageName)
}
}

我究竟做错了什么?

如何解决gradle依赖问题?

我关注了这个 link显示显示配置 AndroidX 进行测试

当我更改我的应用程序 gradle 以明确包含 Guava 时
   // https://mvnrepository.com/artifact/com.google.guava/guava
implementation group: 'com.google.guava', name: 'guava', version: '27.1-android'

依赖性问题更改为以下这些:-
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:preDebugAndroidTestBuild'.
> Could not resolve all task dependencies for configuration ':app:debugAndroidTestRuntimeClasspath'.
> Could not resolve org.checkerframework:checker-compat-qual:2.5.2.
Required by:
project :app
> Cannot find a version of 'org.checkerframework:checker-compat-qual' that satisfies the version constraints:
Dependency path 'JayUnit:app:unspecified' --> 'com.google.truth:truth:0.44' --> 'org.checkerframework:checker-compat-qual:2.5.5'
Dependency path 'JayUnit:app:unspecified' --> 'com.google.guava:guava:27.1-android' --> 'org.checkerframework:checker-compat-qual:2.5.2'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:27.1-android' --> 'org.checkerframework:checker-compat-qual:2.5.2'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.truth:truth:0.44' --> 'org.checkerframework:checker-compat-qual:2.5.5'
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2

> Could not resolve com.google.errorprone:error_prone_annotations:2.2.0.
Required by:
project :app
> Cannot find a version of 'com.google.errorprone:error_prone_annotations' that satisfies the version constraints:
Dependency path 'JayUnit:app:unspecified' --> 'com.google.truth:truth:0.44' --> 'com.google.errorprone:error_prone_annotations:2.3.1'
Dependency path 'JayUnit:app:unspecified' --> 'com.google.guava:guava:27.1-android' --> 'com.google.errorprone:error_prone_annotations:2.2.0'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:27.1-android' --> 'com.google.errorprone:error_prone_annotations:2.2.0'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.truth:truth:0.44' --> 'com.google.errorprone:error_prone_annotations:2.3.1'
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0

> Could not resolve org.checkerframework:checker-compat-qual:2.5.5.
Required by:
project :app > com.google.truth:truth:0.44
> Cannot find a version of 'org.checkerframework:checker-compat-qual' that satisfies the version constraints:
Dependency path 'JayUnit:app:unspecified' --> 'com.google.truth:truth:0.44' --> 'org.checkerframework:checker-compat-qual:2.5.5'
Dependency path 'JayUnit:app:unspecified' --> 'com.google.guava:guava:27.1-android' --> 'org.checkerframework:checker-compat-qual:2.5.2'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:27.1-android' --> 'org.checkerframework:checker-compat-qual:2.5.2'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.truth:truth:0.44' --> 'org.checkerframework:checker-compat-qual:2.5.5'
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2

> Could not resolve com.google.errorprone:error_prone_annotations:2.3.1.
Required by:
project :app > com.google.truth:truth:0.44
> Cannot find a version of 'com.google.errorprone:error_prone_annotations' that satisfies the version constraints:
Dependency path 'JayUnit:app:unspecified' --> 'com.google.truth:truth:0.44' --> 'com.google.errorprone:error_prone_annotations:2.3.1'
Dependency path 'JayUnit:app:unspecified' --> 'com.google.guava:guava:27.1-android' --> 'com.google.errorprone:error_prone_annotations:2.2.0'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:27.1-android' --> 'com.google.errorprone:error_prone_annotations:2.2.0'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.truth:truth:0.44' --> 'com.google.errorprone:error_prone_annotations:2.3.1'
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0

> Could not resolve org.checkerframework:checker-compat-qual:2.5.2.
Required by:
project :app > com.google.guava:guava:27.1-android
> Cannot find a version of 'org.checkerframework:checker-compat-qual' that satisfies the version constraints:
Dependency path 'JayUnit:app:unspecified' --> 'com.google.truth:truth:0.44' --> 'org.checkerframework:checker-compat-qual:2.5.5'
Dependency path 'JayUnit:app:unspecified' --> 'com.google.guava:guava:27.1-android' --> 'org.checkerframework:checker-compat-qual:2.5.2'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:27.1-android' --> 'org.checkerframework:checker-compat-qual:2.5.2'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.truth:truth:0.44' --> 'org.checkerframework:checker-compat-qual:2.5.5'
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2
Constraint path 'JayUnit:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.5.2' because of the following reason: debugRuntimeClasspath uses version 2.5.2

> Could not resolve com.google.errorprone:error_prone_annotations:2.2.0.
Required by:
project :app > com.google.guava:guava:27.1-android
> Cannot find a version of 'com.google.errorprone:error_prone_annotations' that satisfies the version constraints:
Dependency path 'JayUnit:app:unspecified' --> 'com.google.truth:truth:0.44' --> 'com.google.errorprone:error_prone_annotations:2.3.1'
Dependency path 'JayUnit:app:unspecified' --> 'com.google.guava:guava:27.1-android' --> 'com.google.errorprone:error_prone_annotations:2.2.0'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:27.1-android' --> 'com.google.errorprone:error_prone_annotations:2.2.0'
Dependency path 'JayUnit:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.truth:truth:0.44' --> 'com.google.errorprone:error_prone_annotations:2.3.1'
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0
Constraint path 'JayUnit:app:unspecified' --> 'com.google.errorprone:error_prone_annotations' strictly '2.2.0' because of the following reason: debugRuntimeClasspath uses version 2.2.0


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

最佳答案

我找到了解决办法

通过将其添加到我的 gradle 构建文件中

 androidTestImplementation ("androidx.test.ext:truth:1.1.0") {
exclude group: "com.google.truth", module: "truth"
}

androidTestImplementation ("com.google.truth:truth:0.44") {
exclude group: "org.checkerframework", module: "checker-compat-qual"
exclude group: "com.google.errorprone", module: "error_prone_annotations"
}

关于java - 如何为 AndroidX Test 配置 Android 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55626498/

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