Can't Repro
Status Update
Comments
zt...@gmail.com <zt...@gmail.com> #2
Do you have a repro project that you could share with us?
There should be no need to excluding any dependencies: we automatically remove them from the test APK if they are in the main APK.
There should be no need to excluding any dependencies: we automatically remove them from the test APK if they are in the main APK.
uc...@google.com <uc...@google.com> #3
Thank you for this feedback. The team may reach out for more information on triaging or reproducing this issue.
sp...@google.com <sp...@google.com> #4
Is this problem still reproducible in Android Studio 3.0 Canary 7?
xa...@google.com <xa...@google.com>
xa...@google.com <xa...@google.com>
sa...@google.com <sa...@google.com> #5
Hi Zak,
I'm trying to reproduce this problem and not having much success. I've tried in the 2.3.3 and 3.0.0-beta4. My methodology was to create a default project, add a module called :library, add :library as a dependency to :app, added a string resource to :library called pref_key that contains "woot", then replace the contents of ExampleInstrumentationTest in both of these to test the following lines of code:
1. assertEquals("woot", InstrmentationRegistry.getContext().getResources().getString(R.string.pref_key));
2. assertEquals("woot", InstrmentationRegistry.getContext().getResources().getString(com.app.R.string.pref_key));
3. assertEquals("woot", InstrmentationRegistry.getContext().getResources().getString(com.library.R.string.pref_key));
4. assertEquals("woot", InstrmentationRegistry.getTargetContext().getResources().getString(R.string.pref_key));
5. assertEquals("woot", InstrmentationRegistry.getTargetContext().getResources().getString(com.app.R.string.pref_key));
6. assertEquals("woot", InstrmentationRegistry.getTargetContext().getResources().getString(com.library.R.string.pref_key));
In :app, the following cases fail: 1, 2, 3.
In :library, the following cases fail: 2, 5 (I have to comment them out because they don't compile, which makes sense as :library does not depend on :app).
When I set a debug breakpoint in the :library instrumentation test and try to run: InstrmentationRegistry.getTargetContext().getResources().getString(com.app.R.string.pref_key), I get a NoClassDefFound for com.app.R. Which is also expected.
Are you sure you're using the correct Context object in your tests? You need to use the getTargetContext() by the looks of it.
If you're still having these problems in 3.0.0-beta4, I'd really appreciate you sending over a minimal project that reproduces the problem so I can get a better understanding of what you're trying to do. :)
I'm trying to reproduce this problem and not having much success. I've tried in the 2.3.3 and 3.0.0-beta4. My methodology was to create a default project, add a module called :library, add :library as a dependency to :app, added a string resource to :library called pref_key that contains "woot", then replace the contents of ExampleInstrumentationTest in both of these to test the following lines of code:
1. assertEquals("woot", InstrmentationRegistry.getContext().getResources().getString(R.string.pref_key));
2. assertEquals("woot", InstrmentationRegistry.getContext().getResources().getString(com.app.R.string.pref_key));
3. assertEquals("woot", InstrmentationRegistry.getContext().getResources().getString(com.library.R.string.pref_key));
4. assertEquals("woot", InstrmentationRegistry.getTargetContext().getResources().getString(R.string.pref_key));
5. assertEquals("woot", InstrmentationRegistry.getTargetContext().getResources().getString(com.app.R.string.pref_key));
6. assertEquals("woot", InstrmentationRegistry.getTargetContext().getResources().getString(com.library.R.string.pref_key));
In :app, the following cases fail: 1, 2, 3.
In :library, the following cases fail: 2, 5 (I have to comment them out because they don't compile, which makes sense as :library does not depend on :app).
When I set a debug breakpoint in the :library instrumentation test and try to run: InstrmentationRegistry.getTargetContext().getResources().getString(com.app.R.string.pref_key), I get a NoClassDefFound for com.app.R. Which is also expected.
Are you sure you're using the correct Context object in your tests? You need to use the getTargetContext() by the looks of it.
If you're still having these problems in 3.0.0-beta4, I'd really appreciate you sending over a minimal project that reproduces the problem so I can get a better understanding of what you're trying to do. :)
je...@google.com <je...@google.com> #6
closing as requested information was not provided.
Description
android.content.res.Resources$NotFoundException: String resource ID #0x7f030002
I have two gradle modules
:app (android-application) //applicationId:
: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.
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
also see: