How can I move a module inside a subdirectory?

前端 未结 3 865
走了就别回头了
走了就别回头了 2021-01-05 09:44

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:

相关标签:
3条回答
  • 2021-01-05 10:10

    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.

    0 讨论(0)
  • 2021-01-05 10:20

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

    0 讨论(0)
  • 2021-01-05 10:28

    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.

    0 讨论(0)
提交回复
热议问题