Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I move a module inside a subdirectory?

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?

like image 762
Brais Gabin Avatar asked Jan 12 '15 15:01

Brais Gabin


3 Answers

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).

like image 102
Scott Barta Avatar answered Oct 15 '22 11:10

Scott Barta


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.

like image 40
lenhuy2106 Avatar answered Oct 15 '22 11:10

lenhuy2106


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.

like image 36
Javaru Avatar answered Oct 15 '22 11:10

Javaru