[英]Why do I get “file is used by another process” errors when I run the project within Android Studio 3.6.1?
I encounter this error after running the second time the project.第二次运行该项目后,我遇到了这个错误。
...\\app\\build\\intermediates\\compile_and_runtime_not_namespaced_r_class_jar\\debug\\R.jar: The process cannot access the file because it is being used by another process
...\\app\\build\\intermediates\\compile_and_runtime_not_namespaced_r_class_jar\\debug\\R.jar:进程无法访问该文件,因为它正被另一个进程使用
So far Clean project works once, restart the Android Studio works once and the last resort is to restart the pc(running windows 10).到目前为止Clean 项目工作一次,重新启动 Android Studio 工作一次,最后的办法是重新启动电脑(运行 Windows 10)。
Open to suggestions!打开建议!
Some workarounds can be found here Error: Execution failed for task ':app:clean'.可以在此处找到一些解决方法错误:任务 ':app:clean' 执行失败。 Unable to delete file
无法删除文件
When this happens, I use taskkill /im java.exe /f
in cmd (windows 10).发生这种情况时,我在 cmd(Windows 10)中使用
taskkill /im java.exe /f
。 It kills all java processes and releases that file.它会杀死所有 Java 进程并释放该文件。 This is not the best solution, but it's way faster to click on
.bat
file instead of invalidating the whole cache|restart|clean|etc.这不是最好的解决方案,但单击
.bat
文件比使整个缓存无效|重新启动|清理|等更快。
I switched from OpenJDK
to Oracle JDK
, not sure if this will work with OpenJDK
.我从
OpenJDK
切换到Oracle JDK
,不确定这是否适用于OpenJDK
。
Another workaround is to stop using gradle's daemon: https://docs.gradle.org/current/userguide/gradle_daemon.html另一种解决方法是停止使用 gradle 的守护进程: https ://docs.gradle.org/current/userguide/gradle_daemon.html
Disabling the Daemon
禁用守护进程
You can disable the Daemon for a specific build using the
--no-daemon
argument, or disable it for a specific project by explicitly settingorg.gradle.daemon=false
in the project'sgradle.properties
file.您可以使用
--no-daemon
参数为特定构建禁用--no-daemon
,或者通过在项目的gradle.properties
文件中显式设置org.gradle.daemon=false
为特定项目禁用它。
Manually delete the R.jar file in the file explorer then press rebuild.在文件资源管理器中手动删除 R.jar 文件,然后按重建。
The system ( Android Studio Gradle or another debug process ) might be using it automatically even when you haven't asked it to build and the (automatic) process blocks your second build process from using it.系统( Android Studio Gradle 或其他调试过程)可能会自动使用它,即使您没有要求它进行构建并且(自动)过程阻止您的第二个构建过程使用它。
Let me know if this works, apparently, Android Studio 4.0.1 has similar problems.让我知道这是否有效,显然,Android Studio 4.0.1 也有类似的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.