Android Studio hangs / Freezes when project build fails

那年仲夏 提交于 2019-12-03 10:32:31

问题


I am experiencing a very wired problem since this evening.

If I have any errors in my android project, and build is failed, then my Android studio gets frozen / stuck. I cant do anything but kill the Android studio application. Even if I open the same project next time, gradle will try to build and freezes again. [Please find attached screen shot]

Only solution I could find is .... I have to find what exactly cause the "build fail" and I will have to resolve the issue using some other editor, and then my android studio will start working.

Thing is it was working without any issues till this evening; and suddenly broken down. Any one else having the same issue ??

-n


回答1:


If you are using Android Studio v1.2.1.1 or newer and you are using Macbook, I've recently seen that if your device is connected to your laptop (by usb have no idea about over the wifi) and you sleep your laptop then login again, Android Studio hang. Therefore, you need to unplug usb cable then you should see Android studio is happy and then reconnect your usb cable.




回答2:


Open your terminal and reset adb:

adb kill-server
adb start-server



回答3:


This is how I solved the same problem:

  • Go to your project directory using your terminal
  • run ./gradlew (or gradlew.bat) assembleDebug
  • Fix the problems reported by gradle
  • Restart android studio and the problem is gone



回答4:


Based on barbarian's answer I did this on my Mac:

start a terminal
chmod +x gradlew
./gradlew
./gradlew build

This last step showed an error in my xml file, indicating that I used unescaped single quotes. Fixing that solved the hangup.




回答5:


Well, I uninstalled android studio and installed it again, and now the problem has gone away. I still wonder how in the world it broke in the first place.

In case some one else is facing the same issue, try reinstalling your studio. In case if you are using Mac osx refer How to completely uninstall Android Studio? to uninstall Android studio properly; Because only deleting App will not completely uninstall it.




回答6:


In my case the same thing happened, after I had added image-resources with dashes in the filename.

I manually deleted them, renamed them, and added them with underscores in the name, and Android Studio worked normally again.

(I am not sure the dashes were the reason, why should they, but doing the above fixed it.)




回答7:


@Hesam's answer doesn't work for me. Using OSX and AS 1.2.1.1, my building stuck in 'Scanning files to index' and I cannot solve it even after restarted my Macbook. Below work for me:

  1. Shut down Android Studio (force to kill or just unplug the usb you will be good to go)
  2. Go to the directory of AndroidStudioProjects and move the application directory out to some other location (outside AndroidStudioProjects).
  3. Restart the android studio, now you will be shown the screen asking you whether you want to start a new project or open an old one.
  4. Again paste the folder you have cut and kept aside in step 2 back to AndroidStudioProjects directory.
  5. In the android studio prompt, select open existing project and select the directory you have now just pasted to AndroidStudioProjects.

It should work for my case.



来源:https://stackoverflow.com/questions/27402804/android-studio-hangs-freezes-when-project-build-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!