Updating to Android Studio 2.3 - "Cannot delete" file ErrorAndroid Studio can be a challenging IDE to get going with. Customizing settings, connecting to version control systems, configuring the interface, updating... There are enough sources of headaches to thoroughly demoralize the new developers. Recently, while updating to a new version of Android Studio (2.3) in Windows 10, I came across a very stubborn error that looked like this in the console window:
Cannot delete file C:\Program Files\Android\Android Studio1\gradle\m2repository\com\android\tools\layoutlib\layoutlib-api\24.5.0\layoutlib-api-24.5.0.jar
Unfortunately, the error always appears in the last stage of the update as a patch is being applied. It appears that this stage requires API level 24.5 libraries be deleted and replaced with API 25.2 and 25.3 libraries. Attempting to delete the .jar file [layoutlib-api-24.5.0.jar] manually results in an error saying the file is opened by the Java SE process or some similar process. It means the file is locked and can't be manually deleted.
However, if we could shutdown Java SE process or whatever the offending process, we can unlock the file. This can be achieved by closing the Java SE using the Task Manager or other command-line tool. To use Task Manager in Windows 10, press the Ctrl Alt and Del keys all at the same time or Crtl Shift and Esc keys simultaneously. This opens the Task Manager. Look for the offending process. Right-click on it and select the "End Task" popup menu as shown below.
You can now launch Android Studio and select the Help-> Check for Updates menu to check and download updates.