Robolectric 说“找不到 AndroidManifest.xml"; [英] Robolectric says "AndroidManifest.xml not found"

查看:70
本文介绍了Robolectric 说“找不到 AndroidManifest.xml";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试让 Robolectric RC3 在 Android Studio 中工作时,我得到

While trying to get Robolectric RC3 to work in Android Studio, I get

Caused by: java.lang.RuntimeException: build/intermediates/bundles/debug/AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml
at org.robolectric.manifest.AndroidManifest.validate(AndroidManifest.java:120)
at org.robolectric.manifest.AndroidManifest.getResourcePath(AndroidManifest.java:469)
at org.robolectric.manifest.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java:475)
at org.robolectric.RobolectricTestRunner.createAppResourceLoader(RobolectricTestRunner.java:479)
at org.robolectric.RobolectricTestRunner.getAppResourceLoader(RobolectricTestRunner.java:471)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:73)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:421)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234)

我试过了

@Config(manifest = "app/src/main/AndroidManifest.xml", constants = BuildConfig.class, sdk=21)

我尝试在我的 TestRunner 中设置清单位置,但没有任何效果.在文件系统中,我看到清单在

and I tried setting the manifest location in my TestRunner, nothing worked. In the file system I see that the manifest is in

./app/build/intermediates/manifests/full/debug/AndroidManifest.xml

不在 Robolectric 寻找的位置.有一次,清单被忽略了,然后资源出现了类似的问题,应用程序或 Robolectric 找不到我的应用程序使用的原始资源.这是在我的构建文件中:

not in the location Robolectric is looking for it. At one point the manifest just got ignored, then a similar issue occurred for resources, the app or Robolectric couldn't find a raw resource my app uses. This is in my build file:

   sourceSets {
    main {
        java.srcDirs = ['src/main/java']
        resources.srcDirs = ['src/main/res']
    }
    test {
        java.srcDirs = ['src/test/java', 'src/main/java']
        resources.srcDirs = ['src/test/res', 'src/main/res']
    }
}

我如何告诉 Robolectric 在哪里寻找清单,更重要的是,在哪里寻找资源?

How do I tell Robolectric where to look for a manifest, and more importantly, where to look for resources?

我已经从 github 上查看了 Robolectric,我已经构建了它,将它安装在我本地的 .m2 存储库中,gradle 文件现在指的是本地 SNAPSHOT 构建,并且我确保 Gradle 没有从远程存储库获取新版本.然后我将 RobolectricGradleTestRunner 复制到我的项目中,我更改了定义文件位置的行:它不包含模块名称.现在它起作用了.

I have checked out Robolectric from github, I've built it, installed it in my local .m2 repo, the gradle file now refers to the local SNAPSHOT build, and I made sure Gradle doesn't get a new version from a remote repo. Then I copied the RobolectricGradleTestRunner to my project, I have changed the lines where the file locations are defined: it didn't contain the module name. Now it works.

推荐答案

我假设您正在尝试使用 JUnit 运行测试.您可以尝试两种不同的方法:

I'm assuming you're trying to run the tests with JUnit. You can try two different things:

  1. 创建自定义TestRunner类,如图此处.检查 CustomTestRunner 部分,在这里您基本上创建了一个实际上知道要使用的正确清单的 TestRunner.使用 @Config 注释指定您的测试,让它们与您的测试运行器一起运行.
  2. (我的首选)转到您的 JUnit 配置,运行 > 编辑配置.注意工作目录"文本框.将 /app(对于 OSX 和 Linux)或 \app (Windows) 附加到文本框中写入的路径.再次尝试运行,它应该可以工作.
  1. Create a Custom TestRunner class, as shown here. Check the CustomTestRunner section, where you basically create a TestRunner that actually knows the right manifest to use. Specify your tests for them to run with your test runner, with the @Config annotation.
  2. (My preferred choice) Go the your JUnit configuration, Run > Edit Configurations. Notice the 'Working Directory' textbox. Append /app (for OSX and Linux) or \app (Windows), to the path written in the textbox. Try running again and it should work.

这篇关于Robolectric 说“找不到 AndroidManifest.xml";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆