Android Espresso testing 'Cannot resolve symbol 'InstrumentationRegistry''-ThrowExceptions

Exception or error:

I’m trying to import


my build.gradle file

androidTestCompile ''
androidTestCompile ''
androidTestCompile ''
androidTestCompile ''

in default config:

defaultConfig {
        testInstrumentationRunner ""

Is there a library I’m missing here? I’m trying to import InstrumentationRegistry but it doesn’t recognise it!

How to solve:

Check what kind of test do you use.

InstrumentationRegistry used for Instrumented tests
that use emulator or device and they are placed in src/androidTest and use config androidTestCompile.
If you use Local unit tests for JVM from folder src/test you should use
config testCompile

testImplementation ''

After that you can import InstrumentationRegistry, but you will get other errors at run-time.



compile ‘’

instead of

testCompile ‘’


it seems, had been recently excluded from some other package (no clue which one), which also resulted in be unknown; not excluding it from fixed the issue for me.

androidTestImplementation ("") {
    // exclude group: ""
    exclude group: ""

basically, androidTestImplementation needs to contain once.

Leave a Reply

Your email address will not be published. Required fields are marked *