Android Studio is “Borked” — my checklist for fixing build issues
/This article was originally posted to Medium on Jun 19, 2018 · 2 min read
Photo by Simson Petrol on Unsplash
I recently encountered an issue, where despite my project being configured correctly (and building on my colleagues machine), I couldn’t get it working in my local environment.
I tried multiple clean builds, cloning a fresh repo, rebooting my machine, upgrading all my dependency versions, and just about everything else I could think of to solve my issue.
My issue was: the compiler would not recognize any imports from the Android Test Support libraries. I would get the error “Cannot find Symbol” for ActivityTestRule (and other essential classes). Android Studio can get into this “borked” state for a variety of reasons though.
I ended needing to clear all my system caches (I used a great script from Sebastiano Poggi), which eventually fixed my issue.
I am sharing my troubleshooting checklist in case you encounter something similar with Android Studio. Keep in mind the further down in the list you go, the more destructive the action.
- Make sure you have updated Android Studio, and the Gradle version in your project to the most current stable version. 
- Backup any special environment variables or Gradle property files which your project needs/expects 
- Clone a fresh instance of your project to a new directory 
- Reboot Your Computer. 
- Restart AS using the “Invalidate Cache” option 
 Access this in AS from: File\”Invalidate Caches and Restart…”
- Clear Project Cache — there are 2 hidden directories in the main level of your project (after your first compile). Hint: on Mac type “cmd-shift-.” if you don’t see these files in your Finder window. 
 Delete both the directories:
 <project home>/.idea
 <project home>/.gradle
- Delete the system Gradle cache: 
 Delete this folder:
 /<userhome>/.gradle/caches
- Refresh your project dependencies manually during build 
 Use a gradle command similar to :
 $gradlew assemble — — refresh-dependencies
- If none of these steps fix your problem, use the “Deep Clean” method . Execute this script: 
 Warning, this is the last step for a reason. If you run this script, it will reset all of your Android Studio caches, and will make your future builds slower (until the caches recover).
 https://github.com/rock3r/deep-clean
 Edit: there has been an update to this script to v1.5 since this article was released!
It can be frustrating to experience Android Studio build issues. I hope these steps will help you recover quickly.

