Android的工作室:“新的模块 - >导入现有项目“与”导入模块“ [英] Android Studio: “new module -> import existing project” vs. “import module”

查看:156
本文介绍了Android的工作室:“新的模块 - >导入现有项目“与”导入模块“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么:

四独立工作的Andr​​oid模块:


  1. MyProjectMainModule ,主容器应用程序,连接到 MyProject的


  2. MyGradleModule ,图书馆,与在 gradlew 过程内置所有必需的组件。


  3. 我的preGradleModule ,图书馆与的src / RES / 的Andr​​oidManifest.xml 的pom.xml ,没有包装的gradle


  4. MyRawModule ,图书馆与的src / RES / 的Andr​​oidManifest.xml ,不用的pom.xml (常见于基于Ant-Eclipse项目)


想我来实现的:

要导入所有三个模块(即 MyGradleModule 我的preGradleModule MyRawModule )到 MyProject的 MyProject的的依赖关系。完整的项目结构应类似于下项目结构:

  MyProject的
| --MyProjectMainModule
| --MyGradleModule
| - 我的preGradleModule
| --MyRawModule

问:

实现所有三个模块( MyGradleModule 我的preGradleModule MyRawModule )具有不同的结构,什么是最优化的方式来以最小的努力导入每个模块?

能否请你配合在你的答案每个模块以下的Andr​​oid Studio的菜单项(如果你使用任何):


  1. 文件 - > 导入模块...

  2. 文件 - > 新建模块... - > 导入现有项目

  3. 文件 - > 新建模块... - > 的Andr​​oid库


解决方案

您可以通过在MyProject的创建 settings.gradle 文件中添加三个模块在同一个项目/文件夹,并添加模块吧:

 包括':MyGradleModule
包括:我的preGradleModule
包括:MyRawModule

然后为每个模块,配置的build.gradle 依赖关系需要引用其他模块。例如,将其添加到MyProjectMainModule使其使用由MyGradleModule产生的输出:

  {相关性
  编制项目(':MyGradleModule')
}

最后,如果您的项目有异构子模块,那么你可以使用'sourceSets封闭配置它们的结构。例如,您的原始模块将有一个类似的配置:

 安卓{
    sourceSets {
        主要{
            manifest.srcFile'的Andr​​oidManifest.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:

  1. MyProjectMainModule, a main container application, attached to MyProject

  2. MyGradleModule, a library, with all necessary components built during gradlew process.

  3. MyPreGradleModule, a library, with src/, res/, AndroidManifest.xml, and pom.xml, without gradle wrapper

  4. MyRawModule, a library, with src/, res/, AndroidManifest.xml, without pom.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):

  1. File -> Import Module...
  2. File -> New Module... -> Import Existing Project
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆