5

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.

ZakTaccardi
  • 12,212
  • 15
  • 59
  • 107

1 Answers1

0

Not exactly sure why, but adding resources path manually could be something to try,

android {
sourceSets {
    main {
        res.srcDirs = ['res1', 'res2']
    }
}
}

refer to this link for more information

WenChao
  • 3,586
  • 6
  • 32
  • 46
  • the resources are actually there. The call just fails when it's made from within the `:library` module. if the *exact* same call is made from within the `:app` module, it works. – ZakTaccardi Jan 12 '17 at 22:31