简体   繁体   English

当我在 Android Studio 3.6.1 中运行项目时,为什么会出现“文件被另一个进程使用”错误?

[英]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 setting org.gradle.daemon=false in the project's gradle.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.

相关问题 Android Studio:为什么我只运行最简单的代码就会出错 - Android studio: why do I get errors when I just run the simplest code 为什么我在 android 工作室编写代码时会出错并且无法运行应用程序 - why i get errors when i wright my code in android studio and cannot run app 为什么在我创建新项目时android studio中出现这个错误? - why this errors in android studio occurred when i create new project? Android Studio 我不断收到 Gradle 错误“该进程无法访问该文件,因为它正被另一个进程使用” - Android Studio I keep getting Gradle error "The process cannot access the file because it is being used by another process" 当我使用自动完成挂钩框架布局时,Android Studio 3.6.1 错误 - Android Studio 3.6.1 error when i hook frame layout with autocomplete 在 Android Studio(3.6.1) 中创建空活动时未解决的参考 - Unresolved reference when I create Empty Activity in Android Studio(3.6.1) 为什么在 Kotlin 在 Android Studio 中使用 async{} 后,我得到 LiveData 的 null 值? - Why do I get null value of LiveData after I have used async{} in Android Studio with Kotlin? 为什么在导入领域数据库时我无法在android studio上运行我的项目? - why i can't run my project on android studio when i import realm database? 将 Android Studio 3.0.2 更新到 3.6.1 后丢失了我的项目文件夹,如何恢复? - Lost my project folder after updating Android Studio 3.0.2 to 3.6.1, how can I recover it? 为什么在Android Studio中这样显示我的项目? 我如何回到项目结构? - why is my project being shown like this in android studio? How do I get back to the project structure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM