"Could not delete path" on various folders under "build/generated/source/r"

时间:2018-09-18 19:31:27

标签: java android android-studio android-gradle android-build

For the last few months, I have been getting a sporadic, moving, build-time error “Could not delete path” for a folder in the “build/generated/source/r” folder (the exact folder changes). For example:

enter image description here

If I look at the build folder, I can see that

  • Offending folder is present
  • Offending folder is the first folder under the "r" folder
  • Offending folder is empty
  • Subsequent folders are present, and each contains 1 file: the R.file

For example, if the offending folder is “localbroadcastmanager”:

enter image description here

If I try to build again (Build, Make Project), it will successfully delete the offending folder, and several subsequent folders. And then it will (often) encounter the problem for another folder “later” in the file tree.

If I keep trying to build, it will eventually succeed, sometimes after failing ~20 times.

If I manually delete the “build” folder (either in Android Studio, or via File Explorer) the next build process completes without error. Unfortunately, that is a lot of overhead to incur for each build iteration.

My theory is that the gradle build task is recursively deleting the structure under “source/r”. For each folder, the contents of the folder (R.java) are deleted, and then the folder is deleted. Sometimes the folder deletion is initiated before the file deletion has completed, resulting in a lock on the folder.

System details

  • Windows 10
  • Android Studio 3.1.4
  • Anti-virus: Trend Micro Internet Security 12.0

Things I've tried

  • Android Studio
    • Build, Clean Project
    • Invalidate Caches/Restart
    • Delete "build" folder (works, but is not a tenable solution)
  • Anti-virus (Trend Micro)
    • Added "build" folder to "Exception List"
    • Disabled anti-virus
  • Used Resource Monitor and Process Explorer to see if other process has lock on folder
  • Tried suggestions posted here: StackOverflow post: Could not delete path

2 个答案:

答案 0 :(得分:0)

我知道了。我使用备份工具(Genie Timeline Home 2017)。该工具的工作原理是持续监视存储集中指定的文件,并定期(每6个小时)对最近的更改进行快照。

显然,在删除文件夹的内容然后删除文件夹时,监视存在某种间歇性的同步问题。从存储集中删除“ build”文件夹即可解决问题。

我已经使用Genie Timeline多年了,并且仅在最近几个月中一直遇到此问题。不确定发生了什么。

答案 1 :(得分:0)

我一次又一次面临着同样的问题。每次删除Build文件夹时,都可以成功构建应用程序,下一次显示相同的问题。所以我做了一些对我有用的事情

  1. 从您的应用目录中删除“构建”文件夹
  2. 开始构建->制作项目(ctrl + F9)
  3. Build-> Clean&Build-> Rebuild项目创建新的Build Folder

现在必须成功构建应用程序。如果没有,请执行步骤4

  1. 文件->使现金无效并重新启动。这将解决您的问题
相关问题