我有我的 buyer
、seller
模块和一个 common
模块。 buyer
和 seller
模块中使用的少数布局放在 common
模块中。
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')
在项目中添加了库模块。
- 在库模块(即公共(public)模块)中创建了布局/ View 。
- 包含在主布局中
最后,我能够以编程方式更改它。
导入 kotlinx.android.synthetic.main.activity_home.* 导入 kotlinx.android.synthetic.main.item_library.*
构建的环境可能存在一些问题。注意:我使用的是最新的构建版本以及 android 和 kotlin 插件。
请更新您的日志以进一步澄清您的问题。
关于android - 无法解析库模块中的 Kotlin Android 扩展布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50179177/