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

后端 未结 30 1178
感动是毒
感动是毒 2020-11-29 17:19

I\'m trying to rebuild my Android Studio Gradle project (containing mostly Kotlin code), but it started to throw an UnableToDeleteFileException during the clean

相关标签:
30条回答
  • 2020-11-29 18:11

    I had this problem in Android Studio 2.3.

    I simply restarted Android Studio and after that I could clean without complaints.

    0 讨论(0)
  • 2020-11-29 18:15

    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.

    0 讨论(0)
  • 2020-11-29 18:15

    Deleting the directory intermediates is a quick fix for problem.

    The directory will be rebuilt when the project is rebuilt.

    0 讨论(0)
  • 2020-11-29 18:15

    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.

    0 讨论(0)
  • 2020-11-29 18:16

    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.

    0 讨论(0)
  • 2020-11-29 18:16

    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.

    0 讨论(0)
提交回复
热议问题