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
So far Clean project works once, restart the Android Studio works once and the last resort is to restart the pc(running windows 10).
Open to suggestions!
Some workarounds can be found here Error: Execution failed for task ':app:clean'. Unable to delete file
When this happens, I use taskkill /im java.exe /f
in cmd (windows 10). It kills all java processes and releases that file. 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.
I switched from OpenJDK
to Oracle JDK
, not sure if this will work with OpenJDK
.
Another workaround is to stop using gradle's daemon: 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.
Manually delete the R.jar file in the file explorer then press rebuild.
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.
Let me know if this works, apparently, Android Studio 4.0.1 has similar problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With