如何在Android模块中添加模块?

问题描述 投票:0回答:1

具有以下结构。

-根

  • 应用程序
  • 模块1
  • 模块2
      • 子模块

如何在Android模块中添加模块?这意味着 module2 仍然应该检测到 submodule,即使没有在 settings.gradle 中指定它。

目前

module2
build.gradle.kts 中的 implementation(project(":libs:submodule")) 无法正常工作。但是,如果我们这样做,它就会起作用

-根

  • 应用程序
  • 模块1
  • module2(仍然依赖于子模块,但位于根/项目级别)
  • 子模块

这是我们在 settings.gradle

 中指定 
submodule

的时候
rootProject.name = "Sample App"
include(":app")
include(":module1")
include (":module2") // Has dependency to submodule
include (":submodule")

但是我们想要的是 module2 已经包含子模块,所以我们不需要在项目中指定子模块。

android android-module gradle-submodule
1个回答
0
投票

所以,我创建了两个新模块

test1
test2
。我现在创建了一个名为
tests
的新目录。之后,我将两个模块从项目目录移动到
tests
目录。我编辑我的
settings.gradle
文件,其中有

include ':app'
include ':translations'
include ':test1'
include ':test2'

并将其更新为以下内容:

include ':app'
include ':translations'
include 'tests:test1'
include 'tests:test2'

然后我在

tests
目录中创建了另一个名为
subtest
的目录,并将
test2
模块移到了那里。然后我将我的
settings.gradle
文件更新为

include ':app'
include ':translations'
include 'tests:test1'
include 'tests:subtest:test2'

我在项目配置中做到了这一点,如下图所示:

enter image description here

现在看起来像:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.