我有一个多模块项目,其结构如下。
这是解决此错误的代码:https://github.com/ajitsing/MultiModuleAndroid https://github.com/ajitsing/MultiModuleAndroid
Root
|- App Module (Application, Data binding enabled)
|- Lib Module (Library, Data binding enabled)
主模块依赖于 Lib 模块。 Lib 模块包含所有 android 测试。当我使用 testCoverageEnabled 运行 lib 模块的 androidTests 时,它会抛出一些奇怪的数据绑定错误。所有这些错误都是针对自定义绑定的。
:core:compileDebugAndroidTestJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':core:compileDebugAndroidTestJavaWithJavac'.
> java.lang.RuntimeException: Found data binding errors.
Cannot find the setter for attribute 'app:marginStart' with parameter type int on android.widget.LinearLayout.
file:///Users/Ajit/projects/myProject/core/build/intermediates/bundles/debug/res/layout/my_layout.xml Line:25
为了解决这个问题,我将自定义绑定 java 类复制到 androidTest 文件夹,这解决了上述错误。但随后它开始抱怨 BR 的属性。似乎它无法解析 BR.java 类。
MyBinding.java:87: error: cannot find symbol
case BR.name: {
有人面临类似的问题吗?任何形式的帮助将不胜感激。谢谢!
Update:当我设置测试覆盖率启用 = true and 应用插件:'com.android.library',它不会在 build/intermidates/androidTest 文件夹中生成 BR.class。
构建文件夹应用插件:'com.android.application'
构建文件夹应用插件:'com.android.library'