Hi,
in our project we're using a different applicationId than package name.
In build.gradle file we have defined:
...
defaultConfig {
minSdkVersion 13
targetSdkVersion 21
applicationId = "com.xxx.xxxsuffix"
}
...
The package name is only "com.xxx.xxx"
For our tests we're using RobolectricGradleTestRunner:
@Config(constants = BuildConfig.class)
@RunWith(RobolectricGradleTestRunner.class)
When we run the test we get the following error:
android.content.res.Resources$NotFoundException: unknown resource 2131558435
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:351)
at org.robolectric.shadows.ShadowAssetManager.getResourceText(ShadowAssetManager.java:70)
at android.content.res.AssetManager.getResourceText(AssetManager.java)
at android.content.res.Resources.getText(Resources.java:270)
at org.robolectric.shadows.ShadowResources.getText(ShadowResources.java:358)
at android.content.res.Resources.getText(Resources.java)
at android.content.res.Resources.getString(Resources.java:360)
at org.robolectric.shadows.ShadowContext.getString(ShadowContext.java:33)
at org.robolectric.shadows.ShadowContextWrapper.getString(ShadowContextWrapper.java:81)
at android.content.Context.getString(Context.java)
at com.citrix.g2acommon.G2AApplication.getContentTitle(G2AApplication.java:218)
at com.citrix.g2acommon.G2AApplication.onCreate(G2AApplication.java:191)
at com.citrix.g2acustomer.G2ACustomerApplication.onCreate(G2ACustomerApplication.java:137)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:140)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:433)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:240)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
java.lang.RuntimeException: android.content.res.Resources$NotFoundException: unknown resource 2131558435
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:244)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: android.content.res.Resources$NotFoundException: unknown resource 2131558435
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:351)
at org.robolectric.shadows.ShadowAssetManager.getResourceText(ShadowAssetManager.java:70)
at android.content.res.AssetManager.getResourceText(AssetManager.java)
at android.content.res.Resources.getText(Resources.java:270)
at org.robolectric.shadows.ShadowResources.getText(ShadowResources.java:358)
at android.content.res.Resources.getText(Resources.java)
at android.content.res.Resources.getString(Resources.java:360)
at org.robolectric.shadows.ShadowContext.getString(ShadowContext.java:33)
at org.robolectric.shadows.ShadowContextWrapper.getString(ShadowContextWrapper.java:81)
at android.content.Context.getString(Context.java)
at com.citrix.g2acommon.G2AApplication.getContentTitle(G2AApplication.java:218)
at com.citrix.g2acommon.G2AApplication.onCreate(G2AApplication.java:191)
at com.citrix.g2acustomer.G2ACustomerApplication.onCreate(G2ACustomerApplication.java:137)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:140)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:433)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:240)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
... 1 more
I found a workaround.
When I add the package name to my config annotation it works:
@Config(constants = BuildConfig.class, packageName = "com.citrix.g2acustomer")
I have to add this for each test suite.
Is this a known Issue?
Is there a better solution?
Thanks
Alex