Project already contains module with this name -- Android Studio
Asked Answered
A

20

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

Aldershot answered 16/10, 2015 at 13:44 Comment(1)
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...Boston
B
52

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.

Benn answered 15/3, 2016 at 12:49 Comment(1)
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!Repletion
L
32

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.

Lynnett answered 26/12, 2019 at 1:9 Comment(0)
S
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.
Sisterly answered 6/5, 2016 at 5:30 Comment(1)
Thank you, you saved my life!!! I need to delete module folder on step 2Ealasaid
B
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.

Blase answered 5/1, 2016 at 8:23 Comment(0)
R
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.

Rosenstein answered 10/3, 2016 at 21:39 Comment(0)
D
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.

Divergence answered 16/9, 2016 at 0:11 Comment(1)
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.Coppersmith
A
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>
Attired answered 5/12, 2019 at 21:20 Comment(1)
its not complete answer, must delete folder from paret of this .xml, update answerPineal
E
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

Enterovirus answered 17/7, 2017 at 11:32 Comment(0)
S
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.

Slone answered 9/11, 2019 at 0:29 Comment(0)
D
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.

Darsie answered 25/8, 2021 at 20:35 Comment(0)
L
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

Leukocyte answered 16/10, 2015 at 13:59 Comment(3)
Thanks for the answer, but nothing happens, If I change the name it takes, but I don't want to change the name of the Module due to some reasons.Aldershot
you are not able to remove in Dependencies.??#Leukocyte
I had removed from dependencies, but it still says the Project already contains the module with the same name, although I had removed it.Aldershot
P
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

Portentous answered 4/6, 2016 at 10:48 Comment(0)
R
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.

Ringed answered 7/11, 2016 at 21:2 Comment(0)
P
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'
Principalities answered 13/1, 2017 at 9:21 Comment(0)
L
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.

Lossa answered 28/3, 2017 at 10:26 Comment(0)
P
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.

Ptolemy answered 24/10, 2019 at 18:59 Comment(0)
L
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

Lanceted answered 27/4, 2022 at 12:55 Comment(0)
W
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.

Wain answered 16/7, 2022 at 20:44 Comment(0)
B
0

In some cases invalidate cache and restart android studio will also work. Because when fetching your code from git it might have some issue in my case it worked for me.

Babblement answered 5/1, 2024 at 13:46 Comment(0)
L
0

i had the problem in android studio, that i created some submodule, but wanted to delete it again, then on "Create New Module"->"Java or Kotlin Library" when entering the Library Name, it said "module_x_y already exists.". I followed the solutions above, but did not resolve the issue completely. Then i searched for "module_x_y" in the whole project (via Notepad++ full text search) and found in \.idea\workspace.xml the line

<change afterPath="$PROJECT_DIR$/module_x_y/README.md" afterDir="false" />

i deleted this line and my android studio did some strange behaviors, but after some short wait period, i was able to create the module with the name again. So i guess you have to remove the module from all the build.gradle files etc. as mentioned in the solutions above and in case you still cant re-create the module, take a look at workspace.xml, maybe this helps someone.

Laughry answered 10/6, 2024 at 20:25 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.