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

后端 未结 30 1227
感动是毒
感动是毒 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: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.

提交回复
热议问题