我有我的buyer
, seller
模块和一个common
模块。两者都使用的布局很少buyer
and seller
模块被放置在common
module.
common -> layout_toolbar.xml
buyer -> activity_sell.xml ->
<LinearLayout>
<include layout="@layout/layout_toolbar" /> <!-- layout_toolbar.xml is from common module -->
</LinearLayout>
seller -> activity_buy.xml ->
<RelativeLayout>
<include layout="@layout/layout_toolbar" /> <!-- layout_toolbar.xml is from common module -->
</RelativeLayout>
buyer -> BuyActivity.kt
toolbar.title = "Buy"
seller -> SellActivity.kt
toolbar.title = "Sell"
在 IDE 中一切正常,
- 通过解析包含标签并在 IDE 的布局预览中展开,我的布局预览可以正确显示。
- 我的 kotlin 文件也正确解析了工具栏引用,并且没有显示任何问题。
但每当我尝试构建应用程序时,它都会给出编译器错误:
Unresolved reference: toolbar <-- Id of the toolbar inside layout_toolbar.xml
如果IDE可以正确解决依赖关系,为什么gradle无法构建?我做错了什么吗?
请注意common
模块添加为implementation
在其他两个模块中。但我尝试过api
这也不起作用。
乍一看,这似乎是一个好问题。我在当前的项目中重现了同样的问题。
-
我已经通过添加了库模块
实施项目(':mylibrary')
在项目中添加了库模块。
- 在库模块(又名公共模块)中创建了布局/视图。
- 包含在主布局中
-
最后,我能够以编程方式更改它。
导入 kotlinx.android.synthetic.main.activity_home.*
导入 kotlinx.android.synthetic.main.item_library.*
构建环境可能存在一些问题。注意:我使用的是最新的构建版本以及 android 和 kotlin 插件。
请更新您的日志以进一步澄清您的问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)