Android Studio: Background task running indefinitely
AndroidAndroid StudioAndroid Problem Overview
After updating the Android SDK, I started Android Studio. Now its showing background task continuously running with message
> Updating indices: Scanning files to index.
In this mode, it is nearly hanged and I can not work on it. Not able to find a way to stop background task. A restart of Android Studio didn't work either.
Android Solutions
Solution 1 - Android
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...
Solution 2 - Android
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
Solution 3 - Android
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
.
Solution 4 - Android
Stopping and closing the emulators that I had running solved this issue for me on the latest version of Android Studio.
Solution 5 - Android
I've this problem recently and in my case I'm using a linux 64bit SO and my android studio was in a ntfs disk. Since ntfs doesn't support executable permition the file fsnotifier64 was unable to execute and android-studio fallback into a compatibility mode that is much slower. The solution was copy the android-studio folder into my home folder that was ext4 and that way i was able to set permitions.
Solution 6 - Android
I struggled with this issue for almost one hour, and after that found that this is the adb connection issue, you can disconnect your device once and stops all the working adb processes. This issue may get resolved.
Solution 7 - Android
This was happening in my project every time I added a new Activity. So I included my R file in that class and it stopped.
> eg: import com.domain.appname.R;
This fixed the problem.
Solution 8 - Android
I'm also facing this issue, I've tried almost all the methods mentioned in this post, but none of them worked. The only solution that worked for me is to upgrade Android Studio to 3.5(which is still a test version at the time of writing this answer).
Solution 9 - Android
This happens to me after updating the Android Gradle plugin version from (3.5.3) to (3.6.2) and Gradle version from (5.4.1) to (5.6.4) it solved after downgrading the plugin again to change Android Gradle plugin version and Gradle version: File > Project Structure > Project
reference: https://developer.android.com/studio/releases/gradle-plugin.html
Solution 10 - Android
In my case, it was a module circular dependency problem. It wouldn't show until I removed all the changes into all build.gradle
files, then reopen it and apply the stash.
It works :)