Running emulator after building Android from source - android

I am able to pull down the latest android source code into a Ubuntu virtual machine 32-bit (Host: Windows 7 64-bit). The build completes without any errors.
Then I tried to follow these instructions, where it mentions that I should run the emulator on the root of my source code. However, when I tried that, I get an error stating that this command is not found.
So I went to the folder out/host/linux-x86/bin and I found out that there are couple files for emulator*:
emulator
emulator-arm
emulator_renderer
emulator-ui
emulator-x86
When I typed the emulator and emulator-x86 here, it also doesn't work. Here is the error I'm getting:
xxxx/out/host/linux-x86/bin$ ./emulator-x86
emulator: ERROR: You did not specify a virtual device name, and the system
directory could not be found.
If you are an Android SDK user, please use '#<name>' or '-avd <name>'
to start a given virtual device (see -help-avd for details).
Otherwise, follow the instructions in -help-disk-images to start the emulator
So when I run ./emulator-x86 -help-disk-images, I see the following:
If you are building from the Android build system, you should
have ANDROID_PRODUCT_OUT defined in your environment, and the
emulator shall be able to pick-up the right image files automatically.
See -help-build-images for more details.
I built this myself, so I would think that ANDROID_PRODUCT_OUT is set in my environment variables, but I don't see it. So I think that I should run some other shell script to get that set.
I looked at the img files, I saw couple at the location out/target/product/generic:
ramdisk.img
system.img
userdata.img
Could anyone shed some light on this and assist me on what I should do next? I am new to Android and I did some research on this but I couldn't find any similar issues.

I do not know for which product you do your build but to run emulator you can use the following command:
out/host/linux-x86/bin/emulator -sysdir out/target/product/generic/ -system out/target/product/generic/system.img -ramdisk out/target/product/generic/ramdisk.img -data out/target/product/generic/userdata.img -kernel prebuilt/android-arm/kernel/kernel-qemu -sdcard sdcard.img -skindir sdk/emulator/skins -skin WVGA800 -scale 0.7 -memory 512 -partition-size 1024
Just copy it into .sh file into the root of your Android source folder and run this file. Or you can just run it but you should chdir to your Android source folder root at first.
And do not forget to create an sdcard image in the root folder with command mksdcard.

After much puzzling and encountering many of the same problems, I've found a way to get everything working from a new environment.
Environment
First of all, make sure you set your environment with the changes to ~/.bashrc that Android recommends, including:
export USE_CCACHE=1
ccache -M 10G
Follow the steps for downloading the Android source, if you haven't already done so.
Then set up some functions for the environment:
$ . build/envsetup.sh
You now should actually execute one of those functions to get the paths set correctly (as Pingzhong Li pointed out, this is not mentioned in the Android build instructions!):
$ set_stuff_for_environment
First build
Start building! For instance:
$ lunch full-eng
$ make -j4
(Here, 4 threads is ideal for my machine. Change as you see fit.)
When the build finishes, simply launch the emulator:
$ emulator
Subsequent builds
I've found that to get the system.img to rebuild, you need to remove the following files/directories:
out/target/product/generic/obj/PACKAGING/
out/target/product/generic/system.img
Then simply repeat:
$ make -j4
$ emulator

How to run Emulator step by step guide.
Running emulator in downloaded android AOSP source code is as below :-
Step 1
If you have finished your build and generated System image correctly in current running Terminal(Ubuntu), Then it is stragiht forward. Just type below command in your terminal:-
emulator
Step 2
If you have generated system image earlier and you have started a fresh terminal(Ubuntu) then run the following command one by one :-
source build/envsetup.sh
lunch 1 here 1 is my lunch type, you can replace it with yours like(7, 8 etc) and in the last
emulator
Thats it it will lunch your emulator correctly.
Thanks Guys Happy Coding !!!!

Just for reference I had this similar problem and after trying different things I found the solution to be running lunch(after running envsetup.sh) and picking the target in this case aosp_arm-eng. You have to do this everytime you start a new shell because it sets up certain environment variables the emulator needs to run the avd.Provided you have built the target.

#!/usr/bin/env bash
ANDROID_BUILD_OUT=/path/to/android/build/output/
ANDROID_SDK_LINUX=/path/to/android/sdk
ANDROID_BUILD=${ANDROID_BUILD_OUT}/android/target/product/generic
${ANDROID_SDK_LINUX}/tools/emulator \
-sysdir ${ANDROID_BUILD} \
-system ${ANDROID_BUILD}/system.img \
-ramdisk ${ANDROID_BUILD}/ramdisk.img \
-data ${ANDROID_BUILD}/userdata.img \
-kernel ${ANDROID_SDK_LINUX}/system-images/android-18/armeabi-v7a/kernel-qemu \
-skindir ${ANDROID_SDK_LINUX}/platforms/android-18/skins \
-skin WVGA800 \
-scale 0.7 \
-memory 512 \
-partition-size 1024

On a mac, you can add the following lines into your ~/.bash_profile file. Change your disk image and src folders accordingly.
# start emulator
function startEmulator { hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android;
cd /Volumes/android/AndroidSrc;
source build/envsetup.sh;
lunch aosp_arm-eng;
/Volumes/android/AndroidSrc/out/host/darwin-x86/bin/emulator; }
After that, create a new terminal and type:
startEmulator
Your emulator can be started. This works on mac.

Just type emulator on your shell and it will launch the emulator of the latest build as its path is set to the PATH variable of your shell.

If you have the "android sdk" on your machine, then your "emulator" could be picked up from there instead of /out/.... dir.
When you want to work with your "own" emulator, you can rename the "android sdk" directory. Then your "emulator" will be picked up.
Hope this helps you!
Regards
Sammoh

export MY_PWD=/work/ABC/Google_Android
export ANDROID_BUILD_TOP=/work/ABC/Google_Android
export PATH=$PATH:$MY_PWD/prebuilts/gcc/linux
export ANDROID_PRODUCT_OUT=$MY_PWD/out/target/product/generic
The above is my env setting.
ANDROID_BUILD_TOP solved the
"emulator: ERROR: You did not specify a virtual device name, and the system
directory could not be found"
on my machine

I performed this way
I modified the ./build/envsetup.sh file, I only changed the set_stuff_for_environment
function set_stuff_for_environment()
{
setpaths
set_sequence_number
export ANDROID_BUILD_TOP=$(gettop)
# With this environment variable new GCC can apply colors to warnings/errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
export ASAN_OPTIONS=detect_leaks=0
export ANDROID_PRODUCT_OUT=/var/www/android/out/target/product/generic_x86_64
echo $ANDROID_PRODUCT_OUT
}
At the root of the project I created a file named start.sh
#!/usr/bin/env bash
ANDROID_BUILD_OUT=/var/www/android/out
ANDROID_SDK_LINUX=/opt/android-studio/sdk
ANDROID_BUILD=${ANDROID_BUILD_OUT}/target/product/generic_x86_64
sudo chmod -R 777 /dev/kvm
source build/envsetup.sh
set_stuff_for_environment
./prebuilts/android-emulator/linux-x86_64/emulator \
-debug-init -logcat '*:v' -verbose \
-sysdir ${ANDROID_BUILD} \
-system ${ANDROID_BUILD}/system.img \
-ramdisk ${ANDROID_BUILD}/ramdisk.img \
-skindir ${ANDROID_SDK_LINUX}/platforms/android-28/skins \
-skin WVGA800 \
-partition-size 2000
-scale 0.7 \
-memory 2000 \
-data ${ANDROID_BUILD}/userdata.img \

Related

How to create an AVD for "system-images;android-27;google_apis;x86" using avdmanager command line in Ubuntu?

I am able to create emulators for android-26 and older using the avdmanager command line, but I am getting the following error when trying to create for android-27 and above:
~/Android/sdk/tools/bin/avdmanager create avd --force -n Tablet -k "system-images;android-27;google_apis;x86" -d 6 --sdcard 200M
Error: Package path is not valid. Valid system image paths are:ository...
system-images;android-26;google_apis;x86
null
The same command for android-26 works:
~/Android/sdk/tools/bin/avdmanager create avd --force -n Tablet -k "system-images;android-26;google_apis;x86" -d 6 --sdcard 200M
Am I missing anything?
P.S.: This is happening in Linux Ubuntu. It seems to work fine in Mac OS.
Your command is correct but problem is that in your system, you don't have "android-27" OS
Please check which OS you have in your system, go into following directory
directory path : ~\Android\Sdk\platforms
if you don't have it please download it first.
download command is : sdkmanager --install "system-images;android-27;google_apis;x86"

Cannot start Android emulator x86_64 in Docker container (in VM)

I have am using Docker inside a VM (Debian Stable). I want to run an Android emulator for x86_64 in a Docker container.
Here is how the Docker image is built:
FROM debian:stable
RUN apt-get update && apt-get install --yes curl unzip openjdk-8-jdk libqt5widgets5
RUN useradd foo --shell /bin/bash --create-home --user-group
USER foo
WORKDIR /home/foo
RUN curl --output sdk-tools-linux.zip https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
RUN unzip sdk-tools-linux.zip && rm sdk-tools-linux.zip
RUN yes | tools/bin/sdkmanager 'system-images;android-24;default;x86_64' 'emulator' 'build-tools;26.0.1' 'platform-tools' 'platforms;android-24'
RUN echo no | tools/bin/avdmanager create avd --package 'system-images;android-24;default;x86_64' --name android-x86_64
When starting the emulator like this inside the container:
emulator/emulator -avd android-x86_64 -no-window -no-audio -no-boot-anim -no-accel -gpu off
I get the following error:
emulator: WARNING: encryption is off
emulator: WARNING: x86_64 emulation may not work without hardware acceleration!
path /home/foo/.android/avd/android-x86_64.avd/system.img.qcow2
qemu-system-x86_64: -device virtio-blk-pci,drive=system,iothread=disk-iothread,modern-pio-notify: ioeventfd is required for iothread
It seems to be related to hardware acceleration (is it?). Disregarding the purposefulness of such environment (emulator inside Docker inside a VM), is it possible to run the emulator in such context? How can I solve my problem?
Thanks,
We're using (or trying to use) this exact same scenario for automated testing.
The problem: The x86 and x86_64 emulator requires hardware acceleration. Hardware acceleration (VT-X or AMD-V) is not typically available inside a virtual environment (See: https://askubuntu.com/questions/328748/how-to-enable-nested-virtualization-in-ubuntu)
This means your best option is to use the ARM emulator, which is really slow. Running this inside Docker inside a VM will be even slower.
You can create the emulator like this:
# NOTE: Must use ARM, since x86 requires hardware acceleration, which is not available inside
# a docker container running inside a virtual machine
echo no | ${ANDROID_HOME}/tools/bin/avdmanager create avd \
--abi "armeabi-v7a" \
--device 'Nexus 4' \
--force \
--name arm_emulator \
--package "system-images;android-25;google_apis;armeabi-v7a" \
--sdcard 64M
You can then start the emulator like this:
${ANDROID_HOME}/emulator/emulator \
-avd arm_emulator \
-gpu swiftshader_indirect \
-memory 512 \
-no-audio \
-no-boot-anim \
-no-window &
Running this inside Docker on my local machine takes the emulator about 4-5 minutes to finish booting. When the Docker environment runs inside VirtualBox expect it to be even slower.
Even with this working, some commands like app installation through ADB fail because they take simply too long.
If possible, it may be a better option to start the emulator parallel to the virtual machine (e.g. on the same host) and then connect to the emulator through network.

Android 64bit terminal / rsync

I am trying to get my rooted LG G4 to rsync with my server. On the good old LG G2 it is running smoothly but the 64bit architecture throws errors at me.
I tried to come up with a solution from other sources (here and other sites) But it just goes on to the next file it cannot load correctly
The code I use is as follows:
export LD_PRELOAD=/system/lib64/libsigchain.so; export PATH=$PATH:/data/data/burrows.apps.busybox/app_busybox; export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/data/burrows.apps.busybox/app_busybox:/vendor/lib*:/system/lib*; /data/data/burrows.apps.busybox/app_busybox/rsync -v -E --delete -s -r -t -l --partial --size-only --rsh="/data/data/burrows.apps.busybox/app_busybox/ssh -y -i /keypath/ssh.key -p10022" user#homeip:/some/folder/ /local/folder
First it was the libsigchain.so 32/64bit error
Now it is this: CANNOT LINK EXECUTABLE DEPENDENCIES: "/system/lib/libsigchain.so" is 32-bit instead of 64-bit CANNOT LINK EXECUTABLE DEPENDENCIES: "libc.so" is 64-bit instead of 32-bit
Be it tasker, secure settings or terminal emulator ...
I would appreciate any suggestions.

Eclipse Android Emulator won't launch

I have installed Eclipse 4.2 with Eclipse android plugin(ADT)on ubuntu 11.10. when i launch "Hello World" project as an android application, it simply wont launch!
ps -x > log.txt after launching the emulator, output:
1000 7221 20.0 0.6 16884 6908 ? D 18:11 0:00 /home/tutakhail/android-sdks/tools/emulator-arm -avd AndroidBrowser -netspeed full -netdelay none
launching the emulator manually from shell, i get the following error, shortly after which the emulator launches but is very slow.
emulator: ERROR: Could not load OpenGLES emulation library: libOpenglRender.so: cannot open shared object file: No such file or directory
emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
Any hints on what could be the issue here? Perhaps related to Ubuntu?
Turns out the solution is to point LD_LIBRARY_PATH to the /tools/lib path.
Below works for me.
➜ tools file ../tools/lib/libOpenglRender.so
../tools/lib/libOpenglRender.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, not stripped
➜ tools export LD_LIBRARY_PATH=/home/xxxx/devel/android-sdk-linux/tools/lib:$LD_LIBRARY_PATH
➜ tools ./emulator-x86 -avd AtomX86 -gpu on -qemu -m 1024 -enable-kvm
emulator: emulator window was out of view and was recentered
....
I guess its a bug affecting the latest versions of the ADTs perhaps has something to do with NVIDIA GPUs drivers. The issue is discussed here:
https://groups.google.com/forum/?fromgroups#!topic/adt-dev/nlA07toW1fc
The work around that I have found which at least lets me execute my applications till a permanent solution is released, is that by first launching the emulator from shell even if it throws the error. After which i right-click and run my projects as an "Android application". The emulator does surprisingly execute them!
I've got similar error, and I guess this error caused by missing libGL.so.
Install package libgl1-mesa-dev;
sudo apt-get install libgl1-mesa-dev
Source
Try running emulator from command line first to see if everything goes well.
You may need to add options like:
-no-audio
-gpu off
I've seen audio preventing emulator to start on some Ubuntu configurations.
I tried to use the Intel Hardware Acceleration in Ubuntu 12.04 for running emulators using KVM package. However I was getting the error, "Failed to start RenderThread". Installing the package libgl1-mesa-dev and reducing the Device RAM Size to 512 solved my problem. The emulator now is indeed atleast 10X faster. I hope this would help someone trying to emulate android devices in Ubuntu using Intel processor that supports Virtualizattion Technology.
SO i guess maybe you haven't installed everything properly.
You should check if you followed the steps as shown in :
http://www.wikihow.com/Install-Android-on-Ubuntu-Linux-With-Eclipse-Ide
After installing it properly and setting up the PATH environment variables .
Also another thing you can do is try deleting the AVD emulator and creating a new one and then try again .
Also i found your question over here at : https://groups.google.com/forum/?fromgroups#!topic/adt-dev/nlA07toW1fc
THe question you asked is not really specific so just try following the steps.
The following command saved my life with the same problem
sudo apt-get install libgl1-mesa-dev
If using eclipse, you have to add in Project-Properties in the "Java Build Path" -> Libraries -> Android 4.4 -> "Native library location" the path to sdk/tools/lib directory.
For me this is "install-dir-of-sdk"/sdk/tools/lib"
Configure ANDROID_HOME
export ANDROID_HOME=//android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
and set LD_LIBRARY_PATH
export LD_LIBRARY_PATH="$ANDROID_HOME/emulator/lib64:$LD_LIBRARY_PATH"
To run ARM version
cd $ANDROID_HOME/emulator/
./emulator64-arm -avd Nexus_5X_ARM_22 -no-audio -gpu off
I solved this on my Red Hat Linux 64 bit by installing the 32bit libGL (it should be located in /usr/lib/)
sudo yum install mesa-libGL.i686
libOpenglRender.so and other necessary files are present, indeed, in tools/lib64, while avd tries to find them in tools/lib
Making symbolic links to the files and dirs helped (in my case)
ln -s ../lib64/qt qt
ln -s ../lib64/gles_mesa gles_mesa
ln -s ../lib64/libstdc++ libstdc++
ln -s ../lib64/lib64GLES_V2_translator.so lib64GLES_V2_translator.so
ln -s ../lib64/lib64emugl_test_shared_library.so lib64emugl_test_shared_library.so
ln -s ../lib64/lib64OpenglRender.so lib64OpenglRender.so
ln -s ../lib64/lib64GLES_CM_translator.so lib64GLES_CM_translator.so
ln -s ../lib64/lib64EGL_translator.so lib64EGL_translator.so
(seems to be bug in original config, as that happens with fresh install of the studio/sdk)

I get 'Command Not Found' when I try to run Android Emulator on Mac OS X

When I use the Mac OS X Terminal to navigate to the folder with my Android Emulator and type emulator, I get:
command not found
Here's what happens:
$ emulator
-bash: emulator: command not found
How do I get it to work?
The current directory is not normally included in your $PATH on a *nix operating system like OS X; to execute a program in the current directory, precede it with the path to the current directory (.):
$ ./emulator
Emulator can be added with Android Studio https://developer.android.com/studio/run/managing-avds.html
To start emulator: ~/Library/Android/sdk/tools/emulator -avd Nexus_5X_API_23
Related question: How do I launch the Android emulator from the command line?
solutions
1. Symbolic link
steps
create one symbolic link emulator
# soft link
$ ln -s ~/Library/Android/sdk/tools/emulator /usr/local/bin/emulator
call the command
# check all avd
$ emulator -list-avds
$ emulator #avd_name
# OR
$ emulator -avd avd_name
2. system environment
edit env with vim/vscode
# zsh
$ vim ~/.zshrc
# OR
$ code ~/.zshrc
add below lines to the .zshrc file
# export ANDROID_SDK_ROOT=/Users/xgqfrms/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd
update config
# flush update
$ source ~/.zshrc
refs
https://developer.android.com/studio/run/emulator-commandline
These 3 command works for me on VS Code Terminal (Mac Book Pro M1)
echo 'export PATH=$PATH:~/Library/Android/sdk/emulator/' >> ~/.bash_profile
source ~/.bash_profile
emulator -list-avds
Open Android Studio. Click on AVD Manager (the icon with the android and phone) [example image: AVD Manager]. See the list of emulators. You should see something like "Install Emulator" if you don't have any.
Once this is successful, you'll get the tools folder downloaded to your ~/Library/Android/sdk
That is the folder you want, because it has the android and emulator command line tools.
typcally i use from terminal :
./Library/Android/sdk/emulator/emulator *some action*

Categories

Resources