Android Studio: “new module -> import existing project” vs. “import module”

后端 未结 6 1073
陌清茗
陌清茗 2021-01-04 06:14

What I have:

Four independently working Android modules:

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

6条回答
  •  孤城傲影
    2021-01-04 06:40

    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.

提交回复
热议问题