Skip to content

[BUG] Emulator repeatedly crashes on restart due to stale AVD .lock files (Bugfix is Included) #34

@s4t7

Description

@s4t7

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

  1. Start the container/emulator normally.
  2. Stop it in a way that isn’t clean (ex: kill/restart container/host, force stop, etc.).
  3. Start the container/emulator again.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions