How to undo deleting a module in android Studio

5.4k views Asked by At

I just deleted a module that contained the source code of my application. For this reason, I cannot debug and play my application in the emulator. In the Project view the folder does exist but in the android view doesn't exist.

Please help!

4

There are 4 answers

4
Sanket Berde On

Look up the folder in your actual file system (Using Explorer or Finder). If your source code exists there, you can re import it. Otherwise no one can help you. Also consider using a VCS like github next time.

0
Ivan Bartsov On

If you removed just the module not it's contents (through Project Structure dialog) and your module folder is now considered just a generic folder by Android Studio, here's how to bring it back:

Switch to Project mode (of the Project pane), open file .idea/modules.xml (or just hit Ctrl[Cmd] + Shift + N and search for modules.xml)

Add a <module /> tag corresponding to your accidentally deleted module, do Gradle Sync and the module folder will once again be recognized as such.

Here's a sample

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/MODULE_NAME/MODULE_NAME.iml" filepath="$PROJECT_DIR$/MODULE_NAME/MODULE_NAME.iml" />
      <module ...
    </modules>
  </component>
</project>
0
Vincy On

I had the same situation and the easiest way to re-add the deleted module from Project Structure is by selecting the Android Mode option from the top left drop down (not sure what that called) which shows all the android specific structures.

Once you have done that you would see the file called settings.gradle. Open that up by double clicking on it and either add a include line or use the comma and the module name with color as prefix as the string or as shown below:

include ':pDFTron', ':signalr-sdk', ':signalr-client'

or

include ':pDFTron'

include ':signalr-sdk'

include ':signalr-client'

Hope this helps...

1
matthew On

The trick is to get around Android Studio complaining the module name is in use (still). When you delete a module the files are still on disk and the dir is still visible.

Alternative A) Move the deleted module dir outside the project and then import it from there (again)

Alternative B) Rename the deleted module directory and then re-import.

Step 1) Right click on the deleted module dir in the project view, and choose Refactor -> Rename Rename the dir with an trailing underscore Untick the search for references.

Step 2) Use File->New->Import module and navigate to your renamed dir. Studio will complain "Project already contains module with this name" Just delete the underscore from the module name to get back to the original module name Finished Import

Stop NOW for the simple solution. You have your module back in a directory with an underscore.

If you want to rename the directory you can refactor it again BUT Studio does not handle that correctly even if you tick all the refactor boxes To fix this failure goto the settings.gradle file in the project dir and remove the line that maps your module name to the directory with the underscore e.g. remove project(':afreechart_sample').projectDir = new File('afreechart_sample_')

A rebuild should now work.