The problem arises due to workspace.xml and modules.xml inside the .idea directory of your project.
You cannot remove any module if it has a blue rectangle on it. Follow the instructions to remove the module from the project:
Go to File> Project Structure, select the module you want to remove, and click the Red Minus button to delete.
Note. Also remove if any link in the build.gradle file of your main module.
Clean your project using Build> Clean Project
Close your Android studio now
Go to the project directory and delete the file your_project.iml and the contents of the .idea folder from the project root directory, and also delete the directory of the module that you want to delete.
Open Android Studio again and let it sync the project with gradle
If the module appears again, it will not have a blue rectangle shortcut, so you can remove it with the right mouse button> delete and clear the project.
Synchronize your project with gradle, if it appears again, check the event log, if something is used somewhere from the library, if it removes them all. Check your File > Project structure if there is any error related to your module library below. If he uses the red lamp button, remove it.
After deleting all things Clean the project and sync it again.
Let me know in the comments if there is any problem.
source share