Android Studio - How to make modules inside a subdirectory?

前端 未结 3 1138
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-02 09:23

Suppose that I had 3 modules: mod1, mod2 and mod3.

In normal case, the file system hierarchy should be:

[android_root_dir]
build.gradle # list this file          


        
3条回答
  •  萌比男神i
    2021-02-02 10:10

    Though include ':modules:mod1' , ':modules:mod2', ':modules:mod3' kind of gives you the solution, the AS annoyingly generates an empty module for modules. To address this gotcha, please refer to the settings.gradle on the gradle github repo. It basically includes every subproject as a top level one and then sets its project directory to be inside the subdirectory. This trick should perfectly address your need.

    include 'mod1'
    include 'mod2'
    ...
    include 'modX'
    rootProject.name = 'gradle'
    rootProject.children.each {project ->
        String projectDirName = "modules/$project.name"
        project.projectDir = new File(settingsDir, projectDirName)
        assert project.projectDir.isDirectory()
        assert project.buildFile.isFile()
    }
    

提交回复
热议问题