Android Studio: 后台任务无限期运行

在更新了 Android SDK 之后,我启动了 Android Studio,现在它的显示后台任务连续运行消息

更新索引: 扫描文件到索引。

在这种模式下,它几乎是悬挂,我不能在它的工作。无法找到停止后台任务的方法。Android Studio 的重启也不起作用。

52085 次浏览

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.

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.

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

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.

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.

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).

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 File > Project Structure

Change it due to android studio reference

Update Gradle Reference

reference: https://developer.android.com/studio/releases/gradle-plugin.html

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

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 :)