Android Studio:R.jar:进程无法访问该文件,因为它正被另一个进程使用

Amo*_*mos 8 android android-studio build.gradle

全新安装 Android Studio 3.6.3(便携式)后。当我尝试构建和运行我的项目时,我不断收到

app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar:进程无法访问该文件,因为它正被另一个进程使用。

不确定它想从我这里得到什么。我以“管理员身份”运行 Android Studio,甚至关闭项目并重新打开它,第一次运行时,第二次出现错误。

我尝试使缓存无效并重新启动,我尝试删除 app/build 下的文件夹,但它似乎又回来了。我错过了什么?

谢谢

更新:

尝试清理项目时,我得到以下信息

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:clean'.
> Unable to delete directory 'C:\Users\name\Downloads\portable\android-studio\projects\appm\app\build'
    Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.
    - C:\Users\name\Downloads\portable\android-studio\projects\appm\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar
    - C:\Users\name\Downloads\portable\android-studio\projects\appm\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug
    - C:\Users\name\Downloads\portable\android-studio\projects\appm\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar
    - C:\Users\name\Downloads\portable\android-studio\projects\appm\app\build\intermediates
Run Code Online (Sandbox Code Playgroud)

如果我等了几分钟,例如更新这个问题所花的时间,那么它又可以工作了……

更新: 更新到Android Studio 4,出现同样问题。

Fan*_*dez 29

我在处理 Jet Compose 项目时在 Android Studio Arctic Fox 上遇到了同样的问题。

我只是更改了运行配置,构建错误就得到了解决。 在此输入图像描述

更改DefaultPreviewapp,问题就解决了。


dre*_*oso 6

尝试

taskkill /im java.exe /f 
Run Code Online (Sandbox Code Playgroud)

在 cmd (Windows 10)


Abe*_*rad 5

这是 AS 的内部错误,我将其报告为错误,您可以在此处跟进

https://issuetracker.google.com/issues/167701947


小智 5

从任务管理器中终止“ OpenJDK 平台二进制文件”进程对我来说非常有效。

感谢阿贝德·穆拉德(Abed Murad),我在他的链接上看到了这一点。(我还没有投票权——我的错!)

这是 AS 的内部错误,我将其报告为错误,您可以在此处跟进 https://issuetracker.google.com/issues/167701947

我曾经尝试删除...\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug上的文件R.jar,当它被锁定时,我必须关闭 Android Studio,然后在重新打开 Android Studio 之前删除R.jar 。它(杀死“OpenJDK Platform 二进制文件”)是最好的解决方案吗?我不知道,但这就是我现在得到的。一旦我有了更好的,我会更新它。伙计们,祝你好运!