问题描述
限时送ChatGPT账号..四个独立工作的 Android 模块:
Four independently working Android modules:
MyProjectMainModule
,一个主容器应用,附属于MyProject
MyProjectMainModule
, a main container application, attached to MyProject
MyGradleModule
,一个库,包含在 gradlew
过程中构建的所有必要组件.
MyGradleModule
, a library, with all necessary components built during gradlew
process.
MyPreGradleModule
,一个库,带有src/
、res/
、AndroidManifest.xml
、和 pom.xml
,没有 gradle 包装器
MyPreGradleModule
, a library, with src/
, res/
, AndroidManifest.xml
, and pom.xml
, without gradle wrapper
MyRawModule
,一个库,带有src/
、res/
、AndroidManifest.xml
,没有 pom.xml
(常见于基于 Ant 的 Eclipse 项目)
MyRawModule
, a library, with src/
, res/
, AndroidManifest.xml
, without pom.xml
(commonly seen in Ant-based Eclipse projects)
我想达到的目标:
将所有三个模块(即MyGradleModule
、MyPreGradleModule
、MyRawModule
)作为MyProject
的依赖项导入MyProject
代码>我的项目代码>.完整的项目结构应类似于以下项目结构:
What I'd like to achieve:
To import all three modules (i.e. MyGradleModule
, MyPreGradleModule
, MyRawModule
) into MyProject
as dependencies of MyProject
. The complete project structure should resemble below project structure:
MyProject
|--MyProjectMainModule
|--MyGradleModule
|--MyPreGradleModule
|--MyRawModule
问题:
实现所有三个模块(MyGradleModule
、MyPreGradleModule
和 MyRawModule
)具有不同的结构,导入每个模块的最佳方式是什么用最少的努力?
Question:
Realizing all three modules (MyGradleModule
, MyPreGradleModule
, and MyRawModule
) have different structures, what are the most optimal ways to import each modules with minimal efforts?
您能否将以下 Android Studio 菜单项之一与答案中的每个模块相匹配(如果您使用):
Could you please match one of the following Android Studio menu items with each modules in your answer (if you use any):
文件
-> 导入模块...
File
-> New Module...
-> 导入现有项目
File
-> New Module...
-> Android 库
File
-> Import Module...
File
-> New Module...
-> Import Existing Project
File
-> New Module...
-> Android Library
推荐答案
您可以通过在 MyProject/文件夹中创建一个 settings.gradle
文件并添加模块来将这三个模块添加到同一个项目中给它:
You can add the three modules to the same project by creating a settings.gradle
file in the MyProject/ folder and adding the modules to it:
include ':MyGradleModule'
include ':MyPreGradleModule'
include ':MyRawModule'
然后对于每个模块,配置 build.gradle
依赖项以根据需要引用其他模块.例如,将此添加到 MyProjectMainModule 以使其使用 MyGradleModule 生成的输出:
Then for each module, configure the build.gradle
dependencies to reference the other modules as needed. For example, add this to the MyProjectMainModule to make it use the output produced by MyGradleModule:
dependencies {
compile project(':MyGradleModule')
}
最后,如果您的项目具有异构子模块,那么您可以使用sourceSets"闭包配置它们的结构.例如,您的原始模块将具有与此类似的配置:
Finally, if your project has heterogeneous submodules then you can configure their structure using the 'sourceSets' closure. For example, your raw module would have a configuration similar to this:
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
androidTest.setRoot('tests')
}
}
查看 Gradle 插件指南的这一部分 查看可用的配置选项.
Check out this section of the Gradle Plugin Guide to see what configuration options are available.
这篇关于Android Studio:“新模块->导入现有项目"与“导入模块"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论