Pal*_*lak 34 java android android-studio
我在单个android项目中创建了两个模块,命名为x和y.
现在我想在Egg类中导入类Foo,为此我在类Egg中编写了下面提到的语句
Import com.example.y.Foo;
Run Code Online (Sandbox Code Playgroud)
现在,Foo不被android识别.
问题,
是否可以仅使用import语句从其他模块导入Class?
我是否需要创建模块y的库,然后将创建的库导入模块x?
或者解决方案可能是别的.
pde*_*d59 69
确保以下内容:
在settings.gradle中,您应该:include ':x', ':y'.
在x/build.gradle中,您应该将y添加为依赖项:
dependencies {
compile project(':y')
// other dependencies
}
Run Code Online (Sandbox Code Playgroud)
现在在创建新模块时,settings.gradle自动添加此模块。之后,您应该添加以下行:
dependencies {
implementation(
...,
..,
project(":y")
)
}
Run Code Online (Sandbox Code Playgroud)
结合并更正之前的两个答案,最好的解决方案是将这一行添加到 x/build.gradle -> dependencies
implementation project(':y')
Run Code Online (Sandbox Code Playgroud)
compile project() - 已弃用,不再工作
如果您只想实现单个模块,则无需使用implementation(..., .., project(":y")结构。
| 归档时间: |
|
| 查看次数: |
38273 次 |
| 最近记录: |