Reputation: 11
Android Emulator snapshot flag is not working as expected. I created a new avd with name Mydevice using
tools/bin/avdmanager create avd --force --name Mydevice --abi google_apis/x86 --package 'system-images;android-29;google_apis;x86' --device "Nexus 6P" &
Now I run this avd using
sudo emulator/emulator -avd Mydevice -no-window -port 5554
After emulator is booted successfully, I take a snapshot using
adb -s emulator-5554 emu avd snapshot save Snap1
which successfully creates the snapshot.
Now I stop my running emulator using
adb -s emulator-5554 emu kill
Now I again run the emulator using -read-only flag and using the saved snapshot using
sudo emulator/emulator -avd Mydevice -read-only -no-window -port 5554 -snapshot ~/.android/avd/Mydevice.avd/snapshots/Snap1
but it seems like -snapshot is getting ignored as emulator is still taking same time as earlier to boot.
I also tried removing the read only flag but that did not helped.
Upvotes: 0
Views: 1525
Reputation: 19665
The argument to -snapshot
is a snapshot tag name, not a path.
First, list the snapshots like this:
emulator/emulator -avd mydevice -snapshot-list
which will produce output like this (so far I haven't figured out how to list snapshots without actually starting the emulator as well, but for now just shut down the emulator after running this command):
ID TAG VM SIZE DATE VM CLOCK
-- snap_2020-12-03_13-31-29 90M 2020-12-03 13:31:29 01:11:57.073
-- default_boot 68M 2020-12-03 14:15:33 00:02:08.928
Then, start the emulator using one of the values in the "TAG" column e.g.:
emulator/emulator -avd mydevice -snapshot snap_2020-12-03_13-31-29
For Android Studio, the "advanced settings" for devices in the AVD Manager also have a drop-down for selecting a snapshot to start the device with.
As a side note, I've found that starting an emulator image from a snapshot drastically improves its performance, at least on my Linux box. With the snapshot flag, the emulator's disk writes are normal -- without it, for some reason the emulator is essentially constantly writing to disk, slowing everything to a crawl. I honestly don't know why that is.
Upvotes: 0