I hit this build problem today after switching between Android development and spring boot microservice development.
Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project
The solution was simple - in IntelliJ:
File -> Invalidate Caches / Restart
Choose Invalidate and Restart
Rebuild after IntelliJ restarts.