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

旧城冷巷雨未停 提交于 2019-11-27 06:14:44

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.

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

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.

Biswajit Karmakar

Clean project from Terminal using this command gradlew clean.

DeaMon1

Deleting the directory intermediates is a quick fix for problem.

The directory will be rebuilt when the project is rebuilt.

I was facing same issue on Android Studio 2.2 preview 1, solution by @AndresSuarez was correct but for some reasons I couldn't find JAVA TM process in my task manager. So I tried the following solution and it worked -

Open command prompt and type TASKKILL /F /IM java.exe. This will kill all JAVA TM processes automatically. Now re-compile the app again, it will work.

Additionally, you can create a .bat file, add the above code in it and run it every time you face the issue.

I had this problem in Android Studio 2.3.

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

For me it helps when I Exit Android Studio, click one more time Clean Project (it appears the same error) and next click Make Project - after that of course Run 'app' button in Android Studio.

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.

Some times intermediates creates problem so delete it and Rebuild project

OR

simply run cmd command - > gradlew clean

in your project folder in work space (its work for me)

I had the same problem and this worked for me:

  1. close Android Studio.
  2. delete intermediates directory (as long as Android Studio is opened, this directory can't be deleted)
  3. open Android Studio again
Dmitry Smolyaninov

For me, this happened because of an active debugging process. So, before cleaning or rebuilding, make sure to kill all active processes. To nail down the success, execute Invalidate Caches/Restart.

I solved this one in my ubuntu like this.

  1. Check for the processes running in your system(Ubuntu) like in task manager in windows.

    Ubuntu terminal command to list out all processes running ----> "gnome-system-monitor"

  2. Terminate or end the JAVA and ANDROID processes in the list.

  3. Again start the studio and import project.

Its works for me without any problems. Hope this helps...

I thought this is the problem with the process that are already created and Duplicated.

The solution is quite easy.

This is one of the solution which worked for me.

It might be possible that your project's app/build/outputs/apk folder is opened.

so just close this folder and rebuild your project. and it will be solved.

As suggested in the bug report, uncommenting the line

idea.jars.nocopy=false

in the idea.properties file has solved the issue for me.

Note that this needs to be done every time Android Studio updates.

For me, the culprit is adb holding onto the apk file since I utilise it to install and start the application on my physical device through command line.

So simply:

Task Manager > End process adb.exe

And then the file is free to be deleted and the project may be cleaned

If you are testing with a local backend (java servlet on local google app engine) the running process blocks some files. So you are not able to live deploy. So in this case you can solve this by stopping the local backend before starting clean or build. You find the option under "Run -> Stop backend".

I had the same error, tried multiple ways but the solution worked for me was to delete build folders from /android and /android/app directories.

run react-native run-android worked for me.

In Android Studio 3.0, I had the same issue. This fixed it:

  1. Close Studio
  2. Delete projectRoot/build/ and projectRoot/app/build/
  3. Restart Studio
Rick

I solved with command:

taskkill /F /IM java.exe

and then:

gradle assembleDebug 

This issue appeared to me in android studio 2.0 stable channel and the solution was due to a problem happened while updating my android studio i solved this by installing a fresh android studio. after deleting all old files for the old installation. and to keep the very nice feature of Instant Run

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.

Cleaning the project in Android studio and running again fixed the issue. May be do "Make Project" as well.

I had the same problem and I solved it by moving project folder into ext4 partition

I solved it by global searching the missing directory in the project. then delete any files containing that keyword. it can clean successfully after I remove all the build and .externalNativeBuild directories manually.

I am using Android Studio 3.0 Beta 7. Clean Project, Invalidate caches, restart studio did not work but Updating Kotlin version to 1.1.51 and restart studio solved this issue for me.

I had the same issue after moving my project from D: to G: drive but disk checking solved my issue

I used chkdsk /f /r /x G: ** here some command line switches were used:**

/F Fixes errors on the disk

/R Locates bad sectors and recovers readable information (implies /F)

/X Forces the volume to dismount first if necessary (implies /F) (important)

Note: /X is important because it will dismount the drive and you can manually delete the build directory of your project,

now rebuild the project

My Solution for this was very very simple ( if you are using Windows). 1- Close Android Studio. 2- Run Android Studio as Administrator. 3- That is it.

the thing that worked for me was to close visual studio code and open it again ... i guess the apk was folder was opened somewhere in code .... so just try it might work for you as well

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!