3

I am attempting to follow android developer documentation's Set up project for AndroidX Test tutorial (found here) but am getting the error unable to find optional library: android.test.runner.

Here is my Gradle file:

...

android {

    ...

    defaultConfig {
        ...

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    ...

    useLibrary 'android.test.runner'
    useLibrary 'android.test.base'
    useLibrary 'android.test.mock'

}

...

dependencies {
    ...

    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:core:1.0.0'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test:rules:1.1.0'
    androidTestImplementation 'androidx.test.ext:junit:1.0.0'
    androidTestImplementation 'androidx.test.ext:truth:1.0.0'
    androidTestImplementation 'com.google.truth:truth:0.42'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
}

As you can see, I have android.test.runner in my dependencies, but when I add the line useLibrary 'android.test.runner' in my android block, I get the error that it can't find that library...

Is there something off with my Gradle file? I'm following the instructions that were outlined on the tutorial, so I don't know what I could possibly be missing...

Zoe
  • 23,712
  • 16
  • 99
  • 132
BlondeSwan
  • 619
  • 4
  • 17
  • What API level version are you using? I run into the same problem but now found a statement in the tutorial that caused the problem on my side: "The lists in this section show how the platform organizes JUnit-based classes in Android 9 (API level 28) and higher." – CoffeJunky Feb 24 '19 at 07:35

1 Answers1

1

I just not added these useless lines and it is still working even if that is in the official guideline.

But if you are migrating the old version to androidx, remember you have to change the compiling version to 28 otherwise will get some errors.

Allen
  • 2,073
  • 1
  • 23
  • 25