Android Studio I keep getting Gradle error “The process cannot access the file because it is being used by another process”

后端 未结 11 1355
伪装坚强ぢ
伪装坚强ぢ 2020-12-16 10:12

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 sampl

相关标签:
11条回答
  • 2020-12-16 10:28

    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.

    1. Open Resource Monitor, which can be found By searching for Resource Monitor or resmon.exe in the start menu, or As a button on the Performance tab in your Task Manager
    2. Go to the CPU tab
    3. Use the search field in the Associated Handles section

    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

    0 讨论(0)
  • 2020-12-16 10:29

    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..

    enter image description here

    0 讨论(0)
  • 2020-12-16 10:30

    It happened me many times while building or Cleaning the Project The solution is simple:

    1. Open the Specific Directory
    2. Close the Android Studio
    3. Delete the particular Directory
    4. Now run the Android Studio
    0 讨论(0)
  • 2020-12-16 10:30

    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,

    1. Download file leak detector

    2. Check with resmon what process is holding on to the file

    3. Depending on where the file is locked, do the following:

      • Android Studio: In studio, go to HelpEdit 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
        
    4. 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
    }
    
    0 讨论(0)
  • 2020-12-16 10:41

    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

    0 讨论(0)
  • 2020-12-16 10:42

    When this happens to me on Windows 8, I open the task manager

    and simply kill all the instances of "openjdk platform binary"

    0 讨论(0)
提交回复
热议问题