If you just want to know the conclusion, please go to the last section. Thanks.
Usually when building project fails, some common tricks you could try:
- Build -> Clean Project
- Check Build Variants
- Restart Android Studio (as you mentioned)
But to be more specific to your problem - when Android Studio could not find the APK file on disk. It means that Android Studio has actually successfully built the project, and also generated the APK, however, for some reason, Android Studio is not able to find the file.
In this case, please check the printed directory according to the log. It's helpful.
For example:
With Android Studio 2.0 Preview (build 143.2443734).
- Checkout to a specific commit (so that it's detached from head): git checkout [commit_hash]
- Run project
- Android Studio tells: The APK file /Users/MyApplicationName/app/build/outputs/apk/app-debug-HEAD.apk does not exist on disk
- Go to the directory, there is a file actually named: app-debug-(HEAD.apk (with an extra parenthesis)
Run git branch
*(HEAD detached at 1a2bfff)
So here you could see, due to my gradle build script's mistake, file naming is somehow wrong.
Above example is just one scenario which could lead to the same issue, but not necessary to be the same root cause as yours.
As a result, I strongly recommend you to check the directory (to find the difference), and check your build.gradle script (you may change the apk name there, something like below):
applicationVariants.all { variant ->
variant.outputs.each { output ->
def newFileName = "whatever you want to name it";
def apk = output.outputFile;
output.outputFile = new File(apk.parentFile, newFileName);
}
}