roobyroo roobyroo - 5 months ago 39
Android Question

Why do I get a Resources$NotFoundException when using InstrumentationRegistry.getContext().getString()?

I am running Android Instrumentation tests and when I use the

returned by
to retrieve a string given an id I get the message:

android.content.res.Resources$NotFoundException: String resource ID #0x7f060020

I've tried ids from other string resources but to no avail.

I've looked through several questions about this same exception on stackoverflow but all of them involve passing an the string id to
. This is not relevant for me since I am creating a library and there are no
s at all.


I figured this out for myself. The module under test was set up to be an application project but it should have been set up as a library project. In the module's build.gradle file I changed this:

apply plugin: ''

to this:

apply plugin: ''

I also had to remove the applicationId line from the build.gradle file because it is not applicable for library projects.

Once I made these changes the string's resource id could be found.