I\'m trying to rebuild my Android Studio Gradle project (containing mostly Kotlin code), but it started to throw an UnableToDeleteFileException
during the clean
I had this problem in Android Studio 2.3.
I simply restarted Android Studio and after that I could clean without complaints.
After I posted a bug report to the Kotlin bug tracker, I was notified of Issue 61300 on the AOSP tracker. That seems to be the cause. Since there's nothing I can do at the moment, I'll mark this question as answered, and I'll update the answer if the bug is fixed.
In the meantime, if you're running Windows, I believe I've found a workaround. You'll need to download LockHunter (at your own risk of course), then add the following to your module's gradle.build
file, replacing the lockhunter
variable with your path to LockHunter.exe:
task clean(type: Exec) {
ext.lockhunter = '\"C:\\LockHunter.exe\"'
def buildDir = file(new File("build"))
commandLine 'cmd', "$lockhunter", '/delete', '/silent', buildDir
}
This causes LockHunter to forcefully and silently unlock and delete the build files when the app:clean task runs.
Deleting the directory intermediates
is a quick fix for problem.
The directory will be rebuilt when the project is rebuilt.
if you're still having issues then update to the latest version of Android Studio(its 2.1 as of now), might be it was a bug with older version of Android Studio. Its resolved for me now.
Find programs who used app/build/outputs/apk folder, then just delete folder.
I think Android Studio have to delete old apk folder before rebuilding.
Another application that can be using the resources is apparently Android Studio's Kotlin REPL. I closed that, and then I could build again no problem.