I have an app with few flavours, and I've issue with robolectric loading the resources.
I'm using a custom test runner since I had issues with robolectric not finding the manifest (the app/ is missing at the beginning of the default manifest path)
All generated paths from the custom Test Runner are corrects RobolectricFlavourTestRunner
Robolectric assets directory: app/build/intermediates/assets/myAppBlueFlavour/debug
Robolectric res directory: app/build/intermediates/res/merged/myAppBlueFlavour/debug
Robolectric manifest path: app/build/intermediates/manifests/full/myAppBlueFlavour/debug/AndroidManifest.xml
Robolectric package name: au.com.myapp.blue
android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f0a008c in packages [au.com.myapp.blue, android]
at org.robolectric.shadows.ShadowAssetManager.getResName(ShadowAssetManager.java:865)
at org.robolectric.shadows.ShadowAssetManager.resolveResourceValue(ShadowAssetManager.java:673)
at org.robolectric.shadows.ShadowAssetManager.resolve(ShadowAssetManager.java:633)
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:627)
at org.robolectric.shadows.ShadowAssetManager.getResourceText(ShadowAssetManager.java:227)
at android.content.res.AssetManager.getResourceText(AssetManager.java)
at android.content.res.Resources.getText(Resources.java:327)
at android.content.res.Resources.getString(Resources.java:377)
at com.myapp.core.MyApplication.onCreate(MyApplication.java:99)
at org.robolectric.android.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:137)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:289)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:203)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:109)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:36)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:63)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
MyApplication.java
@Override
public void onCreate() {
...
99 if(getResources().getString(R.string.tracking_enabled).equals("true")) {
...
I did some debugging and realised that the variable resourceTable is not populated for the flavour (au.com.myapp.blue) and I guess this is why Robolectric is failing at finding the resource.
Has you can see below, the resourceTable HashBiMap@3127 is empty, this one is from the package name (au.com.myapp.blue) has you can see above. Also resources ResBunch@3126 is populated correctly with all string, colors... items (I can find the item I try to reach).
The resourceTable HashBiMap@3930 from "android" is filled coorectly with 8297 items.
So do you have any clue why resourceTable HashBiMap@3127 is empty, is that a bug?

I guess, any app with flavouring must have this issue. here is how Flavours are defined in gradle:
productFlavors {
myAppGreenFlavour {
applicationId "au.com.myapp.green"
}
myAppBlueFlavour {
applicationId "au.com.myapp.blue"
}
}
Robolectric 3.3.1 & Android SDK 24
Thanks for your help
I have a very similar problem. For me it says:
android.view.InflateException: XML file build/intermediates/res/merged/dev_/debug/layout/profile_activity.xml line #-1 (sorry, not yet implemented): XML file build/intermediates/res/merged/dev_/debug/layout/profile_activity.xml line #-1 (sorry, not yet implemented): Error inflating class android.support.v7.widget.SwitchCompat
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.xxx.mm.android.profile.ProfileActivity.injectDependencies(ProfileActivity.java:166)
at com.xxx.mm.android.dashboard.BaseOscarActivity.onCreate(BaseOscarActivity.java:73)
at com.xxx.mm.android.profile.ProfileActivity.onCreate(ProfileActivity.java:107)
at android.app.Activity.performCreate(Activity.java:6251)
at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:231)
at org.robolectric.android.controller.ActivityController$1.run(ActivityController.java:140)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:362)
at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:40)
at org.robolectric.android.controller.ActivityController.create(ActivityController.java:137)
at org.robolectric.android.controller.ActivityController.create(ActivityController.java:147)
at com.xxx.mm.android.profile.ProfileActivityTest.setupAndCreateActivity(ProfileActivityTest.java:195)
at com.xxx.mm.android.profile.ProfileActivityTest.onResume_shouldNotShow_SetSecurityCode_WhenLegacyUser(ProfileActivityTest.java:278)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:487)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:209)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:109)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:36)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:63)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: android.view.InflateException: XML file build/intermediates/res/merged/dev_/debug/layout/profile_activity.xml line #-1 (sorry, not yet implemented): Error inflating class android.support.v7.widget.SwitchCompat
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
... 47 more
Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff in packages [com.xxx.mm.android, android]
at org.robolectric.shadows.ShadowAssetManager.getResName(ShadowAssetManager.java:865)
at org.robolectric.shadows.ShadowAssetManager.buildTypedValue(ShadowAssetManager.java:731)
at org.robolectric.shadows.ShadowAssetManager.attrsToTypedArray(ShadowAssetManager.java:793)
at org.robolectric.shadows.ShadowResources$ShadowTheme.obtainStyledAttributes(ShadowResources.java:218)
at org.robolectric.shadows.ShadowResources$ShadowTheme.obtainStyledAttributes(ShadowResources.java:213)
at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java)
at android.content.Context.obtainStyledAttributes(Context.java:520)
at uk.co.chrisjenx.calligraphy.CalligraphyUtils.pullFontPathFromTextAppearance(CalligraphyUtils.java:230)
at uk.co.chrisjenx.calligraphy.CalligraphyFactory.resolveFontPath(CalligraphyFactory.java:197)
at uk.co.chrisjenx.calligraphy.CalligraphyFactory.onViewCreatedInternal(CalligraphyFactory.java:132)
at uk.co.chrisjenx.calligraphy.CalligraphyFactory.onViewCreated(CalligraphyFactory.java:114)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:301)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
... 57 more
I also use Robolectric 3.3.1 but Android SDK 23.
I use a custom GradleTestRunner that use the following override method:
@Override protected Config buildGlobalConfig() {
Class[] shadows = {
ShadowBitmapDescriptor.class, ShadowBitmapDescriptorFactory.class, ShadowDirectionsApiRequest.class, ShadowMarker.class, ShadowOscarMapView.class, ShadowPolyline.class, ShadowWebViewClient.class, ShadowGoogleMap.class, ShadowPendingResultBase.class};
private static final String BUILD_VARIANT = BuildConfig.FLAVOR + (BuildConfig.FLAVOR.isEmpty()? "" : "/" + BuildConfig.BUILD_TYPE);
return Config.Builder.defaults()
.setSdk(23)
.setConstants(BuildConfig.class)
.setShadows(shadows)
.setPackageName("com.xxx.mm.android")
.setManifest("AndroidManifest.xml")
.setResourceDir("/build/intermediates/res/merged/" + BUILD_VARIANT)
.setAssetDir("/build/intermediates/assets/" + BUILD_VARIANT)
.build();
}
My app also uses different flavors.
If you are using AGP < 3.0 (latest beta) then the issue is almost certainly that GradleManifestFactory is not picking up the location of your merged resources directory. This is really an ad-hoc integration and was prone to breaking as the intermediate directories have moved between releases. If you can find the location where gradle is putting these merged resources folders your best bet will be to modify GradleManifestFactory and submit a PR. Realistically we're not going to be investing any/much effort in improving this since all our efforts are focussed on the integration with AGP 3.0 which is consuming all our time and priority right now as its a large undertaking, but we'd be happy to accept PR for the existing GradleManifestFactory.
Most helpful comment
I have a very similar problem. For me it says:
I also use Robolectric 3.3.1 but Android SDK 23.
I use a custom GradleTestRunner that use the following override method:
My app also uses different flavors.