无法更新 Android Studio - 拒绝访问和 java.io.FileNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22646604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't update Android Studio - Access Denied and java.io.FileNotFoundException
提问by Sean Barbeau
I'm trying to update Android Studio from 0.5.1 to 0.5.2 on two separate Windows machines, one with Windows 7 Pro 64-bit and one with Windows 7 Enterprise 64-bit.
我正在尝试在两台独立的 Windows 机器上将 Android Studio 从 0.5.1 更新到 0.5.2,一台使用 Windows 7 Pro 64 位,另一台使用 Windows 7 Enterprise 64 位。
I get the normal update prompt:
我得到正常的更新提示:
...and if I choose "Update and Restart", the patch downloads and the IDE exits, but then I get the following dialog:
...如果我选择“更新并重新启动”,补丁下载和 IDE 退出,但我得到以下对话框:
I can't change any of the "Solution" column entries. If I click "Proceed", I get the following message as shown below (image and text, so its copy/paste/search-friendly):
我无法更改任何“解决方案”列条目。如果我点击“继续”,我会收到如下所示的消息(图像和文本,所以它的复制/粘贴/搜索友好):
Temp. directory: C:\Users\Sean\AppData\Local\Temp\
java.io.FileNotFoundException: C:\Program Files (x86)\Android\android-studio\lib\jsch.agentproxy.usocket-nc.jar (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
at com.intellij.updater.Utils.copyStreamToFile(Utils.java:135)
at com.intellij.updater.CreateAction.doApply(CreateAction.java:52)
at com.intellij.updater.PatchAction.apply(PatchAction.java:140)
at com.intellij.updater.Patch.forEach(Patch.java:198)
at com.intellij.updater.Patch.forEach(Patch.java:248)
at com.intellij.updater.Patch.apply(Patch.java:194)
at com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:86)
at com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:77)
at com.intellij.updater.Runner.doInstallImpl(Runner.java:307)
at com.intellij.updater.Runner.doInstall(Runner.java:268)
at com.intellij.updater.Runner.access##代码##0(Runner.java:18)
at com.intellij.updater.Runner.execute(Runner.java:258)
at com.intellij.updater.SwingUpdaterUI.run(SwingUpdaterUI.java:230)
at java.lang.Thread.run(Thread.java:744)
When I click "Exit", Android Studio re-opens, and tells me that the update is still available.
当我点击“退出”时,Android Studio 会重新打开,并告诉我更新仍然可用。
I've updated Android Studio previously using this same method on both machines without a problem.
我之前在两台机器上使用相同的方法更新了 Android Studio,没有问题。
Since I believe this is some kind of bug with Android Studio specific to newer releases, I've opened Issue 67794on the AOSP issue tracker.
由于我认为这是 Android Studio 特定于较新版本的某种错误,因此我在 AOSP 问题跟踪器上打开了问题 67794。
EDIT
编辑
I was able to update from 0.5.2 to 0.5.3 today on both machines without encountering this issue. I was shown the Windows security prompt for the JetBrains installer as in previous successful updates, and update completed successfully without me having to start Android Studio with elevated permissions. So, seems the problem was something specific to 0.5.1 or 0.5.2 patches.
我今天能够在两台机器上从 0.5.2 更新到 0.5.3 而没有遇到这个问题。我看到了 JetBrains 安装程序的 Windows 安全提示,就像之前成功的更新一样,并且更新成功完成,而我不必以提升的权限启动 Android Studio。因此,问题似乎是 0.5.1 或 0.5.2 补丁所特有的。
EDIT
编辑
I encountered a similar error when trying to update from Android Studio 0.6.0 to 0.6.1:
我在尝试从 Android Studio 0.6.0 更新到 0.6.1 时遇到了类似的错误:
Temp. directory: C:\Users\barbeau\AppData\Local\Temp\
+---------------- A file operation failed. This might be due to a file being locked by another application. Please try closing any application that uses the files being updated then press 'Retry'. +----------------
com.intellij.updater.RetryException: Cannot delete file C:\Program Files (x86)\Android\android-studio1\lib\openapi.jar at com.intellij.updater.BaseUpdateAction.replaceUpdated(BaseUpdateAction.java:40) at com.intellij.updater.UpdateZipAction.doApply(UpdateZipAction.java:199) at com.intellij.updater.PatchAction.apply(PatchAction.java:140) at com.intellij.updater.Patch$3.forEach(Patch.java:198) at com.intellij.updater.Patch.forEach(Patch.java:248) at com.intellij.updater.Patch.apply(Patch.java:194) at com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:86) at com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:77) at com.intellij.updater.Runner.doInstallImpl(Runner.java:307) at com.intellij.updater.Runner.doInstall(Runner.java:268) at com.intellij.updater.Runner.access$000(Runner.java:18) at com.intellij.updater.Runner$2.execute(Runner.java:258) at com.intellij.updater.SwingUpdaterUI$7.run(SwingUpdaterUI.java:230) at java.lang.Thread.run(Thread.java:745)
温度。目录:C:\Users\barbeau\AppData\Local\Temp\
+---------------- 文件操作失败。这可能是由于文件被另一个应用程序锁定。请尝试关闭使用正在更新的文件的任何应用程序,然后按“重试”。+----------------
com.intellij.updater.RetryException:无法删除文件 C:\Program Files (x86)\Android\android-studio1\lib\openapi.jar at com.intellij.updater.BaseUpdateAction.replaceUpdated(BaseUpdateAction.java:40) at com .intellij.updater.UpdateZipAction.doApply(UpdateZipAction.java:199) at com.intellij.updater.PatchAction.apply(PatchAction.java:140) at com.intellij.updater.Patch$3.forEach(Patch.java:198)在 com.intellij.updater.Patch.forEach(Patch.java:248) 在 com.intellij.updater.Patch.apply(Patch.java:194) 在 com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:86 ) 在 com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:77) 在 com.intellij.updater.Runner.doInstallImpl(Runner.java:307) 在 com.intellij.updater.Runner.doInstall(Runner.java: 268) 在 com.intellij.updater。Runner.access$000(Runner.java:18) 在 com.intellij.updater.Runner$2.execute(Runner.java:258) 在 com.intellij.updater.SwingUpdaterUI$7.run(SwingUpdaterUI.java:230) 在 java。 lang.Thread.run(Thread.java:745)
This seems to happen if you try to run the update while the Gradle build process is still running (e.g., right after you start up Android Studio).
如果您在 Gradle 构建过程仍在运行时尝试运行更新(例如,在您启动 Android Studio 之后),则似乎会发生这种情况。
回答by Sean Barbeau
A workaround:
解决方法:
- Close Android Studio.
- Right-click "Android Studio" icon and select "Run as administrator".
- Go to "Help->Check for Update...", and go through the normal update process
- 关闭 Android Studio。
- 右键单击“Android Studio”图标并选择“以管理员身份运行”。
- 进入“Help->Check for Update...”,完成正常的更新过程
I realized after a few failed update attempts from 0.5.1 to 0.5.2 that I was no longer getting the Windows security prompt to allow the JetBrains IntellJ installer to proceed, as I had seen in previous successful updates. I'm not sure what changed from previous updates, but apparently the update process was unsuccessfully trying to access files without proper permissions. Elevating Android Studio to admin through the above process fixed the issue.
在从 0.5.1 到 0.5.2 的几次更新尝试失败后,我意识到我不再收到允许 JetBrains IntellJ 安装程序继续的 Windows 安全提示,正如我在之前的成功更新中看到的那样。我不确定以前的更新有什么变化,但显然更新过程没有成功尝试访问没有适当权限的文件。通过上述过程将 Android Studio 提升为管理员解决了该问题。
As noted in the question above, this issue no longer seems to occur with the update from 0.5.2 to 0.5.3.
如上述问题所述,从 0.5.2 到 0.5.3 的更新似乎不再出现此问题。
EDIT
编辑
To fix the next error I encountered with the Android 0.6.0 to Android 0.6.1 update, I shut down Studio and then restarted it, and let it sit overnight (more by coincidence than design). When I returned to the machine in the morning and ran the update, it succeeded. So, it seems there is some kind of long running process that blocks the update under certain conditions (likely immediately after startup - possibly the Gradle build process?). @Daniel Wilson's answer below should also work for this scenario.
为了修复我在从 Android 0.6.0 到 Android 0.6.1 更新时遇到的下一个错误,我关闭了 Studio,然后重新启动它,让它静置一夜(更多是巧合而不是设计)。当我早上回到机器并运行更新时,它成功了。因此,似乎有某种长时间运行的过程会在某些条件下阻止更新(可能在启动后立即 - 可能是 Gradle 构建过程?)。@Daniel Wilson 下面的回答也适用于这种情况。
回答by Daniel Wilson
This happened with me updating from 0.6.0 to 0.6.1. I had attempted to open AS in admin mode with every other application closed but the update still failed for me. I also tried deleting the Temp folder.
这发生在我从 0.6.0 更新到 0.6.1 时。我试图在关闭所有其他应用程序的情况下以管理员模式打开 AS,但更新对我来说仍然失败。我也尝试删除 Temp 文件夹。
Eventually I noticed in the task manager when everything was closed I still had a sizeable java.exe still running in the background for some reason.
最终我在任务管理器中注意到,当一切都关闭时,由于某种原因,我仍然有一个相当大的 java.exe 仍在后台运行。
What I did was open AS in admin mode, run the update and let it fail, claiming a file is locked / access is denied or something similar. Open the task manager and I noticed 2 java.exe processes running. For me the smaller one (about 200k) was the AS updater utility itself. But if I killed the larger one (about 600k), and hit retry, the update went through without issue.
我所做的是在管理员模式下打开 AS,运行更新并让它失败,声称文件被锁定/访问被拒绝或类似的东西。打开任务管理器,我注意到 2 个 java.exe 进程正在运行。对我来说,较小的(大约 200k)是 AS 更新程序实用程序本身。但是如果我杀死了较大的一个(大约 600k),然后点击重试,更新就会顺利通过。
回答by CJBS
Don't re-install as an Administrator!
不要以管理员身份重新安装!
Whilst running in Admin mode might make the update work, it may also affect the permissions that are set on any files that are added and/or updated, such that future operations in Android studio that use such files will need elevated (Admin) access to work properly.
虽然在管理员模式下运行可能会使更新工作,但它也可能影响对添加和/或更新的任何文件设置的权限,因此 Android studio 中使用此类文件的未来操作将需要提升(管理员)访问权限好好工作。
Doing this will result in many operations not working unless Android Studio has been run in elevated mode.
这样做会导致许多操作无法运行,除非 Android Studio 已在提升模式下运行。
Instead, deal with the file lock, then try again:
相反,处理文件锁,然后重试:
Try killing all instances of java.exe(in Task Manager or Process Explorer), then re-attempt the update, but notrunning as Administrator.
尝试终止 java.exe 的所有实例(在任务管理器或进程资源管理器中),然后重新尝试更新,但不要以管理员身份运行。
Every time I've used Process Explorer(on Windows) to check which application has a lock on one of the files that's blocked an Android Studio update, it's always been Java.
每次我使用Process Explorer(在 Windows 上)检查哪个应用程序锁定了阻止 Android Studio 更新的文件之一时,它总是 Java。
What worked for me (on Windows):
什么对我有用(在 Windows 上):
- Download Process Explorer, and kill all instances of java.exe: in Process Explorer, sort by the Process column and find java.exe instances, press Delon the highlighted row. (On a side note, the file that's blocking the update, for example
jsch.agentproxy.usocket-nc.jar
, can be checked by pressing Ctl+F, and then entering the file name) - If the update process doesn't automatically resume, kill it by dragging the target icon
to the update process' window - this locates it in Process Explorer's Process window - and then press Delto delete the process
- Re-run Android Studio (from start menu), and re-initiate update process.
- 下载Process Explorer,并杀死 java.exe 的所有实例:在 Process Explorer 中,按 Process 列排序并找到 java.exe 实例,按Del突出显示的行。(附带说明,例如
jsch.agentproxy.usocket-nc.jar
,可以通过按Ctl+来检查阻止更新F的文件,然后输入文件名) - 如果更新过程没有自动恢复,通过将目标图标拖到
更新过程的窗口来终止它 - 这将在进程资源管理器的进程窗口中找到它 - 然后按Del删除进程
- 重新运行 Android Studio(从开始菜单),并重新启动更新过程。
回答by Telmo Marques
You might also try to give your user permission to the folder.
您也可以尝试授予您的用户对该文件夹的权限。
- Right click the "android-studio" folder and select "Properties"
- Change to "Security" tab
- Click the "Edit" Button
- Select the group/user from the "Group or user names" list
- You can select/add your username to this list -or-
- Select the group "Users" (or the group where your user is)
- Select the "Full control" checkbox
- Click "Apply" and wait
- 右键单击“android-studio”文件夹并选择“属性”
- 更改为“安全”选项卡
- 单击“编辑”按钮
- 从“组或用户名”列表中选择组/用户
- 您可以选择/添加您的用户名到此列表 - 或 -
- 选择组“用户”(或您的用户所在的组)
- 选择“完全控制”复选框
- 点击“申请”并等待
You're done.
你完成了。
回答by Sabeer Mohammed
Disable antivirus and try update again.... Worked for me.
禁用防病毒软件并再次尝试更新.... 为我工作。
回答by Lou Morda
I had a Java process running in the background on my Windows machine that wasn't showing up in my Task Manager. This will make sure Java gets killed:
我有一个 Java 进程在我的 Windows 机器上的后台运行,但没有显示在我的任务管理器中。这将确保 Java 被杀死:
taskkill /F /IM java.exe
taskkill /F /IM java.exe
回答by gustavoknz
I had this same issue updating from 2.2 to 2.2.1. My solution was getting out the car then getting in again: Restarting Windows
我从 2.2 更新到 2.2.1 时遇到了同样的问题。我的解决方案是下车然后再上车:重新启动 Windows
回答by J. Fdez
I used LockHunter to see what was locking the files. Result: Adb had locked some of them (I was testing the application by wifi in a mobile phone). I killed adb server, restart the Android Studio and I was able to update it.
我使用 LockHunter 来查看锁定文件的原因。结果:Adb 已经锁定了其中一些(我在手机中通过 wifi 测试该应用程序)。我杀死了 adb 服务器,重新启动了 Android Studio,我能够更新它。
Good luck for others!
祝别人好运!
回答by Iar0slav
I had the same problem - update from 0.6.0 to 0.6.1 After pressed button "Update", Android studio restarted and started to update. After this I got "Error message". I pressed "Retry" button - it was unsuccessful. Then I waited about 2 minutes (in my studio after start Gradle is working) and pressed again "Retry" - Done! :) Everything was updated. So in my case the reason of problem was Gradle that works after start of Android studio.
我遇到了同样的问题 - 从 0.6.0 更新到 0.6.1 按下“更新”按钮后,Android studio 重新启动并开始更新。在此之后,我收到了“错误消息”。我按下了“重试”按钮 - 它没有成功。然后我等了大约 2 分钟(在开始 Gradle 工作后在我的工作室中)并再次按下“重试”-完成!:) 一切都更新了。所以在我的情况下,问题的原因是在 Android Studio 启动后工作的 Gradle。
回答by Dmitry Weiner
I've stuck at the same issue, but I solved it by running this script in elevated console: Program Files\Android\android-studio\bin\update_studio.bat
我遇到了同样的问题,但我通过在提升的控制台中运行这个脚本来解决它:Program Files\Android\android-studio\bin\update_studio.bat