Android的工作室:“新的模块 - >导入现有项目“与”导入模块“ [英] Android Studio: “new module -> import existing project” vs. “import module”
问题描述
我有什么:
四独立工作的Android模块:
-
MyProjectMainModule
,主容器应用程序,连接到MyProject的
-
MyGradleModule
,图书馆,与在gradlew
过程内置所有必需的组件。 -
我的preGradleModule
,图书馆与的src /
,RES /
,的AndroidManifest.xml
和的pom.xml
,没有包装的gradle -
MyRawModule
,图书馆与的src /
,RES /
,的AndroidManifest.xml
,不用的pom.xml
(常见于基于Ant-Eclipse项目)
想我来实现的:
要导入所有三个模块(即 MyGradleModule
,我的preGradleModule
, MyRawModule
)到 MyProject的
为 MyProject的
的依赖关系。完整的项目结构应类似于下项目结构:
MyProject的
| --MyProjectMainModule
| --MyGradleModule
| - 我的preGradleModule
| --MyRawModule
问:
实现所有三个模块( MyGradleModule
,我的preGradleModule
和 MyRawModule
)具有不同的结构,什么是最优化的方式来以最小的努力导入每个模块?
能否请你配合在你的答案每个模块以下的Android Studio的菜单项(如果你使用任何):
-
文件
- >导入模块...
-
文件
- >新建模块...
- >导入现有项目
-
文件
- >新建模块...
- >的Android库
您可以通过在MyProject的创建 settings.gradle
文件中添加三个模块在同一个项目/文件夹,并添加模块吧:
包括':MyGradleModule
包括:我的preGradleModule
包括:MyRawModule
然后为每个模块,配置的build.gradle
依赖关系需要引用其他模块。例如,将其添加到MyProjectMainModule使其使用由MyGradleModule产生的输出:
{相关性
编制项目(':MyGradleModule')
}
最后,如果您的项目有异构子模块,那么你可以使用'sourceSets封闭配置它们的结构。例如,您的原始模块将有一个类似的配置:
安卓{
sourceSets {
主要{
manifest.srcFile'的AndroidManifest.xml
java.srcDirs = ['src'中]
resources.srcDirs = ['src'中]
aidl.srcDirs = ['src'中]
renderscript.srcDirs = ['src'中]
res.srcDirs = ['水库']
assets.srcDirs = ['资产']
}
androidTest.setRoot(测试)
}
}
检查出的摇篮插件指南,看看有什么配置选项。
What I have:
Four independently working Android modules:
MyProjectMainModule
, a main container application, attached toMyProject
MyGradleModule
, a library, with all necessary components built duringgradlew
process.MyPreGradleModule
, a library, withsrc/
,res/
,AndroidManifest.xml
, andpom.xml
, without gradle wrapperMyRawModule
, a library, withsrc/
,res/
,AndroidManifest.xml
, withoutpom.xml
(commonly seen in Ant-based Eclipse projects)
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
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?
Could you please match one of the following Android Studio menu items with each modules in your answer (if you use any):
File
->Import Module...
File
->New Module...
->Import Existing Project
File
->New Module...
->Android Library
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'
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')
}
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')
}
}
Check out this section of the Gradle Plugin Guide to see what configuration options are available.
这篇关于Android的工作室:“新的模块 - >导入现有项目“与”导入模块“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!