Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Execution failed for task ':app:clean'. Unable to delete file

I killed all the java TM processes in the task manager and it let me to rebuild


If you are using Android Studio 2.0 Beta, this issue might appear (more likely if you are working on NTFS filesystem) and it seems like the "Instant Run" is the culprit. Search for "Instant Run" in settings and uncheck the box.

I have filed an issue on the bug tracker.


Try File -> Invalidate Caches and Restart

This worked for me


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.