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.
Related
I saw some links and posts about running AndroidTest in Docker. Like:
https://dzone.com/articles/running-android-tests-in-docker
https://github.com/ksoichiro/android-tests/tree/master/docker-emulator
And some more. However, they all seem inappropriate for AndroidTest in CI, since they require an actual VM, or simply they are too old.
I tried the following lines Docker Image (Partial):
RUN /opt/adk/tools/bin/sdkmanager "emulator" "build-tools;${BUILD_TOOLS}" "platforms;${ANDROID_PLATFORM}" "system-images;${ANDROID_PLATFORM};google_apis;armeabi-v7a" \
&& echo no | /opt/adk/tools/bin/avdmanager create avd -n "Android" -k "system-images;${ANDROID_PLATFORM};google_apis;armeabi-v7a" \
And then I run the emulator using:
/opt/adk/emulator/emulator #Android -writable-system -nocache -no-snapstorage &
However, when trying to run connectedAndroidTest there were some weird exceptions, like:
Caused by: com.android.ddmlib.InstallException: Unknown failure: Error: Could not access the Package Manager. Is the system running?
Or, if I try to manually install the test APK, and run am instrument:
android.util.AndroidException: Can't connect to activity manager; is the system running?
So my question: Is anyone is running AndroidTest on emulator as part of the CI on docker? Means, an image that you just need to mount your project and run gradle connectedAndroidTest, and everything works? Is there a working example for that?
I run AndroidTest on emulator as part of the CI on docker using this image: https://hub.docker.com/r/chrisss404/android-emulator
The problem you might encounter is that hardware acceleration is not available on your host because of missing nested KVM (just a guess, but that was the problem I was facing). In this case you have to use software rendering, which can take a significant amount of time.
With software rendering, the startup takes about 40 minutes until the emulator is usable (on my host). However, then you can run the instrumentation tests as usual in an acceptable timeframe.
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.
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.
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.
Back again on Stack needing help from fellow Android Developers. In my development environment im using a lot of command line building and management. Currently im running into a issue where the Terminal "Using Mac OSX" when executing the command "emulator -avd nameOfemulator" the Terminal is still live.
Example of Launching Emulator
However even when the emulator is open and live, The Terminal is not let go to be able to execute additional command, I dont want to just open a new tab or window to have to execute my adb command's. Currently i can closes the emulator and kill the live terminal/emulator command by a simple 'ctrl-C' however this defeats the purpose if the emulator is closed.
Does anybody know of anyway of getting the terminal live again, either through a script, string of commands, different type of emulator's, etc.
UPDATE
Now running the following command emulator -avd NexusSeven & This emulator has the HAX Intel Hardware Acceleration enabled. And shortly after the terminal becomes available again, The string "HAX is working and emulator runs in fast virt mode" is inputted into the command input and makes the terminal live again.
Since MacOSX is just a fork of BSD Linux, the emulator can be run in background by appending the ampersand:
emulator -avd NexusSeven &
To ignore all output, the following command will help:
emulator -avd NexusSeven > /dev/null 2>&1 &