java - 从 Android 应用程序中的其他模块引用公共模块
问题描述
我正在创建一个包含两个模块的 Android 应用程序。
一个模块是普通平板/手机模块,另一个是 WearOS 模块。
但是还有第三个模块叫做“common”。通用模块编译无误。它有java类、资源等等。它有
import static com.myapp.common.R.*;
在需要资源的主要 java 类中(IDE 建议在资源参考说明下添加红线时添加该资源)。
这三个包名称类似于:
com.myapp.common
com.myapp.wear_module
com.myapp.phone_tablet_module
应用程序 build.gradle 文件包括
implementation project(':app:common')
磨损模块 build.gradle 文件包括
implementation project(':app:common')
手机/平板电脑模块包括
implementation project(':app:common')
但是我看到其他模块中没有引用公共模块的资源和java文件。此外,我看到一个奇怪的抱怨,例如:
ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :app:common
IDE 建议添加实现行,但它已经存在。如果我接受,它会添加另一个。
问题是什么。如何将通用模块导入其他模块?
解决方案
尝试这个implementation project(':common')
然后在settings.gradle确保像这样包含公共模块
include ':app', ':common', ':wear_module', ':phone_tablet_module' // as this is the modules names
rootProject.name='MyApp'
推荐阅读
- flutter - Flutter - 如何捕获仅在实时构建中而不是在调试中发生的崩溃?
- c# - C# WPF OnMouseEnter 和 OnMouseLeave 循环
- python - 哪个类在 Django REST 中调用序列化程序类
- python - 我可以在 python 脚本中使用 FFMPEG 将列表中的 mp4 文件合并到一个文件中吗
- java - 从 Kotlin 中的 deeplink Url 中提取 QueryParameters
- c++ - 当我为 long long 变量分配更大的数字时,为什么变量为 0?
- c++ - 如何配置 CodeLite IDE 以使用 C++ 和 SFML 库?(Windows/Linux) 配置完整解决方案
- javascript - 是否有任何处理程序来旋转对象?
- wordpress - 如何使叠加层出现在 Elementor 中的图像上方?有关更多详细信息,请参阅快照
- java - 如何用java替换文本文件中的特定字符串?