Amos
Amos

Reputation: 535

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.

Upvotes: 31

Views: 21205

Answers (12)

shabas 001
shabas 001

Reputation: 411

if you are using react native and you encounter this error follow this method

  1. close the IDE (e.g VsCode)
  2. reopen your project back
  3. locate the file and delete it Navigate to the directory \YOUR-APP\android\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\.
  4. delete the (R.jar ) Thats all congratulation

Upvotes: 0

Mahmoud Mousa Hamad
Mahmoud Mousa Hamad

Reputation: 707

I was working on a react native project and was using AS to debug my native android code. I had both VS Code AND AS open at the same time and I got this error in AS. When I closed VS Code and ran taskkill /im java.exe /f in CMD (thanks @dreinoso), I was able to run the app in AS.

Doing this solved my issue.

Upvotes: 0

Vadym Matus
Vadym Matus

Reputation: 61

Migration from kapt to ksp solved this error for me.

Upvotes: 0

Takeshi
Takeshi

Reputation: 19

did all the solutions and nothing work for me. i noticed that i can apply change Ctrl + F10 on java file, but when i change something in XML files this error occurs. All I can do is shut down Android Studio, manually delete R.jar, then reopen Android Studio, which turned out to be really annoying

not sure what went wrong in here

Upvotes: 0

small.dream
small.dream

Reputation: 81

stop running app ,then open any of the xml layout ,wait it load complete, it works.

Upvotes: 4

Obaidi
Obaidi

Reputation: 1

I had the same issue all I did remove R.jar and re build my project.

Upvotes: 0

Tonnie
Tonnie

Reputation: 8152

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.

Upvotes: 29

Patel Divyesh
Patel Divyesh

Reputation: 11

Invalidate cache and restart solved my problem

Upvotes: -1

Gabriel Carneiro
Gabriel Carneiro

Reputation: 59

Killing the "OpenJDK Platform binary" process from Task manager worked great for me.

Thanks to Abed Murad, which I saw on his link. (I have no reputation to cast a vote yet - my bad!)

It's an internal bug in AS, I reported it as a bug, you can follow up here https://issuetracker.google.com/issues/167701947

I used to try to delete the file R.jar on ...\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug and when it's locked, I had to close Android Studio then delete R.jar before reopening the Android Studio.

Is it (killing the "OpenJDK Platform binary") the best solution? I don't know, however, it's what I got for now. Once I get a better one, I'll update it.
Luck there guys!

Upvotes: 5

abd3lraouf
abd3lraouf

Reputation: 1658

Try removiong all *.xml files from %USERPROFILE%\AppData\Roaming\Google\AndroidStudioPreview2020.3\workspace

I figured it out from this google issue.

Upvotes: 1

dreinoso
dreinoso

Reputation: 1689

Try

taskkill /im java.exe /f 

in cmd (windows 10)

Upvotes: 52

Abed Murad
Abed Murad

Reputation: 342

It's an internal bug in AS, I reported it as a bug, you can follow up here

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

Upvotes: 5

Related Questions