Android Studio - How to make modules inside a subdirectory?

旧时模样 提交于 2019-12-03 08:35:50

问题


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 just to make it clear.
----mod1
----mod2
----mod3

But what I want is:

[android_root_dir]
build.gradle # list this file just to make it clear.
----modules
    ----mod1
    ----mod2
    ----mod3

how to do it in Android Studio 1.1.0?

PS: I find this article but it does not seem to work, or it works for earlier versions of AS, not 1.1.0: How can I move a module inside a subdirectory?


回答1:


You can do it:

root
  build.gradle
  settings.gradle
  modules
    mod1
      build.gradle
    mod2
      build.gradle
    mod3
      build.gradle

In your settings.gradle

include ':modules:mod1' , ':modules:mod2', ':modules:mod3'



回答2:


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()
}



回答3:


My project struct

Coding
   app
   push-dir
     coding-push
     push-xiaomi
   setting.gradle

setting.gradle file

// need repeat declarative, i think it's bug
include ':app'
include ':coding-push'
include ':push-dir:coding-push'
include ":push-xiaomi"
include ":push-dir:push-xiaomi"

I used repeat declarative in settings.gradle to solve. (Android Studio 3.0), I think it's AS's bug. Sometimes need restart AS.



来源:https://stackoverflow.com/questions/28658574/android-studio-how-to-make-modules-inside-a-subdirectory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!