You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Emulator repeatedly crashes on restart due to stale AVD .lock files (Bugfix is Included) #34
After an unclean shutdown / container stop, the Android emulator can enter a restart/crash loop on the next boot. The AVD folder keeps leftover *.lock files (ex: /data/android.avd/*.lock). When these stale lock files are present, the emulator often fails to start properly and keeps crashing until the lock files are manually removed.
Steps to reproduce
Start the container/emulator normally.
Stop it in a way that isn’t clean (ex: kill/restart container/host, force stop, etc.).
Start the container/emulator again.
Emulator crashes or fails to boot repeatedly.
Expected behavior
Emulator should start normally after restart, even if the previous stop was unclean.
Actual behavior
Emulator fails to start and/or crashes repeatedly until *.lock files are deleted from the AVD directory.
Diagnosis
Stale *.lock files are left behind in /data/android.avd after an unclean shutdown. On next start, the emulator treats the AVD as “in use” / locked and can crash or refuse to boot.
Proposed fix
Delete stale lock files before launching the emulator in start-emulator.sh.
Patch
Add these lines after killing any running emulator processes:
# Removes .lock files before emulator starts to prevent crashes
rm -rf /data/android.avd/*.lock
Notes
-f ensures startup doesn’t fail when no lock files exist.
-r is included for robustness (in case any lock artifacts are directories).
This only targets *.lock entries in the AVD directory and doesn’t touch other AVD data.
Activity
sayhere556 commentedon Dec 16, 2025
Here is the updated start-emulator.sh that will fix this:
Shmayro commentedon Dec 16, 2025
Yeah, I usually get this. True, I used to do the cleanup manually.
Good work!
You can open a pull request so I can merge it.
sayhere556 commentedon Dec 17, 2025
Done.
sayhere556 commentedon Dec 17, 2025
Please reply when you pull the code so I know when to update my scripts.