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
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.
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.
Open your terminal and reset adb:
adb kill-server
adb start-server
@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:
It should work for my case.
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.)
This is how I solved the same problem: