During an instrumentation test, my app is throwing the following error. This error is not thrown in my non-test builds.
android.content.res.Resources$NotFoundException: String resource ID #0x7f030002
I have two gradle modules
:app (android-application) //applicationId: com.app
:library (android-library) //applicationId: com.library
//:app includes :library as a dependency
The resource in question is defined and thrown in the :library
module.
While under instrumentation, my :library
module calls:
context.getResources().getString(com.library.R.string.pref_key)
- this throws an exception
If I debug at a breakpoint during instrumentation and call:
context.getResources().getString(com.app.R.string.pref_key)
- this works! But this is code from my:library
module, which doesn't have a depedendency on:app
.
How can I fix this? Note - the error only occurs during instrumentation tests, not normal builds.
UPDATE: while under instrumentation, calling getString(com.library.R.string.pref_key)
works when called from a class within the :app
module, but throws the exception from a class within the :library
module. Literally, calling the exact same method on the same instance of Resources
behaves differently when called from :app
vs :library
.