Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Android project for AndroidX Test

I am having difficulty configuring my Android application for testing with AndroidX.

When I attempt to run my initial test I get this error:-

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

My gradle resembles this:-

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'
}

The test I am attempting to execute resembles this:-

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)
    }
}

What am I doing wrong?

How can I resolve the gradle dependency issues?

I've followed this link that show show to configure AndroidX for testing

When I change my app gradle to include guava explicitly

   // https://mvnrepository.com/artifact/com.google.guava/guava
    implementation group: 'com.google.guava', name: 'guava', version: '27.1-android'

The dependency issues change to these below:-

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
like image 646
Hector Avatar asked Apr 11 '19 07:04

Hector


1 Answers

I found a resolution

by adding this to my gradle build file

 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"
    }
like image 162
Hector Avatar answered Nov 09 '22 23:11

Hector