当我尝试访问原始资源时,收到android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f060000
错误。
该资源是.bks证书,用于服务器验证。它存储在res/raw
文件夹中。
最尴尬的是,当我将证书(和验证架构)复制到一个新项目(我为了测试它而构建)时,它起作用了!
我正在使用nenick的custom runner,因此Robolectric可以正确找到清单,资源和资产的文件夹。当我转到intermediates / res / debug文件夹时,所有资源都在那里。我没有项目中的风味(以前的项目,我删除了它们。也许这就是问题?)
我正在使用com.android.tools.build:gradle:1.2.2
。 buildToolsVersion '22.0.1'
。
我对项目有很多依赖:(
另外,我正在使用testCompile 'org.robolectric:robolectric:3.0-rc2'
和testCompile 'org.robolectric:shadows-support-v4:3.0-rc2'
stacktrace:
android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f060000
at org.robolectric.shadows.ShadowResources.getResName(ShadowResources.java:346)
at org.robolectric.shadows.ShadowResources.openRawResource(ShadowResources.java:385)
at android.content.res.Resources.openRawResource(Resources.java)
at com.xxx.xxx.xxx.ssl.CertificateHelper.loadKeyStoreFromRaw(CertificateHelper.java:145)
at com.xxx.xxx.xxx.xxx.XXX.createSSLSocketFactory(XXX.java:432)
at com.xxx.xxx.xxx.xxx.xxx.XXX.<init>(XXX.java:92)
at com.xxx.xxx.xxx.xxx.xxx.XXX.initiate(XXX.java:73)
at com.xxx.xxx.xxx.MainApplication.onCreate(MainApplication.java:60)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:131)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:431)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:224)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
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.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:168)
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: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: Unable to find resource ID #0x7f060000
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:228)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
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.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:168)
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: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:57)
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: Unable to find resource ID #0x7f060000
at org.robolectric.shadows.ShadowResources.getResName(ShadowResources.java:346)
at org.robolectric.shadows.ShadowResources.openRawResource(ShadowResources.java:385)
at android.content.res.Resources.openRawResource(Resources.java)
at com.xxx.xxx.xxx.xxx.CertificateHelper.loadKeyStoreFromRaw(CertificateHelper.java:145)
at com.xxx.xxx.xxx.xxx.XXX.createSSLSocketFactory(XXX.java:432)
at xxx.xxx.xxx.xxx.xxx.xxx.XXX.<init>(TrafficManagerImpl.java:92)
at xxx.xxx.xxx.xxx.xxx.xxx.XXX.initiate(XXX.java:73)
at com.xxx.xxx.xxx.MainApplication.onCreate(MainApplication.java:60)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:131)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:431)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:224)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
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.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:168)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
... 1 more
对于包/类名称上的“xxx”感到抱歉,但我没有代码。
修改1以添加代码
在应用程序onCreate
处执行的代码是:
InputStream is = resources.openRawResource(keystoreId);
变量keystoreId
是R.raw.keystore
。
有谁知道造成这种情况的原因是什么?
编辑2以提供更多信息
额外信息:我在模块的build.gradle和AndroidManifest上有不同的应用程序ID。即使我改变项目使它们变得相同,事情也不起作用并且bug仍然存在:(
编辑3:Android工作室更新
随着最后的android studio更新,测试开始能够找到资源!除了原始文件夹中的那些:(
我正在通过在我的代码中添加一个丑陋的if
解决它,但由于这不是我的问题的解决方案,我不会关闭它...
答案 0 :(得分:2)
如果错误,我希望Nenick会纠正这个答案。但是你的设置不需要他的自定义跑步者。您可以改为使用RobolectricGradleTestRunner
。