11

I need to write a lot of trivial modules and I don't want to hide the main modules between them. For this reason I want to have a directory tree like this:

Project
|-module1
|-module2
+-directory
    |-module3
    |-module4
    +-module5

The problem: if I move the modules inside a new folder Android Studio doesn't find them.

So, my question is: How can I move modules inside a directory?

yoAlex5
  • 29,217
  • 8
  • 193
  • 205
Brais Gabin
  • 5,827
  • 6
  • 57
  • 92

4 Answers4

19

I would recommend closing the project in Android Studio, moving the directories manually in your OS, and updating the project's settings.gradle file to point to the modules in their new location. Using your example, the updated settings.gradle file will look like this:

include ':module1'
include ':module2'
include ':directory:module3'
include ':directory:module4'
include ':directory:module5'

Then re-open the project in Android Studio, and make sure it syncs the project with the new Gradle files (which it should do automatically, but if it doesn't, click the toolbar button for it).

Scott Barta
  • 79,344
  • 24
  • 180
  • 163
5

You can now define the location of modules with

include ':myModule'    

project(':myModule').projectDir = new File('dir/myModule')

Further, you have to remove the .iml files under the module directory to let Android Studio recreate them.

lenhuy2106
  • 313
  • 3
  • 8
0

You can simply add them as a new module.

  1. Open the new module dialog either via:
    • File > New Module; or
    • File > Project Structure, [Modules] and click the add icon enter image description here and select New Module
  2. Select the module type, I assuming Android in your case. Then select the Android module type
  3. Click Next
  4. Either type in or use the browse button enter image description here to open the file chooser and enter the "Content Root" as Project\directory\module3
  5. The "module file location" should update to match the content root, but double check it and set it if necessary
  6. Click Finish
  7. Repeat for the other modules

By default, in the project tool window tree, it will show a flat structure of:

Project
+-Module1
+-Module2    
+-Module3
+-Module4
+-Module5

If you want to add a hierarchy to the project tree structure:

  1. Open the project structure dialog (File > Project Structure)
  2. Select the modules panel on the left.
  3. Select module3 and right click it. Select Move Module to Group > New Top Level Group.
  4. Enter a name and click OK.
  5. for all the other sub modules, select them, right click, and select Move Module to Group > {yourGroupName} > To this group

Now in the project tool window, those modules will be grouped into a hierarchy.

Javaru
  • 30,412
  • 11
  • 93
  • 70
  • 2
    This options are not at Android Studio. I suppose that this options are at IntelliJ Idea... I probably need to change to *pure* IntelliJ. – Brais Gabin Jan 12 '15 at 17:00
0

One more variant where you include modules and provide their paths

include ':module1', ':module2', ':module3'

project(':module1').projectDir = new File('modules/module1')
project(':module2').projectDir = new File('modules/module2')
project(':module3').projectDir = new File('modules/module3')
yoAlex5
  • 29,217
  • 8
  • 193
  • 205