Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: R.jar: The process cannot access the file because it is being used by another process

After a new installation of Android Studio 3.6.3 (portable). When I try to build and run my project, I keep getting

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.

Not sure what it wants from me. I run Android Studio "as administrator" and even closing the project and reopening it, the first time it runs, the second time I get the error.

I tried invalidate caches and restart, I tried deleting folders under app/build but it seems to come back. What am I missing?

Thanks

Update:

When trying to clean the project, I get the following

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

If I wait for several minutes, for example, the time it took me to update this question, then it works again...

update: Updated to Android Studio 4 and the same problem occurs.

like image 571
Amos Avatar asked May 29 '20 09:05

Amos


2 Answers

Try

taskkill /im java.exe /f 

in cmd (windows 10)

like image 144
dreinoso Avatar answered Nov 20 '22 14:11

dreinoso


I encountered the same problem but on Android Studio Arctic Fox while working on a Jet Compose project.

I simply changed the run configuration and the build error was resolved. enter image description here

Change DefaultPreview to app and the issue is resolved.

like image 24
Tonnie Avatar answered Nov 20 '22 15:11

Tonnie