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.
After an unclean shutdown / container stop, the Android emulator can enter a restart/crash loop on the next boot. The AVD folder keeps leftover
*.lockfiles (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
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
*.lockfiles are deleted from the AVD directory.Diagnosis
Stale
*.lockfiles are left behind in/data/android.avdafter 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:
Notes
-fensures startup doesn’t fail when no lock files exist.-ris included for robustness (in case any lock artifacts are directories).*.lockentries in the AVD directory and doesn’t touch other AVD data.