51

I had successfully imported a Module in my Application project in Android Studio. Then I deleted or removed the module by following the below link:

How to delete a module in Android Studio

I also removed the project module from the dependencies of my build.gradle(app) file.

Now, When I need to again include the same module project in my Andorid Application, it doesn't allows me, and gives the Project already contains module with the same name error.

I had check in my Project, Package, Android Structure but the project module which i need to Import and add as a Module Project is not there but still it say it already exist.

Can anyone help me to overcome this issue.??

Community
  • 1
  • 1
Pravinsingh Waghela
  • 2,516
  • 4
  • 32
  • 50
  • Were you ever able to solve this? im running into the same problem. Accidentally deleted a dependency project and now i can't add it again because it said there already is a module with the same name. Tried all of Chirag SolankI's steps, but it doesn't work... – Erik Verboom Dec 07 '15 at 16:20

18 Answers18

49

If somebody faces this issue, except removing the Folder containing the old module also remove from the settings.gradle file the line corresponding to the old module: include ':youroldmodule'. If you dont remove that line manually, 2 modules with the same name will appear when trying to add module dependency.

eldjon
  • 2,800
  • 2
  • 20
  • 23
  • 3
    It turns out that I just need to add the module name into `settings.gladle` file, sync it and it will automatically appears inside Android project. I didn't even need to use "File / Import Module" dialog at all! – Mike Keskinov Feb 20 '21 at 13:50
31

Switch to the Project View. Then open .idea/modules.xml. Find and delete the line that corresponds to the module. Then Invalidate Caches and Restart. That's it.

Kwabena Berko
  • 1,091
  • 11
  • 8
26

I solved the problem through this way:

  1. Open Module Settings(Mac: command + down; Windows: F4) and delete the module.
  2. Delete the module folder on the disk. You will find it at ~/AndroidStdioProjects/YourApplicationName/ModuleName.
  3. Import the Module.
LunaElf
  • 345
  • 3
  • 6
23

I have encountered this. And I deleted the folder which below my project with the module name I set before, then I can import a module with same name again.

Hope this helps you.

Venson Yen
  • 231
  • 2
  • 3
6

The project view on the left hand side, doesn't show 'everything' your project contains. You can switch the view from the drop-down menu, which is defaulted to 'Android' and change it to 'Project Files', which will probably show you where the problematic reference to the Module remains.

Alternatively, just check on disk where your project is located. I found references in the main project folder.

brandall
  • 6,094
  • 4
  • 49
  • 103
5

You can't import a module if you've put the code for the module in the place it will end up being copied to. I had the module source code placed in the project root folder and it failed to import with the above message. If you move the code away somewhere, on import Android Studio will copy the code in.

sunilr
  • 1,146
  • 10
  • 11
  • Thanks for sharing this, i had this same problem and as you said, AndroidStudio **wants** to copy the code over the project folder, so moving it to another folder and then letting AS copy the code was the solution. – RRoman Sep 22 '19 at 05:27
5

If you still see the error after removing the code from settings.gradle and the app gradle file, check the following file and remove any entries with the module name you are trying to remove.

./.idea/modules.xml

<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
    </modules>
  </component>
</project>
Sohail
  • 1,137
  • 2
  • 12
  • 22
3

Remove compile project(':module_name') from build.gradle under app folder

then remove module folder under your Project Folder

then remove your module name entry from settings.gradle

Muhammad Hamza Shahid
  • 956
  • 1
  • 15
  • 23
3

This worked for me:

In app/build.gradle, remove this line from dependencies {:

implementation project(':library')

In settings.gradle, change

include ':app', ':library'

to

include ':app'

Then you can import the library. Be sure to put the lines back into the gradle files you took out above.

Nick
  • 138,499
  • 22
  • 57
  • 95
Deaneaux
  • 31
  • 3
2

Those who are still seeing this issue and have already removed the module from settings.gradle file but still sees that Module already present while importing it again, This is what I did: 1.) Switch to Project mode in Android studio for your project 2.) Once switching it to Android mode, delete that module manually by clicking right click on it. And Hope it works for you now.

Siddharth Choudhary
  • 1,069
  • 1
  • 15
  • 20
0

I am Not Sure but I hope it's Help you.

Step 1: Pressed Alt + 1 for get Focus of your App.

Step 2: Now Pressed F4 for open Module structure of Project

Step 3 Now Select Dependencies and Remove All Extra dependencies of your project.

than Pressed OK.

and Resync gradle.

I hope you are clear with my solution.

Best Luck

Chirag Solanki
  • 1,107
  • 2
  • 13
  • 23
0

I had this problem when I was trying to add junit 4.12 to my project.First of all I delete old junit codes in dependencies of my build.gradle(app) file manually.Next I deleted the old junit.jar from my library with deleting libs folder and then create new libs folder directory in my app for add library.and for the end.......I find the old junit FILE near the end of project view after gradle folder....you can see in this image......and I deleted it.now I can add new module very easy and without same name error.sorry for bad english!! look this image for last order

0

I solved this by removing the existing module from the project structure, then renaming the folder. It finally worked when I removed the folder, ran a sync, then re-added the folder and attempted to import.

0

In one condition if you have copy a folder like this

rootProject/module1

if you import module android studio will find if you have same name folder. if you have it is not import android studio will tell you you have contains this module ,you just add this in setting.gradle like

include ':modlue1'
0

If shows this error after deleting the module from project structure then, select Project view of our project in android studio and then explore and the there will be the folder of module that we imported, right click on that and Delete it and rebuild the app.

PK 7
  • 101
  • 1
  • 10
0

If any of the above answers worked for you and you are sure that your branch is clean then close your Android Studio, browse to the root of your project and delete .idea folder. Then re-launch Android studio and run your project.

Hesam
  • 52,260
  • 74
  • 224
  • 365
0

I had same issue, initially created a module, then removed it from settings.gradle and finally the fix was to ACTUALLY remove ALL folders related to that module, those won't be visible in the ANDROID view, hence change to project view and remove all related or browse using an external tool and remove all folders

pinkfloyd
  • 255
  • 4
  • 13
0

For me, there was still a reference to the old module in my project's /.idea/gradle.xml file:

<option value="$PROJECT_DIR$/mymodule" />

I just deleted that line then re-synced with gradle and the error went away.

Adam Johns
  • 35,397
  • 25
  • 123
  • 176