3
votes

I need to include existing android emulator with the changes included in it (qcow2 files) in the docker image.

Sequencing:

1) Create an emulator through the Android Studio

2) Run it with the -writable-system option

emulator -avd xposed -writable-system

3) Make the necessary changes (Xposed installation, some xposed modules, data recording on the SD card and so on). All of these changes writing to qcow2 files (system.img.qcow2, sdcard.img.qcow2, etc.)

4) Stop the emulator

5) Archive it

cd /home/user/.android/avd && tar -cvzf xposed.tar.gz .

6) In the docker file:

ADD xposed.tar.gz /root/.android/avd

7) In xposed.ini change absolute path to the emulator instance

path=/root/.android/avd/xposed.avd

When try to run the emulator inside the docker - the qcow2 files with changes are recreated instead of used existing. :(

I get the same android-sdk tools and emulator versions, the same JDK and so on.

Also trying to change paths in harware-qemu.ini to the new one (/root/.android/avd/xposed/....) but no luck.

Some information about system and docker:

1) Android version 23 (6.0) x86 google_apis image

2) Run docker command:

sudo docker run -d -p 5900:5900 -p 5555:5555 --privileged -v /dev/kvm:/dev/kvm --name xposed xposed

3) Run android emulator command:

usr/local/android-sdk/emulator/emulator -avd xposed -noaudio -no-window -gpu off -verbose -qemu -usbdevice tablet -vnc :0

I really don`t know what to do. It is real, one time a have a luck, I get it and it was working great, but I lost this state and now nothing happens :(

By the way, in normal behavior I will get an error, like:

avd\system.img.qcow2,read-only: Could not open backing file: Could not open .....

But now no errors, it just override my files :(

1

1 Answers

1
votes

I had the same problem when copying the emulator from the host to a docker container: the emulator inside docker would always start (in the best case) clean as after a factory reset, ignoring all my changes. This is how I solved the problem:

  • I started the emulator inside the docker container and I installed everything I needed (Xposed, custom apks etc.) while the emulator was running in docker.
  • After the emulator was setup the way I wanted, I turned if off and copied the /root/.android/avd/<emulator name> directory from the docker container to the host computer (by using docker cp command). This way I obtained a backup copy of the emulator with all the custom settings that can be used with docker.
  • I built a new docker image containing all the sdk stuff and tools needed to run the emulator and I added to the image the /root/.android/avd/<emulator name> directory previously saved. Now when I start a docker container from the new image I have a working emulator with all the settings I need.

Bonus tip: if you want to use the snapshot feature of the emulator, you have to commit the changes in the container to a new image (see docker commit command) and then use that new image, simply copying the avd directory will not work in this case and your snapshot will always be ignored.