Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find optional library: android.test.runner

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...

like image 548
BlondeSwan Avatar asked Feb 23 '26 05:02

BlondeSwan


1 Answers

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.

like image 70
Allen Avatar answered Feb 25 '26 04:02

Allen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!