Android Studio: Background task running indefinitely

I've find out that I should use the solution of @free3dom which is the Invalidate Caches / Restart option in the File menu.

I have to do this every time I change some project file by switching branches in GIT.

And yes, Android Studio really sucks and is full of bugs...


Unplug all the phones and plug them again, it gets working. It is related to adb as stated here : https://code.google.com/p/android/issues/detail?id=172387 and a known bug that is to be fixed in the future


The indexing is triggered through inotify on Linux.
There is a limit to how many directories a single user can set watches on. If your project is large, then this limit may be exceeded, and Android Studio falls back to recursive scanning mode, which is very slow.

To fix this, add this line to /etc/sysctl.conf file:

# Increase the limit for Android Studio
`fs.inotify.max_user_watches = 500000`

Then run sudo sysctl -p.


Stopping and closing the emulators that I had running solved this issue for me on the latest version of Android Studio.