Reputation: 701
I can import a sample app project, try to build it and I keep getting this error. Not always the same file but a new temp file each time. I've tried several different samples. I've been programming for 30+ years and feel completely clueless. Only clue seems to be the Windows Task Manager shows 99% to 100% CPU usage when it gives the error and ends the build.
Upvotes: 70
Views: 70064
Reputation: 320
Close file explorer by clicking on close window option and then run the program
Upvotes: 0
Reputation: 903
When this happens to me on Windows 8, I open the task manager
and simply kill all the instances of "openjdk platform binary"
edit Feb 2024: from powershell I now use this command to kill openjdk (java):
Get-Process -Name "java" -ErrorAction SilentlyContinue | Stop-Process -Force
Upvotes: 45
Reputation: 1463
Restarting Android Studio with cache invalidation doesn't helped.
The file that caused the problem is being used by the emulator and if you are using an external emulator (BlueStacks) like me, restarting Android Studio will not help. I restarted the emulator and the problem went away.
Upvotes: 0
Reputation: 195
In my case, deleting the /.gradle/ directory and rebuilding resolved the issue.
Upvotes: 0
Reputation: 218
Above suggested solutions may fixed this error but they are time consuming so the best solution to fix this problem is open command prompt and run the following command.
taskkill /im java.exe /f
Upvotes: 1
Reputation: 564
Terminating "OpenJDK platform binary" from Task Manager then deleting src/build and finally rebuilding the project should make it work.
Upvotes: 1
Reputation: 37051
Had the same on Windows 10, it was resolved by closing all "Command Prompt" (cmd) windows 🤷♂️
Upvotes: 0
Reputation: 224
Choose app
instead of DefaultPreview
. Now if you build, then you should not see this issue.
Upvotes: 8
Reputation: 208
For those which are still searching for this answer in 2022, remove the build folder and rebuild...
Upvotes: 0
Reputation: 22867
Invalidating the IDE cache is NOT enough.
app\build
we should first stop locking process - OpenJDK Platform binary.app\build
Context: Using Coroutines in Android Instrumented Test.
GL
Upvotes: 4
Reputation: 28773
Restart of Android Studio with cache invalidation doesn't help.
As others said, we should delete a <module>\build
folder. Because a file is locked by OpenJDK Platform binary
, we should stop this process in Task Manager (or unlock the file via LockHinter).
Upvotes: 2
Reputation: 455
try to delete the file (the folder inside builder message) the message will contain process name ( i dont remember the name) find the prcess in task manager and stop it
Upvotes: 1
Reputation: 5488
If the error is recurring, you can try a file leak detector to determine what part of the gradle process is holding your files. As suggested here,
Download file leak detector
Check with resmon what process is holding on to the file
Depending on where the file is locked, do the following:
Android Studio: In studio, go to Help
→ Edit custom VM options
and add the following line:
-javaagent:path/to/file-leak-detector.jar=http=19999
Gradle: Add to your gradle.properties file the following line:
org.gradle.jvmargs=-javaagent:path/to/file-leak-detector.jar=http=19999
When the problem occurs again, open localhost:19999
in your browser and search for locked files.
In my case, I found out that a file was held by AspectJ compiler/weaver (ajc):
#115 C:\Users\me\StudioProjects\myapp\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar by thread:Execution worker for ':' Thread 3 on Mon Oct 19 18:41:06 BST 2020
at java.util.zip.ZipFile.<init>(ZipFile.java:156)
...
at org.aspectj.tools.ajc.Main$run.call(Unknown Source)
I was running it directly from Gradle:
new Main().run(args, handler)
I don't know if it's possible to make ajc release the files. So I resolved my issue by running it in a separate process. I added a new configuration to get aspectjtools onto classpath:
val weaving: Configuration by configurations.creating
dependencies {
weaving("org.aspectj:aspectjtools:1.9.6")
}
And instead of the above code, I did:
javaexec {
classpath = weaving
main = "org.aspectj.tools.ajc.Main"
args = arguments
}
Upvotes: 1
Reputation: 124
I had 2 jre's installed when I installed android studio. Uninstall the one that you find from control panel and that is located something like c:\program files\java etc.
On the next opening of android studio 4.0 + it will fallback to "C:\Program Files\Android\Android Studio\jre" and the process lockdown after each succesfull build will stop
Upvotes: 0
Reputation: 9
It happened me many times while building or Cleaning the Project The solution is simple:
Upvotes: -1
Reputation: 678
Invalidate Caches / Restart doesn't work all the time and it's not the better idea to close the whole Android Studio just we couldn't figure out what process was using it.
Please follow the below steps to figure out which process is using your file.
You can use the Resource Monitor for this which comes built-in with Windows 7, 8, and 10.
When you've found the handle, you can identify the process by looking at the Image and/or PID column.
You can then try to close the application as you normally would, or, if that's not possible, just right-click the handle and kill the process directly from there.
Ref : https://superuser.com/questions/117902/find-out-which-process-is-locking-a-file-or-folder-in-windows
Upvotes: 1
Reputation: 111
I had the same problem and in my case it is due to multiple Java Run times (JRE's). Try switching between JRE's in android studio or use only one Java runtime.
Hope it fix the problem. Happy Coding..
Upvotes: 1
Reputation: 1655
I have the same issue's.Even I tried all the solution mentioned here it didn't work.Even I can't delete the signin file as running android studio administrative mode.I see a notification at bottom right side of the IDE update gradle pluggin.So update gradle pluggin usually worked for me
Upvotes: 2
Reputation: 14908
Do This
File -> Invalidate Caches / Restart.. -> Invalidate/ Restart
Upvotes: 73