117

I am trying to run emulator on my android studio 8.14. When I click run it says it is already running. Any help would be appreciated.

AVD api21 is already running.

If that is not the case, delete the files at /home/sayem/.android/avd/api21.avd/*.lock and try again

image containing the error written out above

Zoe
  • 27,060
  • 21
  • 118
  • 148
Sayem
  • 4,891
  • 3
  • 28
  • 43

35 Answers35

213

You don't have to completely delete the emulator when this happens. The files to delete should have a ".lock" extension:

Screenshot of files for an AVD. The first three files appear as file folders in Windows 7 and have '.lock' at the end of their file names.

You don't need to touch the configuration files.

You can easily find the files location by clicking on the arrow under the Actions tab (in the ADB manager), and selecting "Show on Disk".

BSMP
  • 4,596
  • 8
  • 33
  • 44
  • I have the same problem. I tried doing this, but it won't let me because it says that the files are currently in use. What should I do? – qwerty May 20 '20 at 20:54
  • I thought i just need to delete *.lock file, but it also required to delete *.lock folder. – Yohanim Jul 14 '20 at 07:27
  • @ap Was Android Studio still running? You might try quitting the application first. – BSMP Dec 10 '20 at 18:52
  • Deleting all the .lock files and restarting the Emulator is what worked form me – chobela Dec 27 '21 at 09:10
  • On Windows, this is the only sureshot method (https://stackoverflow.com/a/62676806/2632842) and does not require clearing cache, restarting Studio, rebooting Windows and other such things. – zehawk Apr 22 '22 at 08:58
  • Nice, had deleted the files but didnt notice the folder also was *.lock lol – Second2None May 04 '22 at 03:04
  • Just remove all *.lock files under the emulator folder. – android iPhone May 26 '22 at 13:40
63

This worked for me:

Go to AVD Manager and click on the down-arrow on the right and click Stop. This stops the emulator and you can re-run it.

BigDreamz
  • 816
  • 1
  • 7
  • 9
  • 7
    Most precise answer here because, if we try to delete the *.lock folder, it may simply be denied while this work at first attmpt. – JorgeAmVF Apr 10 '19 at 21:13
  • 4
    This worked for me. I was unable to delete the *.lock files it was telling me to delete since "they were in use". So clicking Stop allowed me to delete the AVD. – Alexiz Hernandez Aug 29 '19 at 04:44
  • 2
    "Most precise answer here because" probably for you. That did nothing in my case – Farid Feb 19 '21 at 17:50
  • Thanks, It worked. No need to delete files. @Farid In case the delete button was disabled, I changed the Graphics to "automatic" and "stop" button enabled. – Ehsan Shadi Sep 25 '21 at 07:15
  • I have to "Stop" action there. – jave.web Mar 18 '22 at 13:03
49

Go to the down arrow and click on the "Show on Disk" link like attached image. You will get the list of all files, remove the file "hardware-qemu.ini.lock" and start again.

It works for me hope it will work for you too.

enter image description here

Rahul Mishra
  • 4,263
  • 7
  • 32
  • 53
  • 6
    may also need to be deleted in "multiinstance.lock" – Burak Odabaş Jan 15 '22 at 22:53
  • although it allows startup, before the device opens I get "...was terminated", even if I delete `multiinstance.lock` too I had to also delte `snapshot.lock.lock` then device started, but please note this **does not** kill the hanging process of the original device. That can be done with `adb kill-server` - I suggest running that first – jave.web Mar 18 '22 at 13:07
  • If .lock files are in use, end the **qemu-system-i386.exe** process first, then delete the .lock files. – andreszs Nov 15 '22 at 12:10
19

There are so many answer but i just extending to give answer of this question. What happen is when i follow Android Studio instruction and try to delete that folder Or file but i am not able to delete it, So what am i do is that i open the AVD Manager and click on down arrow which is on right side as you can see in below screenshot and click on stop after click on start and its working fine. There is no need to restart or recreate the AVD.

Joker
  • 796
  • 1
  • 8
  • 24
Ninja
  • 678
  • 10
  • 26
18

Follow the instructions on the error and go to your C:\Users\directory\.android\avd/Nexus_5_API_24.avd/*.lock and delete all files with the .lock extension and it should work.

Zack
  • 472
  • 7
  • 16
11

I restarted the computer and it worked for me!

joekevinrayan96
  • 564
  • 10
  • 25
11

When I was trying to delete multiinstance.lock it says

enter image description here

So, I opened Window's task manager and selected qemu-system-x86_64.exe and press End task

enter image description here

Jitendra
  • 1,015
  • 9
  • 24
8

This working for me :

Invalidate chaches/ restart

Go to

1 - File

2 - Select Invalidate Cahes / Restart

enter image description here

Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
5

Use this for killing all emulator processes.

adb emu kill
Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78
4

C:\Users\admin.android\avd\Nexus_5X_API_26.avd follow path and delete hardware-qemu.ini.lock this folder. make sure your problem can be solve :)

4

Find and open the pid folder within your *.lock folder. Inside should be a number.

Kill pid:

Windows

taskkill /F /PID pid_number
bg9848
  • 322
  • 8
  • 23
  • On Windows, this is the most elegant, sureshot method and does not require clearing cache, restarting Studio, rebooting Windows and other such things as mentioned in other answers. – zehawk Apr 22 '22 at 09:02
4

Go to (Windows)

C:\Users\directory.android\avd/Nexus_5X_API_26.avd

Or (Ubuntu)

~/.android/avd/name.avd/Nexus_5X_API_26.avd

and delete all files of with .lock extensions.

MD Jahid Hasan
  • 786
  • 1
  • 9
  • 19
3

Thanks everyone.

I removed files of given location. but when I refresh the AVD manager, Existing emulator are all gone.

I recreated new emulator. Now it works fine.

Sayem
  • 4,891
  • 3
  • 28
  • 43
3

When you go to the specified location and try to delete those files sometimes you might get an error stating that the file or folder is already open or is used by another application

So the simple Solution is just to go to

Tools > Android > AVD Manager and Stop the AVD that you are trying to run

Then When you try to run the AVD again you might have the problem resolved

Divakar Rajesh
  • 1,140
  • 2
  • 18
  • 23
3

For me, "delete .lock file" & "stop emulator then start" & "delete emulator then recreate" does't work.

but,delete "C/User/yourName/.android" folder can fix this problem

Rabbit
  • 480
  • 5
  • 13
3

For MAC Users

Open Terminal, cd to the given path. List all the files using the command ls. You will see two files with .lock extensions or maybe more. Just delete those files. enter image description here

Ajji
  • 3,068
  • 2
  • 30
  • 31
3

For Windows: Step By Step Instructions below:

  1. Locate the avd folder: *C:\Users\username\.android\avd*
  2. Try delete *lock and figure out the process holding the lock
  3. Ctrl+Shift+Esc to get to TaskManager
  4. Select Pid and Process name by right clicking on the header
  5. Get the PID number of the offending application
  6. on cmd type: taskkill /F /PID /PIDnumber
  7. Now go back to the avd folder & delete the *lock files. It will work.
  8. Restart Emulator
Hez
  • 315
  • 2
  • 7
2

Just follow the tips from Android Studio ... Delete the file corresponding to your avd and recreate it.

This happens when the virtual device is shut down in an unexpected state.

pdegand59
  • 12,776
  • 8
  • 51
  • 58
2

I Also have the same problem but in ubuntu 20.04 and I had to navigate to /home/your_username/.android/avd/Pixel_2_API_28.avd/*.lock and then delete all file with .lock

Note: you first need to enable show hidden files and I may have used different device (Pixel_2_API_28) from yours but it is applied to any device

twizelissa
  • 111
  • 5
2

For Linux this should clear them for all devices in one go if your issue is just .lock files

find $HOME/.android -type f -name '*.lock' -exec rm {} \;

Example with it just echoing out.

❯ find $HOME/.android -type f -name '*.lock' -exec echo rm {} \;
rm /home/mike/.android/build-cache.lock
rm /home/mike/.android/debug.keystore.lock
rm /home/mike/.android/avd/Pixel_6_Pro_API_33.avd/multiinstance.lock
rm /home/mike/.android/avd/Pixel_6_Pro_API_33.avd/hardware-qemu.ini.lock
rm /home/mike/.android/avd/Pixel_6_Pro_API_30.avd/multiinstance.lock
rm /home/mike/.android/avd/Pixel_6_Pro_API_30.avd/hardware-qemu.ini.lock
rm /home/mike/.android/build-cache/3.5.2.lock
~ at 10:16:27 
❯ 

If you did not stop them all first can run this first beforehand.

adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
Mike R
  • 679
  • 7
  • 13
1

If "adb kill-server" dont work try killing the adb from System monitor app of ubuntu:

System monitor->processes

All processes will be listed here end adb from here, must be in the top of the list.

sharkbait
  • 2,980
  • 16
  • 51
  • 89
shijin
  • 2,998
  • 1
  • 24
  • 30
1
  1. Open Settings
  2. Goto developer options
  3. Click revoke USB debugging authorizations
Floern
  • 33,559
  • 24
  • 104
  • 119
user1677230
  • 1,024
  • 9
  • 3
1

In your Android Studio go to Tools->Android->AVD Manager. It will list your virtual devices. Click the Action column corresponding to your virtual device. It will list many actions. Click on Stop. This will shutdown your android studio. Now start android studio. Your virtual device should work fine.

ABN
  • 1,024
  • 13
  • 26
1

Or you can type a command in terminal as

1.killall Finder and then type,

2.defaults write com.apple.Finder AppleShowAllFiles true it shows hidden .android folder

Open .android folder and delete .android/avd/Nexus_5X_API_26.avd/*.lock file and now you run emulator it works fine.

Agilanbu
  • 2,747
  • 2
  • 28
  • 33
1

I closed the emulator, clicked the AVD Manager Icon on the menubar then under the emulators actions tab downward arrow I selected "Cold Boot Now" then ran the program normally by pressing SHIFT + F10enter image description here

Tonnie
  • 4,865
  • 3
  • 34
  • 50
1

You can also solve this problem by doing "Invalidate chaches/ restart".

pankaj
  • 29
  • 1
1

EASIEST SOLUTION:

  1. Go to AVD Manager
  2. Click on down arrow in the Actions column on the right
  3. Click on Wipe data

You're done :)

Stack Fox
  • 1,201
  • 9
  • 14
  • Why would you do this when there is a simple solution? https://stackoverflow.com/a/62676806/2632842 – zehawk Apr 22 '22 at 09:00
0

Run this command and try again:

adb kill-server 
oz123
  • 27,559
  • 27
  • 125
  • 187
Konstantin Loginov
  • 15,802
  • 5
  • 58
  • 95
0

In my case the emulator looked fine but it was hung.

Just killing the emulator and trying again did the trick.

Johan Walles
  • 1,447
  • 2
  • 15
  • 23
0

C:\Users\.android\avd follow the path and open Emulator directory and delete all .lock extension folders.

Vivek Pratap Singh
  • 1,564
  • 16
  • 26
0

If you have followed all answers, and no success yet. And not able to find that specific lock.

Search all .lock extension files in /avd dir, and remove them. After then start again emultaor. It works for me without restart system.

vivek
  • 1,034
  • 11
  • 14
0

I'm don't know if some one is still having this problem, but, in my case, it's was an issue related to VAGRANT.... more precisely whit Virtual Box. I just stop the vBox proccess (i'm ussing ubuntu), remove the .lock files related to the emulator inself and that's it... the emulator should by ready to go.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Martín Mori
  • 1,021
  • 1
  • 7
  • 5
0

I tried solutions above but nothing worked so I deleted the emulator, restart pc and create a new one and it was resolved

Hanako
  • 1,637
  • 1
  • 13
  • 16
0

Check Updates... Emulator had an update. After I updated and restarted.. worked fine.

batthis
  • 127
  • 1
  • 5
0

for Linux , create an executable script that contains this (depends on package psmisc ,Artix Linux):

#!/bin/bash

#kill x86 + x86_64 emulator instances
killall qemu-system-x86_64 -9
killall qemu-system-i386 -9

# delete all lock-files
for n in `find ~/.android/avd/ -name "*.lock"`; do rm -v $n;done
CaptainCrunch
  • 1,230
  • 14
  • 15