261

I have installed Android Studio version 1.0.1. I have imported my projects from eclipse and it works fine. Then I deleted a module and reimported it into my Android Studio project. The gradle build says "BUILD SUCCESSFUL" but it pops up an alert window with the message

Failed to complete Gradle execution. Cause: Already disposed: Module: 'MYMODULENAME'

I can't start my app now. Any idea what I can do?

Edit: I solved the problem with the following instructions:

  1. Switch project view from Android to Project
  2. Remove entry include 'MYMODULENAME' in settings.gradle
  3. The blue box in the module symbol don't show. Then you can delete the module in the context menu
  4. Import the module
3
  • This seems like a bug... Have you filed one ? Commented Jan 25, 2015 at 0:33
  • Oded Breiner gave the right answer. This happens when you rename and then forget to delete the iml file Commented May 17, 2015 at 22:57
  • 2
    Just reimport the project into Android Studio.
    – JaydeepW
    Commented Aug 13, 2018 at 7:01

20 Answers 20

362

Note: this is purely an IDEA/AS issue, gradlew clean | Build > Clean | Build > Rebuild will just waste your time.

Most of the solutions here are blind stabbings in the dark. Here's what I found to be the root cause:

  1. Some of the .iml files may be missing (maybe because we deleted it), check if the module erroring has .iml.
  2. If it is missing, check if .idea/modules.xml has an entry for that module

While syncing I noticed that IDEA/AS tries to put a new duplicate entry into .idea/modules.xml while there's already one. This duplicate entry is probably disposed of twice while the sync tries to reset the modules in memory.

Quick Solution: In order to make it work the easiest is to delete .idea/modules.xml along with the .iml files. Additionally may worth deleting .idea/modules/ folder if it exists. Restart Android Studio (no need to clear cache) and force a Gradle sync from Gradle view or toolbar to recreate the files.

5
  • 92
    For lazy copy pasters: find . -name *.iml -delete && rm .idea/modules.xml, sync Android Studio
    – LukaCiko
    Commented Sep 3, 2018 at 11:28
  • 1
    Thanks very much on the insight. In my case there were two entries for the app module in modules.xml
    – Ishan
    Commented Dec 13, 2018 at 8:02
  • This works but Android Studio (3.4.1) keeps doing this to me when I switch projects. It will also keep trying to sync the previous module that i had open. Is there a long term solution for this? Commented Jul 10, 2019 at 17:36
  • @BenWilkinson Didn't notice in 3.4.1 the two projects I open are the same codebase from different clones. Although I choose "new window" most of the time. I would close AS, clean up both projects and hope that after the new sync they settle in.
    – TWiStErRob
    Commented Jul 10, 2019 at 18:52
  • for mac users find . -name "*.iml" -exec rm '{}' + && rm .idea/modules.xml
    – eugene
    Commented Mar 24, 2020 at 2:39
278

I figured out this problem by:

  1. ./gradlew clean
  2. Restart Android Studio
6
  • 1
    Its worked but I didn't get why its download gradle version ,I have already configure the latest gradle 2.2 Commented Feb 11, 2015 at 6:14
  • 29
    The 3rd time I came here to read that I have to restart Android Studio #eclipseflashback
    – passsy
    Commented Feb 17, 2015 at 20:54
  • 2
    Grandle and Android Studio are simply shameful: I removed a module via the GUI and it started to give me this errors. Commented Apr 19, 2015 at 11:26
  • thought first it didn't work but forgot to restart :D then it worked thx
    – tung
    Commented Jun 17, 2015 at 9:48
  • Instead of command line, i did the same via Build->Clean Project option in studio menu, and then restart. Just in case anyone having issue using command line, this is simpler. Does the same thing. :) Commented Sep 5, 2017 at 12:11
102

Simplest solution. (Try this first).

  1. Quit and Restart Android studio. (Quit not close)

  2. Build > Clean your project if needed.

0
85

works for me: File -> Invalidate Caches / Restart... -> Invalidate and Restart

3
  • Yep!!! A hard invalidation of caches is sometimes the only way to fix these things. Commented May 18, 2018 at 18:31
  • 4
    Infuriating that we still have to do this in 2019! Commented Apr 25, 2019 at 14:51
  • 1
    From all the other suggestions from users in this thread (./gradlew clean, to delete some project files, etc.), this was the only one that worked for me. Commented Nov 4, 2019 at 10:03
11

Sometimes gradlew clean or Invalidate Cache and Restart does not help, because these methods do not clean Android Studio specific files by themselves.

In this case, close AS and remove .idea directory and .iml file in a root project where settings.gradle file exists. This will make AS rebuild from the fresh ground.

2
  • 1
    I think this is the most robust solution
    – George
    Commented Jul 8, 2019 at 15:48
  • This solution solved my issue when i upgrade my Android Gradle to the build:gradle:3.5.0-rc02 Commented Aug 4, 2019 at 17:46
6

For me this happened when i deleted a module and built a new one with the same package name Solution:

Clean & Restart Studio

5
  1. In the left pane, change to "Project" view.
  2. Delete MYMODULENAME.iml
1
  • Delete mymodulename.iml
    – xgqfrms
    Commented Jan 27, 2017 at 8:08
4

For an alternative solution, check if you added your app to settings.gradle successfully

include ':app' 
0
2

For me this happened when I removed a module and tried to build the project:

Simple solution was to Invalidate the cache & Restart.

Android Studio>File>Invalidate Caches>Invalidate & Restart

1
  • invalidate and restart is best saviour Commented Jan 17, 2023 at 11:07
1

Had a similar issue when working with RN components in my Android project and the only way to get around this issue was to ignore the gradle project.

To do this:

  • Click on the gradle tab on the right hand side of AS
  • Right click the gradle module which is causing an issue
  • Click "Ignore Gradle Project"
  • Perform a gradle sync which should be successful now
  • If you need this module perform the 4 above steps again, this time when right click on the gradle project it'll show "Unignore Gradle Project"
  • Gradle sync should now work

No idea what causes this but I've had this happen to me when using React Native Maps.

Note: If you're still having issues following this. Try to refresh the gradle project which was causing issues.

1

If gradle clean and/or Build -> Clean Project didn't help try to re-open the project:

  • Close the project
  • Click "Open an existing Android Studio project" on the "Welcome to Android Studio" screen enter image description here
  • Select gradle file to open

Warning Be aware it's a destructive operation - you're going to loose the project bookmarks, breakpoints and shelves

1

below solution works for me

  1. Delete all .iml files
  2. Rebuild project
1

For Solve this issue take it this simple steps.

  1. Find the .idea folder in your Android studio under the Folder Project.
  2. In .idea --> Find this one. .idea/.modules
  3. Simple Delete that .modules folder and restart Your studio.
  4. when it reopens gradle sync Automatically and also recreate .modules folder and files.
  5. Error has gone !
0

I also face this problem sometimes. Click on gradle console in bottom bar of android studio, at right side. It will show the exact error in logs. My problem was that I had compile SDK 22 and imported appcomact library was of sdk 23.

0

I had the same problem, after delete some gradle files (of aws)

i solved it by mark them "ignore gradle"

I believe it is not the best answer but it solve it for me

Gradle (at the right bar)--> right click on the problematic gradle --> ignore

0

Although the accepted answer didn't work for me (unfortunately I can't leave a comment), it led me in the right direction.

in .idea/libraries i found that there were some duplicate xml files (the duplicates were named with a 2 before the _aar.xml bit).

deleting those, restarting android studio and sync fixed the error

0

I was having this issue because gradle and Android Studio were using a different path for the jvm. In the Event Log there was an option for AS and gradle to use the same path. Selecting this and then doing an invalidate cache & restart resolved the issue for me.

0

In my case, same as in this question, it happened because I had my project in a symbolic link directory. After reopening the project in the real directory and reconfiguring gradle (File -> Sync with Gradle files) the problem went away. Shame on you, Android Studio!

0

I have tried the Invalidate cached, remove .idea folder, .gradle folder, all of them does not work, So I remove the full project, then clone the repo again. it solve my problem.

-1

Since the accepted answer didn't work for me here's a solution that did:

  • You can use this program I made, and give it the project(s) folder and wait for it to say "Done." (The process might take some time),
  • or you can do it by hand and deleate the ".gradle" and ".idea" folders in the project folder and the "build" folder in any of it's subdirectories.

After any of the above processes is done an "Invalidate Caches... / Invalidate Caches and Restart" is needed if Android Studio was running otherwise you can just launch it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.