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 :(
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.
Related
I want to install an ARM .apk onto a x86 Android emulator. It already works with libhoudini and Genymotion. Now I want to use libhoudini with docker-android.
I already tried the solution from How to flash zip on Genymotion programmatically (extracting the shell script and pushing it via adb to the emulator inside Docker), but this didn't work either because unzip/zip is not supported.
This is the current Dockerfile:
FROM budtmo/docker-android-x86-6.0
COPY ./app/outputs/apk/release/app-release-unsigned.apk .
COPY ./arm-translation.tar .
COPY ./setup.sh .
COPY ./flash-archive.sh .
RUN chmod 777 setup.sh
What is the best way to run an ARM .apk on a x86 emulator inside Docker?
I tried to run emulator64-arm in a Docker container but it reported:
$ emulator64-arm -avd t2 -no-window -no-accel -gpu off
qemu: could not open disk image /home/testuser/.android/avd/t2.avd/sdcard.img: Interrupted system cal
I think qemu-aarch64 should be a pure software emulator without any fancy things involved but I was wrong.
I also tried to start the container with --privileged but still no luck.
In my case we need to run some smoke tests for our Android APK, speed doesn't really matter but Android-X86 is not an option.
This is not about the root cause but a workaround.
AVD created under Linux will also create "qcow2" files for each image, with these qcow2 files, emulator can successfully start.
But these qcow2 files are not created under any other platforms, I was using an AVD created under Mac and got the error, then I recreated AVD under Linux and the error was gone.
I'm trying to run freshly built Android image on emulator (generic aosp_x86-eng target built from current master using Google sources). The emulator seems to be working fine, except it does not mount external SD card when run with -sdcard option. Emulator version is the one that comes from the git. Everything is executed on a headless server.
My complete list of steps:
repo init -u https://android.googlesource.com/platform/manifest
repo sync
. build/envsetup.sh
lunch aosp_x86-eng
make -j16
mksdcard 1G sd.img
emulator -no-window -no-skin -no-audio -sdcard sd.img &
adb shell mount | grep vfat
The virtual device appears to be correctly forwarded, as seen by the output of adb shell blkid:
/dev/block/vda1: LABEL="system" UUID="da594c53-9beb-f85c-85c5-cedf76546f7a" TYPE="ext4"
/dev/block/vdb: LABEL="cache" UUID="f73de97f-7017-ca5e-9b47-ca9c8f633e83" TYPE="ext4"
/dev/block/vde1: LABEL="vendor" UUID="6d16bab1-58d9-3c5d-8f14-f608f924affd" TYPE="ext4"
/dev/block/vdf: LABEL="SDCARD" UUID="1CEA-0B06" TYPE="vfat"
However, it is not mounted by vold. What could be the problem?
I also get the same result when I run emulator using Android 8 image downloaded via SDK manager. With Android 7, SD card works OK.
EDIT:
Solved the issue for emulator that comes with aosp_x86-eng build (see my own answer). On the emulator from Android SDK, the cause is probably different.
Turns out, in my case headless mode was the culprit. When I run emulator with -no-skin -no-window options, SD card is not mounted. If I remove these options (and enable X11 forwarding, since I work on a headless server), everything works correctly.
I still want to know why I can't use SD card in headless mode, but at least I was able to solve the problem for the required task.
Essentially my issue is that when I run emulator -verbose -avd Nexus_5X_API_19 in the command line the emulator starts up with the argument -dns-server = "w,x,y,z" where w,x,y,z are 4 ip addresses for DNS servers. When I run ipconfig /all I only see x,y,z listed as my valid DNS servers in Windows. Because of this odd first DNS server, I am unable to access the internet within the emulator. When I run the emulator with emulator -verbose -avd Nexus_5X_API_19 -dns-server "x,y,z" everything works fine.
But now I want to be able to run my app from within Android Studio 2.2.3 with the corrected DNS servers. So does anyone know how to specify the emulator command line arguments within Android Studio (similar to this answer for the older Eclipse based version: https://stackoverflow.com/a/4736518/1088659), or how to set the default DNS for the emulator to start with?
Unfortunately, as of 3.0.1, this isn't possible. They removed adding additional arguments for emulators launched from Android Studio. Until they add it back in, starting the emulator from the command line (as you showed) is the only option.
You can track this issue here: https://issuetracker.google.com/issues/37071385
If you are on MacOS or Linux, you could rename the Android Emulator executable to something else (say emulator-binary) and create a script with the actual emulator name (emulator) in its place, that calls the executable with the -dns-server parameter.
Here are the steps required:
Find the path where the Android SDK is located in your system. This answer will help you find it.
cd <your-SDK-path>/emulator.
Rename the original executable: mv emulator emulator-binary.
Finally, create an emulator shell script named emulator with the following contents:
<your-SDK-path>/emulator-binary -dns-server "8.8.8.8,8.8.4.4" $#
Unfortunately, I ran into the same issue. I wrote a simple script that pulls the DNS address from settings automatically. Script was written for MacOS, but should work for Linux just the same. Note: You may need to change the path to the Android Emulator script.
#!/bin/bash
set -m
dns=$(grep "nameserver" /etc/resolv.conf | grep "\." | awk '{split($0,a," "); print a[2]}')
echo "Running emulator with DNS address: $dns"
~/Library/Android/sdk/emulator/emulator -avd $1 -dns-server $dns -no-snapshot-load &>/dev/null &
disown
You just need to give it your emulator name (note: spaces become underscores), e.g.:
runemu Pixel_4_API_30
where "runemu" is what I named the script on my machine.
I am trying to run a emulator from the Android source by loading the goldfish kernel with some of my configuration changes. Though I found a lot of questions on this, but could not find my answer.
1. I downloaded the android source.
2. I also successfully built my goldfish kernel. Now I can see the zImage in the /goldfish/arch/arm/boot folder.
After this I tried running this emulator by referring to a lot of similar questions.
Building Android from source - emulator and AVDs, Running emulator after building Android from source, How to compile android goldfish 3.4 kernel and run on emulator. But unfortunately didn't solve my problem. When I try to run the emulator with :
./emulator -debug init -kernel Thepath/goldfish/arch/arm/boot/zImage -avd firstAvd -wipe-data
I get an error that AVD is not found. I then found this blog, https://yaapb.wordpress.com/2012/09/22/build-a-custom-android-emulator-image/ where it says to first make the emulator from the source tree by the following commands:
$ source build/envsetup.sh
$ lunch full-eng
$ make -j4
$ emulator -wipe-data &
Then to run the emulator with my modified kernel, I need to run :
$ cd ${ANDROID_BUILD_TOP}
$ emulator -kernel ~/workspace/android/goldfish/arch/arm/boot/zImage -wipe-data &
Though I am trying to do this, the process of creating the emulator with the make command is taking hours. 7% in 90 mins till now. So in the mean time I wanted to know if anyone can tell me that to run an emulator with my kernel, do I need to first create an emulator from the source? Also, I dont find the system.img, ramdisk.img files in the android source tree. Is it normal or I ge them when I create an emulator?
**
EDIT
**
I would also like to know if I can run the emulator without the make -j4. The Android source tree also includes the SDK. Can I run the Emulator from the SDK. If yes, how? The google official docs say to run the following command form the /tools folder in the sdk. But there is no tools folder in the sdk folder.
After you have built the sources, you should not run build process once again in order to use the emulator. Simply go to the folder with your AOSP code and run the following commands:
$ cd ${ANDROID_BUILD_TOP}
$ source build/envsetup.sh
$ emulator -kernel ~/workspace/android/goldfish/arch/arm/boot/zImage -wipe-data &
The command source build/envsetup.sh will add additional commands to your shell, and you should be able to run emulator without building it one more time from scratch.