【问题标题】:Robolectric in library module: manifest merger fails due to placeholder not being provided库模块中的 Robolectric:由于未提供占位符,清单合并失败
【发布时间】:2022-02-03 13:08:14
【问题描述】:
我正在尝试在库模块中使用 Robolectric。该库希望应用程序模块为清单占位符指定一个值。当我运行测试时出现错误:
Attribute data@scheme at tempFile1ProcessTestManifest273304251747743144.xml requires a placeholder substitution but no value for <someParameter> is provided.
因此,测试没有运行。
【问题讨论】:
标签:
android
android-studio
unit-testing
kotlin
robolectric
【解决方案1】:
为了解决这个问题,我们需要为 Robolectric 提供一个假的 AndroidManifest.xml,它要么定义这个占位符,要么完全删除需要它的节点。
假AndroidManifest.xml文件示例:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application>
<activity
android:name="com.example.RedirectActivity"
tools:node="remove" />
</application>
</manifest>
在上面的示例中,我选择完全删除需要占位符的节点。
那么这个AndroidManifest.xml的正确放置位置是在库模块的test目录的根目录下。例如:/library/src/test/AndroidManifest.xml。
通过此设置,占位符问题现在消失了。