Can't update Android Studio - Access Denied and java.io.FileNotFoundException - android

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.
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:
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$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:744)
When I click "Exit", Android Studio re-opens, and tells me that the update is still available.
I've updated Android Studio previously using this same method on both machines without a problem.
Since I believe this is some kind of bug with Android Studio specific to newer releases, I've opened Issue 67794 on the AOSP issue tracker.
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.
EDIT
I encountered a similar error when trying to update from Android Studio 0.6.0 to 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)
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).

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
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.
As noted in the question above, this issue no longer seems to occur with the update from 0.5.2 to 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.

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

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.
Doing this will result in many operations not working unless Android Studio has been run in elevated mode.
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 not running as Administrator.
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.
What worked for me (on 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 Del on 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 Del to delete the process
Re-run Android Studio (from start menu), and re-initiate update process.

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
You're done.

Disable antivirus and try update again.... Worked for me.

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:
taskkill /F /IM java.exe

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

I solved a similar problem while updating Android Studio by just closing all other running applications, such as Firefox and restarted the update process.
It seems that a file is just by another program and it cannot be accessed by Android Studio.
Another way to solve this problem is to delete all files in the corresponding folder, such as: User/AppData/Local/Temp

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.

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.
Good luck for others!

I had this same issue updating from 2.2 to 2.2.1.
My solution was restarting Windows

Related

Android studio isn't opening [duplicate]

Every time I run Android Studio, this loading screen pops up, but Android Studio stays here and doesn't load. It's like this following picture except that the loading bar is loaded all the way but stuck there. I am running Windows 10.
I have tried many things, including setting the system variables JDK_HOME to where my JDK is located and the same for JAVA_HOME. I have also set a path. I ran as admin many times and let AS through a firewall.
I have also restarted and reinstalled countless times.
The version of AS is 2.0, and I am running the latest versions of Java.
Any help?
Open file Android Studio setup directory/bin/idea.properties
Add disable.android.first.run=true to end
Restart Android Studio
PLEASE NOTE: This will break patch updating to the next version. We
now check full binary checksums on the whole installation to prevent
various install corruption bugs as well as to preserve application
signatures. Therefore, make a copy of this file first, and before
updating, put it back.
Please try the following method to fix that issue:
Find the folder of your AndroidStudio: based on the following directory
macOS: ~/Library/Application Support/Google/AndroidStudio[version]
Delete the AndroidStudio folder.
Restart
Ref:https://developer.android.com/studio/known-issues#studio-config-directories
In order to know how to debug the problem, I executed the bin\studio.bat script in the terminal and inspected the actual Idea exceptions in order to fix the problem.
For me, this was the issue:
ERROR - llij.ide.plugins.PluginManager - java.net.BindException: Address already in use: bind
java.util.concurrent.CompletionException: java.net.BindException: Address already in use: bind
This means the plugin manager is trying to listen on a port that is not available. Is something listening on that port? For me, it was the stupid "excluded ports" by Windows, so I simply stopped the service:
net stop winnat (as administrator), and confirmed that Android Studio started to work.
No need to re-install, delete precious configuration (and plugins, etc.). Just read the log provided by the bin\studio.bat script, and I was able to fix the issue.

android studio emulator won't start/show up

I'm new to Android/Kotlin programming (not to programming in general) and I'm following the Kotlin Basics course on developer.android.com.
The very first lesson after having installed Android Studio is to create a Virtual Device and run an extremely basic app on it.
However I can't get the emulator to work. The very first time I tried, it opened a small window with a progress bar but it became unresponsive at around 1/4 progress and I had to eventually kill it.
Since then it just won't start/open.
After I click run, the code compiles and the Event Log within Android Studio says Executing tasks[...] then Gradle build finished[...] and that's it. Nothing happens beyond that and the Emulator window says "No emulators are currently running".
However:
Some emulator-related processes have been started. Those processes stay alive even after closing Android Studio..
If I try to start the AVD from within the device manager, I get an error message that the device is already running
I am unable to delete these .lock files without killing the aforementioned processes
What I could find:
The Windows Event Viewer shows an Application Error
The Android Studio log file also shows an Error
I don't know what to do with either of these messages, though
What I tried
Killing the emulator processes, removing the *.lock files and trying again.
Creating a different AVD (different device, different version of Android)
Completely reinstalling Android Studio and the SDK following the accepted answer to this question: How to completely uninstall Android Studio from windows(v10)?.
None of this had any effect.
I'm running Android Studio Arctic Fox (2020.3.1 Patch 4) on Windows 10 Pro (10.0.19042 Build 19042).
I am able to run the app on my actual phone but down the line I would like to be able to test apps on different types of devices or without having to always use my physical one.
All help would be greatly appreciated.
By running and emulator.exe command in a command prompt, I was able to see yet another error message, the same one as in this post: emulator: incompatible HAX module version 3 requirs minimum version 4, and the answer to that post from user Harold Sota (as well as the comment under it from Harun, more specific to my situation) solved the issue.

Android Studio stuck while building application

I recently switched from Eclipse to Android Studio because I read that it is now the official IDE for Android application development. I downloaded and installed the latest version (1.0.2) for Windows. When using the program for the first time, I decided to create a test application to see if the program was working correctly. Unfortunately, it was not. Once I clicked the finish button to complete the New Project Wizard, A loading bar showed up that said Gradle: Build. This is where the program gets stuck. There is no error message and it appears that the program is running fine, however the build never actually completes. I am never given my MainActivity.Java class, or my activitymain.xml document. If I click the cancel button, the program freezes and I have to use the TaskManager to kill the program. If I re-enter the program and choose to open an existing project, my project will be there. However, upon trying to open the project, I am greeted with the same Gradle: Build loading bar.. I have been searching for an answer for the last 3 days and nothing has worked. Any help is greatly appreciated!
Things I have tried:
Simply letting the program sit for a while to see if it was actually downloading something and was just really slow. I let it sit for 45+ minutes before killing the program.
Uninstalling and re-installing Android Studio
Restarting my computer
Turning off my firewall (Kaspersky)
Running the program as an administrator
Connecting to a different network
Disconnecting my computer from any networks (to force the program to build in offline mode)
Manually downloading Gradle from the link that Android Studio attempts to use when it gets stuck and telling the program to use that file instead of downloading another one.
(I went to this link https://services.gradle.org/distributions/gradle-2.2.1-all.zip, downloaded the file, unzipped it, went to Gradle settings in Android Studio, checked the Offline work checkbox, and finally set the service directory path to my unzipped Gradle folder.)
Hopefully I have given enough information and made it clear what my problem is. If not please tell me what else I need to explain so I can get this issue resolved. Thanks!
Please note I am working on a 64 bit machine running Windows 8. Also, I use studio64.exe
to run the program.
From the discussion we had in the comments, it does not look like you have your gradle on your windows path.
Please change the below to point to your gradle install:
set GRADLE_HOME=C:\<installation location>\gradle-1.11
set PATH=%PATH%;%GRADLE_HOME%\bin
After this, verify that in the terminal running the following works:
gradle tasks
once you get this working, you will want to run the following in your project:
gradle wrapper
This will produce a .bat file which you can then use to run gradle through the wrapper, letting you support multiple native gradle installations.

Android Studio hangs / Freezes when project build fails

I am experiencing a very wired problem since this evening.
If I have any errors in my android project, and build is failed, then my Android studio gets frozen / stuck. I cant do anything but kill the Android studio application.
Even if I open the same project next time, gradle will try to build and freezes again. [Please find attached screen shot]
Only solution I could find is .... I have to find what exactly cause the "build fail" and I will have to resolve the issue using some other editor, and then my android studio will start working.
Thing is it was working without any issues till this evening; and suddenly broken down. Any one else having the same issue ??
-n
If you are using Android Studio v1.2.1.1 or newer and you are using Macbook, I've recently seen that if your device is connected to your laptop (by usb have no idea about over the wifi) and you sleep your laptop then login again, Android Studio hang. Therefore, you need to unplug usb cable then you should see Android studio is happy and then reconnect your usb cable.
Open your terminal and reset adb:
adb kill-server
adb start-server
This is how I solved the same problem:
Go to your project directory using your terminal
run ./gradlew (or gradlew.bat) assembleDebug
Fix the problems reported by gradle
Restart android studio and the problem is gone
Based on barbarian's answer I did this on my Mac:
start a terminal
chmod +x gradlew
./gradlew
./gradlew build
This last step showed an error in my xml file, indicating that I used unescaped single quotes. Fixing that solved the hangup.
Well, I uninstalled android studio and installed it again, and now the problem has gone away.
I still wonder how in the world it broke in the first place.
In case some one else is facing the same issue, try reinstalling your studio.
In case if you are using Mac osx refer How to completely uninstall Android Studio? to uninstall Android studio properly; Because only deleting App will not completely uninstall it.
In my case the same thing happened, after I had added image-resources with dashes in the filename.
I manually deleted them, renamed them, and added them with underscores in the name, and Android Studio worked normally again.
(I am not sure the dashes were the reason, why should they, but doing the above fixed it.)
#Hesam's answer doesn't work for me. Using OSX and AS 1.2.1.1, my building stuck in 'Scanning files to index' and I cannot solve it even after restarted my Macbook. Below work for me:
Shut down Android Studio (force to kill or just unplug the usb you will be good to go)
Go to the directory of AndroidStudioProjects and move the application directory out to some other location (outside AndroidStudioProjects).
Restart the android studio, now you will be shown the screen asking you whether you want to start a new project or open an old one.
Again paste the folder you have cut and kept aside in step 2 back to AndroidStudioProjects directory.
In the android studio prompt, select open existing project and select the directory you have now just pasted to AndroidStudioProjects.
It should work for my case.

Apk only runs in debug mode. Apk started with "Run" in Eclipse stops on breakpoints

I note that this has been asked before but I haven't found an answer yet. The main tell tale of this problem is that Eclipse stops on break points when the apk has been deployed as "Run"
I've done these so far and none produce a correctly running "Run" build from Project shell -> Run As -> 1. Android Application
• Disconnecting, uninstalling and re installing the apk does not fix the problem (this is a tablet device, not an emulator.)
• Made all of the project and library projects write able using the file system
• Brand new projects work correctly e.g. they don't stop on breakpoints in "Run" mode in the same Eclipse workspace as the problem project
• Window -> Preferences -> Run/Debug(expand) -> Launching "Launch in debug mode when workspace contains breakpoints" is set to never
• Closed and opened Eclipse
• Killed all of the running processes under the "Debug" tab in that perspective
• Cleaned the entire workspace both in Eclipse IDE and manually by deleting the res and gen folders of the main and library project dependencies
• Checked for the occurrence of the word "debug" in the project build files
• Clean built the project from the command line using: ant clean then ant release
Interestingly enough, when I clean build from the command line then fresh-install the new apk, if Eclipse is open the debugger will attach to the running process and stop at the first break point! If Eclipse is closed, the program will wait for the debugger with the standard "Waiting for Debugger" dialog.
So something is broken in the build process (haven't figured out what all files are getting involved yet) and/or something in .metadata and/or some depenency.
edit
I've found a file at:
C:\Projects\Mobile\Android\.metadata\.plugins\org.eclipse.debug.core\.launches\MyProjectName.launch
in the xml:
<launchConfiguration type="com.android.ide.eclipse.adt.debug.LaunchConfigType">
Don't know if it's a clue, but if I delete the file Eclipse will just replace it with the same.
edit
*Confirmed that the project Runs correctly when built and run from another machine, so I suspect that it's my work machine's Eclipse workspace that's causing this issue. Maybe I need to throw out all of the workspace's metadata and start over.
I encountered same issue. The solution is, restarting your device. Good luck.
You said you have breakpoints?
Try:
Window -> Preferences -> Run/Debug(expand) -> Launching
There should be a section entitled "Launch in debug mode when workspace contains breakpoints"
If that is not on "Never" that would be your problem.
I have the same problem and I need 4 steps to resolve them:
Disconnect the device
Reboot the device
Clean and build all the projects in workspace.
Start the app in emulator in Run mode and check it's ok.
Start the app in the device in Run mode and all works ok.
Only restarting the device not works for me!
I've encountered same problem: I could run my application only in debug mode, but it won't properly start when I press 'run' button. I've tried all solution here, but nothing works for me.
After some time I've found android.os.Debug.waitForDebugger(); in the begining of my Activity. I hope this answer sometimes help someone, because this question was first in Google, when I search for help.
Update
Use Intellij instead of Eclipse for Android development (far fewer IDE interface bugs) and then disregard the following altogether:
Two important rules I've found since the original post:
1) Get in the habit of waiting until Eclipse is finished build the workspace - the indicator shows up in the bottom left corner of Eclipse by default. WS build times can take minutes in a large project with multiple libs. Don't change anything until the build is complete.
2) Close all projects in the workspace and reopen them one-at-a-time starting with the project with no lib dependencies and so on. Make sure not to open a project until you can verify the the workspace has finished building what is already open. Fix any issues along the way before opening the next project.
Good luck.
Happens to me sometimes - have you uninstalled the application completely from the handset and tried to reinstall? Can you install the apk and then disconnect the handset from the machine? (obv won't work if you're using an emulator)
Faced same issue on Samsung S4 and issue is fixed by unchecking "Wait for debugger" option under "Developer options".
Had the same issue, check that you haven't got this line of code anywhere in your project:
android.os.Debug.waitForDebugger();
It may exist in a Service for debugging purposes, once you comment it out it will work in release mode. The problem is that this line of code waits for the debugger, and if you're not running in debug mode it will wait indefinitely

Categories

Resources