Skip to content

Instantly share code, notes, and snippets.

@atyachin
Last active November 15, 2024 14:04
Show Gist options
  • Save atyachin/2f7c6054c4cd6945397165a23623987d to your computer and use it in GitHub Desktop.
Save atyachin/2f7c6054c4cd6945397165a23623987d to your computer and use it in GitHub Desktop.
Running headless android emulator on AWS EC2 Ubuntu instance (ARM64 / aarch64) - 2022
Android Emulator (ARM64) on EC2 - 2022
---------------------------------------
1. Launch EC2 ARM based Instance (a1.metal / a1.2xlarge): (16 Gb RAM, 32Gb Disk), Ubuntu Server 22.04 LTS (HVM) ARM x64
2. sudo apt update && sudo apt upgrade
3. sudo apt install default-jdk python3-pip repo python-is-python3 unzip libpcre2-dev adb
4. wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip
5. unzip commandlinetools-linux-8512546_latest.zip -d android-sdk
6. sudo mv android-sdk /opt/
7. mkdir /opt/android-sdk/cmdline-tools/latest
8. mv /opt/android-sdk/cmdline-tools/* /opt/android-sdk/cmdline-tools/latest (ignore the error)
9. at this point you should have sdkmanager and avdmanager under /opt/android-sdk/cmdline-tools/latest/bin/
10. echo "export ANDROID_SDK_ROOT=/opt/android-sdk" >> ~/.bashrc
11. echo "export ANDROID_HOME=/opt/android-sdk" >> ~/.bashrc
12. echo "export ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=60" >> ~/.bashrc
13. echo "export PATH=$PATH:/opt/android-sdk/cmdline-tools/latest/bin" >> ~/.bashrc
14. source ~/.bashrc
15. sdkmanager --update
16. sdkmanager --licenses
17. cd /opt/android-sdk/
18. Get emulator download link:
- https://ci.android.com/builds/branches/aosp-emu-master-dev/grid?
- column: emulator --> linux_aarch64
- click a green version
- click Artifacts tab
- click sdk-repo-linux_aarch64-emulator-[build number].zip (~1.6Gb)
- Right-click the Download link (blue) and copy the download URL
- A Relatively stable version (31.3.8 - 5/24/2022): https://ci.android.com/builds/submitted/8632828/emulator-linux_aarch64/latest/sdk-repo-linux_aarch64-emulator-8632828.zip
19 wget -O emulator.zip "[download URL]"
20. unzip emulator.zip
21. cd emulator
22. copy text from https://chromium.googlesource.com/android_tools/+/refs/heads/master/sdk/emulator/package.xml
23. nano /opt/android-sdk/emulator/package.xml --> paste copied text
24. cat source.properties --> get Emulator version number from Pkg.Revision (Example: Pkg.Revision=31.3.9)
25. update the following params in package.xml according to the version: <major>, <minor>, <micro>
26. sdkmanager "system-images;android-31;google_apis;arm64-v8a"
27. avdmanager -v create avd -f -n MyAVD -k "system-images;android-31;google_apis;arm64-v8a" -p "/opt/android-sdk/avd"
28. avdmanager list avd --> check that you have MyAVD
29. mkdir /opt/android-sdk/platforms
30. mkdir /opt/android-sdk/platform-tools
31. echo "Vulkan = off" >> ~/.android/advancedFeatures.ini
32. echo "GLDirectMem = on" >> ~/.android/advancedFeatures.ini
33. on Metal instance, enabled KVM access:
- sudo gpasswd -a $USER kvm
- logout and re-login
- /opt/android-sdk/emulator/emulator -accel-check --> check accel:0, KVM (version 12) is installed and usable: accel
Run the Emulator:
------------------
Metal instance:
/opt/android-sdk/emulator/emulator @MyAVD -no-window -no-audio -ports 5554,5555 -skip-adb-auth -no-boot-anim -show-kernel
Non-metal instance:
/opt/android-sdk/emulator/emulator @MyAVD -no-window -no-audio -ports 5554,5555 -skip-adb-auth -no-boot-anim -show-kernel -qemu -cpu max -machine gic-version=max
Notes:
1. Use an ARM based EC2 instance. A Metal instance will allow ARM to run on the host CPU (via KVM). A non-metal instance will do ARM emulation which is much slower (but works).
2. The Android Emulaotr isn't included in the sdk-tools for ARM, we download it separately. After we install and update its package file, we can use sdkmanager to download system images and other emultaor-dependant packages.
3. The platform-tools (adb, aapt2 etc.) aren't not available for ARM64. We install ADB with apt-get (see apt list android-sdk* for other available tools).
4. Make sure to create the /platforms and /platform-tools folders under /opt/android-sdk/ or the emulator will exit (folder can be empty).
5. First run on non-Metal instance might take 10-15 minutes.
6. Use "google_apis" system image and not "google_apis_playstore". The "google_apis_playstore" requires authentication to connect via ADB (adb devices will show "emulator-5554 offline")
7. In case of unstable images (crash with illegal instruction), try using the aosp_atd image (e.g. "system-images;android-30;aosp_atd;arm64-v8a")
Android Emulator HW options:
----------------------------
nano /opt/android-sdk/avd/config.ini
nano ~/.android/avd/MyAVD.ini
Specific parameters to consider:
hw.ramSize=2048M
disk.dataPartition.size=2048M
Disabling the "Ok Google" Hotword detection (might cause 100% CPU on non-metal instance):
-----------------------------------------------------------------------------------------
adb shell "su root pm disable com.google.android.googlequicksearchbox"
Note: run after Emulator fully loaded
Connecting to Emulator console:
-------------------------------
1. get token from: /home/ubuntu/.emulator_console_auth_token
2. telnet 127.0.0.1 5554
3. auth [token]
4. save snapshot: avd snapshot save default
Manually setup system image (ex: android-32, Google APIs, ARM64):
-----------------------------------------------------------------------
1. https://dl.google.com/android/repository/sys-img/google_apis/arm64-v8a-32_r03.zip
2. mkdir /opt/android-sdk/system-images/android-32
3. mkdir /opt/android-sdk/system-images/android-32/google_apis
4. unzip arm64-v8a-32_r03.zip /opt/android-sdk/system-images/android-32/google_apis
image path: /opt/android-sdk/system-images/android-[api_version]/[api_type]/[arch_type] (/opt/android-sdk/system-images/android-32/google_apis/arm64-v8a)
avdmanager -v create avd -f -n MyAVD2 -k "system-images;android-32;google_apis;arm64-v8a" -p "/opt/android-sdk/avd2"
Useful ADB commands:
--------------------
Connect: adb devices
Install APK: adb install myapp.apk
Uninstall app: adb uninstall com.package.name
Start app: adb shell am start -n com.package.name/com.package.name.ActivityName
Start app2: adb shell monkey -p com.package.name --pct-syskeys 0 -c android.intent.category.LAUNCHER 1
Stop app: adb shell am force-stop com.package.name
Disable package: adb shell "su root pm disable com.google.android.googlequicksearchbox"
Uninstall package: adb shell "su root pm uninstall --user 0 com.google.android.googlequicksearchbox"
Check if running: adb shell dumpsys activity | grep -i run | grep -i com.package.name
Forward port: adb forward tcp:8888 tcp:8888
Kill emulator: adb -s emulator-5554 emu kill
Links:
------
Emulator ARM builds:
https://ci.android.com/builds/branches/aosp-emu-master-dev/grid?
Specific: https://ci.android.com/builds/submitted/8664812/aarch64_sdk_tools_linux/latest/sdk-repo-linux_aarch64-emulator-8664812.zip
ARM System images:
Google API Images: https://androidsdkoffline.blogspot.com/p/android-sysimg-google-arm-v8a-download.html
All Images: https://androidsdkoffline.blogspot.com
Another: https://androidsdkmanager.azurewebsites.net/GoogleAPIaddonSystemImages
References:
https://developer.android.com/studio/releases/emulator#emulator_for_arm64_hosts
https://github.com/google/android-emulator-container-scripts/issues/192
https://github.com/yaizudamashii/AndroidSDK/pull/1
https://medium.com/heuristics/deploying-android-emulators-on-aws-ec2-1-3-arm-architecture-and-genymotion-solutions-for-a-2ef3238542d5
https://gist.github.com/JonathanLalou/180c87554d8278b0e6d7
@agranig
Copy link

agranig commented Oct 5, 2022

Thanks for the great write-up!

Did you ever run into the issue that the emulator crashes with "illegal instruction" some seconds after the boot is complete?

...
[   44.908954][    T1] init: Sending signal 9 to service 'ranchu-setup' (pid 1430) process group...
[   44.914605][    T1] libprocessgroup: Successfully killed process cgroup uid 0 pid 1430 in 0ms
INFO    | Boot completed in 46997 ms
INFO    | Increasing screen off timeout, logcat buffer size to 2M.
INFO    | Revoking microphone permissions for Google App.
...
[   58.328133][  T186] logd: logdr: UID=10102 GID=10102 PID=1262 n tail=0 logMask=4 pid=0 start=0ns deadline=0ns
[   60.174300][    T1] init: Sending signal 9 to service 'idmap2d' (pid 2064) process group...
[   60.184410][    T1] libprocessgroup: Successfully killed process cgroup uid 1000 pid 2064 in 6ms
[   60.188143][    T1] init: Control message: Processed ctl.stop for 'idmap2d' from pid: 526 (system_server)
[   60.196064][    T1] init: Service 'idmap2d' (pid 2064) received signal 9
Illegal instruction

I'm trying to run it on an a1.metal, tried the emulator version you linked, and also the one from today. Also tried with GLDirectMem=off, with -gpu off etc, but all with the same result.

@gordonchen1989
Copy link

I'm trying to run it on an a1.2xlarge. The following error will be reported when it is started. Have you ever encountered a similar error?

[358.095160][ T1] init: processing action (nonencrypted) from (/system/etc/init/hw/init.rc:1100) [ 358.191935][ T1] init: starting service 'goldfish-logcat'... [ 359.244307][ T1] init: starting service 'bt_vhci_forwarder'... [ 360.449177][ T1] init: starting service 'cameraserver'... [ 361.916990][ T1] init: starting service 'idmap2d'... [ 363.446260][ T1] init: starting service 'incidentd'... [ 365.248111][ T1] init: starting service 'installd'... [ 365.937186][ T427] qemu-adb-setup: /data/misc/adb/adb_keys exists. Skipping qemu adb setup [ 366.512123][ T1] init: starting service 'mediaextractor'... [ 368.371226][ T1] init: starting service 'mediametrics'... [ 369.405733][ T1] init: starting service 'media'... ** ERROR:/buildbot/src/android/emu-master-dev/external/qemu/hw/intc/arm_gicv3_cpuif.c:779:gicv3_cpuif_update: assertion failed: (qemu_mutex_iothread_locked()) Aborted (core dumped)

@krmlrd
Copy link

krmlrd commented Oct 25, 2022

Having the same error as @gordonchen1989 on a1.2xlarge too.

@mexmirror
Copy link

I was able to start an emulator with Android SDK 30 by omitting the -machine gic-version=max parameter, and adding the -gpu swiftshader_indirect parameter. Here is the full command to start the emulator:

emulator @arm-test-30 -gpu swiftshader_indirect -no-accel  -no-audio  -ports 5554,5555 -show-kernel -debug-kernel -engine qemu2 -qemu -cpu max

@GZLiew
Copy link

GZLiew commented Mar 10, 2023

Hi @atyachin I tried downloading the emulator zip but its not downloading the correct file how do you do it?

wget -O /tmp/emulator.zip "https://ci.android.com/builds/submitted/8632828/emulator-linux_aarch64/latest/sdk-repo-linux_aarch64-emulator-8632828.zip"

@sinnpi
Copy link

sinnpi commented Mar 10, 2023

Very nice guide. Couldn't for the life of me find an arm64 build of the emulator by myself...

Hi @atyachin I tried downloading the emulator zip but its not downloading the correct file how do you do it?

wget -O /tmp/emulator.zip "https://ci.android.com/builds/submitted/8632828/emulator-linux_aarch64/latest/sdk-repo-linux_aarch64-emulator-8632828.zip"

You need to open the page in your browser and then get the download link there.

@GZLiew
Copy link

GZLiew commented Mar 11, 2023

@p-sin Im trying to run it through docker solve it with the below

curl -sS -L https://ci.android.com/builds/submitted/8632828/emulator-linux_aarch64/latest/sdk-repo-linux_aarch64-emulator-8632828.zip | grep -o 'https://storage[^"]*' | sed 's/\\u0026/\&/g'

but ended doesnt work because linux/arm64 doesnt build react-native android

falling back to x86

@chinhdinh2023
Copy link

Hello ! I am new to Android Emulator.
My goal is to set it up an Android Emulator on AWS and install an app such as Telegram , programmatically .. Is it possible ? and how ?
Please advise
Thank you so much

@Sam1808
Copy link

Sam1808 commented Jun 30, 2023

I'm trying to run it on an a1.2xlarge. The following error will be reported when it is started. Have you ever encountered a similar error?

[358.095160][ T1] init: processing action (nonencrypted) from (/system/etc/init/hw/init.rc:1100) [ 358.191935][ T1] init: starting service 'goldfish-logcat'... [ 359.244307][ T1] init: starting service 'bt_vhci_forwarder'... [ 360.449177][ T1] init: starting service 'cameraserver'... [ 361.916990][ T1] init: starting service 'idmap2d'... [ 363.446260][ T1] init: starting service 'incidentd'... [ 365.248111][ T1] init: starting service 'installd'... [ 365.937186][ T427] qemu-adb-setup: /data/misc/adb/adb_keys exists. Skipping qemu adb setup [ 366.512123][ T1] init: starting service 'mediaextractor'... [ 368.371226][ T1] init: starting service 'mediametrics'... [ 369.405733][ T1] init: starting service 'media'... ** ERROR:/buildbot/src/android/emu-master-dev/external/qemu/hw/intc/arm_gicv3_cpuif.c:779:gicv3_cpuif_update: assertion failed: (qemu_mutex_iothread_locked()) Aborted (core dumped)

Hi. Try to omit keys -machine & gic-version=max. For example:
emulator @phone_name -no-window -no-audio -ports 5554,5555 -skip-adb-auth -no-boot-anim -show-kernel -qemu -cpu max

@galook
Copy link

galook commented Aug 1, 2023

I am new to this, is there a way to connect to this emulator and see the graphical interface of android?

@ravi0402
Copy link

ravi0402 commented Aug 7, 2023

I am getting following error while installing sample apk file on my emulator

$ adb install ApiDemos-debug.apk
Performing Streamed Install
adb: failed to install ApiDemos-debug.apk: cmd: Can't find service: package

My emulator is up though:

$ adb devices
List of devices attached
emulator-5554	device

@Sam1808
Copy link

Sam1808 commented Aug 7, 2023

I am getting following error while installing sample apk file on my emulator

$ adb install ApiDemos-debug.apk
Performing Streamed Install
adb: failed to install ApiDemos-debug.apk: cmd: Can't find service: package

My emulator is up though:

$ adb devices
List of devices attached
emulator-5554	device

same error
in my opinion, the reason for this error is that the emulator was loaded incorrectly

@rricarrdo
Copy link

I am getting following error while installing sample apk file on my emulator

$ adb install ApiDemos-debug.apk
Performing Streamed Install
adb: failed to install ApiDemos-debug.apk: cmd: Can't find service: package

My emulator is up though:

$ adb devices
List of devices attached
emulator-5554	device

same problem here...
Was anyone able to fix this issue?

@theone9807
Copy link

theone9807 commented Oct 19, 2023

My it's showing offline, Command to make it available/online/device in background all the time ?
@agranig @rricarrdo @mexmirror @krmlrd @ravi0402

List of devices attached
emulator-5554	offline

@JossHorn
Copy link

JossHorn commented Oct 30, 2023

I'm trying to run this on an m1 chip running ubuntu. The emulator seems to manage all of the pre-boot steps (mounting the images and setting system props) but then crashes with this error when trying to cold boot:
ERROR | Unable to spawn process due to:, No such file or directory qemu-system-aarch64-headless: can't open backing store /home/thea/avds/YetAnotherTestAvd.avd/snapshots/default_boot/ram.img for guest RAM: Permission denied qemu-system-aarch64-headless: falling back to regular RAM allocation. WARNING: cannnot unmap ptr 0xfffe94eb4000 as it is in the protected range from 0xfffe94eb4000 to 0xffff150b4000 WARNING: cannnot unmap ptr 0xffff15004000 as it is in the protected range from 0xfffe94eb4000 to 0xffff150b4000 Could not init 'oss' audio driver WARNING | The emulator now requires a signed jwt token for gRPC access! Use the -grpc flag if you really want an open unprotected grpc port INFO | Using security allow list from: /home/thea/espen/emu/emu-master-dev/test/emulator/lib/emulator_access.json WARNING | *** Basic token auth should only be used by android-studio *** INFO | The active JSON Web Key Sets can be found here: /run/user/1001/avd/running/36869/jwks/aa8a5442-3c34-43b0-95f0-e7e3257578f9/active.jwk INFO | Scanning /run/user/1001/avd/running/36869/jwks/aa8a5442-3c34-43b0-95f0-e7e3257578f9 for jwk keys. INFO | Started GRPC server at 127.0.0.1:8554, security: Local, auth: +token INFO | Advertising in: /run/user/1001/avd/running/pid_36869.ini I1030 15:04:48.293225 36910 FrameBuffer.cpp:3682] setDisplayConfigs w 320 h 640 dpiX 160 dpiY 160 I1030 15:04:48.293273 36910 FrameBuffer.cpp:3695] setDisplayActiveConfig 0 INFO | Loading snapshot 'default_boot'... WARNING | Device 'encrypt' does not have the requested snapshot 'default_boot' WARNING | Failed to load snapshot 'default_boot' INFO | Cold boot based on user configuration WARNING | Cold boot based on user configuration ERROR | Unable to spawn process due to:, No such file or directory ERROR | Unable to spawn process due to:, No such file or directory ERROR | crashhandler_die: fatal: kvm_user_backed_ram_map: error registering slot: Invalid argument Segmentation fault (core dumped)

Any idea what would cause this or how to fix it?

@bentalcy
Copy link

anyone figured out the error "Can't find service: package" i am seeing a few folks here encountered it and i am also seeing that.
Using a1.2xlarge and following the instructions to the letter. the emulator runs but the package service isn't functioning.

many thanks!

@Abyss-W4tcher
Copy link

Hi, would you be able to create a Dockerfile to wrap the setup and ensure reliability accross systems ?

Thanks !

@NASAok
Copy link

NASAok commented May 22, 2024

@atyachin, shalom!
Have you ever tested how many emulators can one server run simultaneously?
Would be really thankful for the info (and for server's specs)!

@0x80O0oOverfl0w
Copy link

I tried this on a Gigabyte server with a 128-Core Ampere Altra Max running Ubuntu 22.04LTS (baremetal) and the performance is not great to say the least out of the box.

Pro tip for those out there still trying to do this. Ignore the the ram and core settings in the AVD, the emulator doesn't care. You need to use -cores and -memory flags when you launch the emulator. With 8 cores and 16GB ram per emulator, the performance was actually pretty good, but UI latency is terrible. Single core performance does not seem as good as it should be, but multicore performance is on par with real Android devices. I found that the emulator is very unstable if you assign is less than around 10-12GB ram.

If anyone has any tips on getting GPU acceleration working please let me know. I have two Tesla T4's that I'm trying to use in my server.

@Marietto2008
Copy link

Marietto2008 commented Sep 10, 2024

Hello.

I'm trying on the Jetson nano 4 GB,where I have installed Ubuntu 22.04,even if the kernel is still 4.9,but I have kvm enabled because I've applied the right patches,these ones :

https://github.com/OE4T/linux-tegra-4.9

aresuser@jetson:~$ /opt/android-sdk/emulator/emulator @MyAVD -no-window -no-audio -ports 5554,5555 -skip-adb-auth -no-boot-anim -show-kernel

INFO    | Storing crashdata in: /tmp/android-aresuser/emu-crash-34.2.8.db, detection is enabled for process: 47221
INFO    | Android emulator version 34.2.8.0 (build_id 11435509) (CL:N/A)
INFO    | Found systemPath /opt/android-sdk/system-images/android-34/google_apis/arm64-v8a/

ERROR: ld.so: object '/opt/android-sdk/emulator/lib64/libStubXlib.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

ERROR: ld.so: object '/opt/android-sdk/emulator/lib64/libStubXlib.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

INFO    | Storing crashdata in: /tmp/android-aresuser/emu-crash-34.2.8.db, detection is enabled for process: 47221
INFO    | Duplicate loglines will be removed, if you wish to see each individual line launch with the -log-nofilter flag.
INFO    | Increasing RAM size to 2048MB

WARNING | Failed to process .ini file /opt/android-sdk/avd/quickbootChoice.ini for reading.
library_mode swiftshader_indirect gpu mode swiftshader_indirect

Initializing hardware OpenGLES emulation supportandroid_startOpenglesRenderer: gpu infoI0911 00:57:13.689850   47221 HealthMonitor.cpp:279] HealthMonitor disabled.

I0911 00:57:13.737002   47221 FrameBuffer.cpp:506] Graphics Adapter Vendor Google (Google Inc.)
I0911 00:57:13.737075   47221 FrameBuffer.cpp:507] Graphics Adapter Android Emulator OpenGL ES Translator (Google SwiftShader)
I0911 00:57:13.737138   47221 FrameBuffer.cpp:508] Graphics API Version OpenGL ES 3.0 (OpenGL ES 3.0 SwiftShader 4.1.0.7)
I0911 00:57:13.737177   47221 FrameBuffer.cpp:509] Graphics API Extensions GL_OES_EGL_sync GL_OES_EGL_image 

GL_OES_EGL_image_external GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint GL_OES_texture_float 
GL_OES_texture_float_linear GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_packed_depth_stencil GL_OES_vertex_half_float GL_OES_standard_derivatives GL_OES_texture_npot GL_OES_rgb8_rgba8 GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_texture_format_BGRA8888 GL_APPLE_texture_format_BGRA8888 
I0911 00:57:13.737231   47221 FrameBuffer.cpp:510] Graphics Device Extensions N/A

OpenGL Vendor=[Google (Google Inc.)]OpenGL Renderer=[Android Emulator OpenGL ES Translator (Google SwiftShader)]OpenGL Version=[OpenGL ES 3.0 (OpenGL ES 3.0 SwiftShader 4.1.0.7)]INFO    | Sending adb public key [QAAAAO+utZ/xv67ueyyTAR1t8Dhz7lo8Jagj7K4khOIzav5L0I2p8abmJuu4Wu2nPcbxvgVsR5qRv3MkOF7nr462kVOLCM7Uf+aaAQVRfGymXKA+EXTqgnS3oTv3Gw5ogEmKI6IYxeY9M7UQSv/6Ifm1IHxepSWd5UUVeyBSIeDu6R33aQ26ck+Kq1TIsXiULuZjzhFBPEuLIIwzsiK9LTnn6LdeY2pjS9p/J22jNJRKZKfuVwc9GzLyTg8UD20nbLjZc2zeoc4+kLgYq/JMXgt/bV20kNlhDhidbjZzl7mCePENHKHZlOg65oCZTcQLXGcRITAndvlLylzQHdGCAw1Rp5UZ5dKXK33AEO8zIhHbd+M67OCFdlk7a9GfFCvsRmAc+CxaWyUwmFYVpDnq3GSXTzKoRkYQZX6g522aTMbqDx4RcyHqGG4dqJLv+dX787YiJF8RNcN/Cmvhbc/Kwl8La9sFD6/5ngZ69FHiYPx1gFFteNFPcVVLcrI7vZvdwu0Q0Uxn5uJeyiwQQnajnCouxeAPje+EQJLrct79mRsEBcrfD2tO9fLBBRKRVDaNk4pzJ4CNrShHzFIFRWzoFgP22yulXLbjYOJGgdcD68/kLseM8aKaE6EL59nB6DomPNFMRlgKca3AKojXK+cCqt9eZ8cjASiN/umegZiJeIKofffj6MRijQEAAQA= aresuser@unknown]

ERROR   | Unable to spawn process  due to:, No such file or directory

qemu-system-aarch64-headless: Unable to determine GIC version supported by host
WARNING | Unable to connect to packet streamer, no bluetooth emulation available

and this is what I get :

aresuser@jetson:~$ adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached
emulator-5554	offline

it is always offline. Someone knows the reason ? how can I bring it online ? thanks.

@lecko-cngroup
Copy link

I'm trying to run this on an m1 chip running ubuntu. The emulator seems to manage all of the pre-boot steps (mounting the images and setting system props) but then crashes with this error when trying to cold boot: ERROR | Unable to spawn process due to:, No such file or directory qemu-system-aarch64-headless: can't open backing store /home/thea/avds/YetAnotherTestAvd.avd/snapshots/default_boot/ram.img for guest RAM: Permission denied qemu-system-aarch64-headless: falling back to regular RAM allocation. WARNING: cannnot unmap ptr 0xfffe94eb4000 as it is in the protected range from 0xfffe94eb4000 to 0xffff150b4000 WARNING: cannnot unmap ptr 0xffff15004000 as it is in the protected range from 0xfffe94eb4000 to 0xffff150b4000 Could not init 'oss' audio driver WARNING | The emulator now requires a signed jwt token for gRPC access! Use the -grpc flag if you really want an open unprotected grpc port INFO | Using security allow list from: /home/thea/espen/emu/emu-master-dev/test/emulator/lib/emulator_access.json WARNING | *** Basic token auth should only be used by android-studio *** INFO | The active JSON Web Key Sets can be found here: /run/user/1001/avd/running/36869/jwks/aa8a5442-3c34-43b0-95f0-e7e3257578f9/active.jwk INFO | Scanning /run/user/1001/avd/running/36869/jwks/aa8a5442-3c34-43b0-95f0-e7e3257578f9 for jwk keys. INFO | Started GRPC server at 127.0.0.1:8554, security: Local, auth: +token INFO | Advertising in: /run/user/1001/avd/running/pid_36869.ini I1030 15:04:48.293225 36910 FrameBuffer.cpp:3682] setDisplayConfigs w 320 h 640 dpiX 160 dpiY 160 I1030 15:04:48.293273 36910 FrameBuffer.cpp:3695] setDisplayActiveConfig 0 INFO | Loading snapshot 'default_boot'... WARNING | Device 'encrypt' does not have the requested snapshot 'default_boot' WARNING | Failed to load snapshot 'default_boot' INFO | Cold boot based on user configuration WARNING | Cold boot based on user configuration ERROR | Unable to spawn process due to:, No such file or directory ERROR | Unable to spawn process due to:, No such file or directory ERROR | crashhandler_die: fatal: kvm_user_backed_ram_map: error registering slot: Invalid argument Segmentation fault (core dumped)

Any idea what would cause this or how to fix it?

ERROR | Unable to spawn process due to:, No such file or directory refers to /opt/android/emulator/bin64/netsimd which is not part of aarch64 emulator build. Netsim is responsible for Bluetooth stack, anyone know how to disable it?

@tal-rofe98
Copy link

For anyone who wants more dynamic script (for automated workflows):

sudo apt update && sudo NEEDRESTART_MODE=a apt -y upgrade
sudo NEEDRESTART_MODE=a apt -y install default-jdk python3-pip repo python-is-python3 unzip libpcre2-dev adb
wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip
unzip commandlinetools-linux-8512546_latest.zip -d android-sdk
sudo mv android-sdk /opt/
mkdir /opt/android-sdk/cmdline-tools/latest
mv /opt/android-sdk/cmdline-tools/* /opt/android-sdk/cmdline-tools/latest
echo "export ANDROID_SDK_ROOT=/opt/android-sdk" >> ~/.bashrc
echo "export ANDROID_HOME=/opt/android-sdk" >> ~/.bashrc
echo "export ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=60" >> ~/.bashrc
echo "export PATH=$PATH:/opt/android-sdk/cmdline-tools/latest/bin" >> ~/.bashrc
source ~/.bashrc
sdkmanager --update
yes | sdkmanager --licenses
cd /opt/android-sdk/
curl -o emulator.zip $(curl -s "https://ci.android.com/builds/submitted/12401025/emulator-linux_aarch64/latest/sdk-repo-linux_aarch64-emulator-12401025.zip" | sed -n 's/.*"artifactUrl":"\([^"]*\)".*/\1/p' | sed 's/\\u0026/\&/g')
unzip emulator.zip
cd emulator
echo $(curl -s "https://chromium.googlesource.com/android_tools/+/refs/heads/main/sdk/emulator/package.xml?format=TEXT" | base64 --decode) > /opt/android-sdk/emulator/package.xml
MAJOR_VERSION=$(grep 'Pkg.Revision' source.properties | cut -d'=' -f2 | cut -d'.' -f1)
MINOR_VERSION=$(grep 'Pkg.Revision' source.properties | cut -d'=' -f2 | cut -d'.' -f2)
MICRO_VERSION=$(grep 'Pkg.Revision' source.properties | cut -d'=' -f2 | cut -d'.' -f3)
sed -i "s|<major>[0-9]\+</major>|<major>${MAJOR_VERSION}</major>|g" package.xml
sed -i "s|<minor>[0-9]\+</minor>|<minor>${MINOR_VERSION}</minor>|g" package.xml
sed -i "s|<micro>[0-9]\+</micro>|<micro>${MICRO_VERSION}</micro>|g" package.xml
sdkmanager "system-images;android-31;google_apis;arm64-v8a"
yes "" | avdmanager -v create avd -f -n MyAVD -k "system-images;android-31;google_apis;arm64-v8a" -p "/opt/android-sdk/avd"
mkdir /opt/android-sdk/platforms
mkdir /opt/android-sdk/platform-tools
echo "Vulkan = off" >> ~/.android/advancedFeatures.ini
echo "GLDirectMem = on" >> ~/.android/advancedFeatures.ini

This is my setup script. Although the Run the emulator section didn't run successfully for me :|

@backpapp
Copy link

backpapp commented Oct 9, 2024

I'm trying to run this on an m1 chip running ubuntu. The emulator seems to manage all of the pre-boot steps (mounting the images and setting system props) but then crashes with this error when trying to cold boot: ERROR | Unable to spawn process due to:, No such file or directory qemu-system-aarch64-headless: can't open backing store /home/thea/avds/YetAnotherTestAvd.avd/snapshots/default_boot/ram.img for guest RAM: Permission denied qemu-system-aarch64-headless: falling back to regular RAM allocation. WARNING: cannnot unmap ptr 0xfffe94eb4000 as it is in the protected range from 0xfffe94eb4000 to 0xffff150b4000 WARNING: cannnot unmap ptr 0xffff15004000 as it is in the protected range from 0xfffe94eb4000 to 0xffff150b4000 Could not init 'oss' audio driver WARNING | The emulator now requires a signed jwt token for gRPC access! Use the -grpc flag if you really want an open unprotected grpc port INFO | Using security allow list from: /home/thea/espen/emu/emu-master-dev/test/emulator/lib/emulator_access.json WARNING | *** Basic token auth should only be used by android-studio *** INFO | The active JSON Web Key Sets can be found here: /run/user/1001/avd/running/36869/jwks/aa8a5442-3c34-43b0-95f0-e7e3257578f9/active.jwk INFO | Scanning /run/user/1001/avd/running/36869/jwks/aa8a5442-3c34-43b0-95f0-e7e3257578f9 for jwk keys. INFO | Started GRPC server at 127.0.0.1:8554, security: Local, auth: +token INFO | Advertising in: /run/user/1001/avd/running/pid_36869.ini I1030 15:04:48.293225 36910 FrameBuffer.cpp:3682] setDisplayConfigs w 320 h 640 dpiX 160 dpiY 160 I1030 15:04:48.293273 36910 FrameBuffer.cpp:3695] setDisplayActiveConfig 0 INFO | Loading snapshot 'default_boot'... WARNING | Device 'encrypt' does not have the requested snapshot 'default_boot' WARNING | Failed to load snapshot 'default_boot' INFO | Cold boot based on user configuration WARNING | Cold boot based on user configuration ERROR | Unable to spawn process due to:, No such file or directory ERROR | Unable to spawn process due to:, No such file or directory ERROR | crashhandler_die: fatal: kvm_user_backed_ram_map: error registering slot: Invalid argument Segmentation fault (core dumped)
Any idea what would cause this or how to fix it?

ERROR | Unable to spawn process due to:, No such file or directory refers to /opt/android/emulator/bin64/netsimd which is not part of aarch64 emulator build. Netsim is responsible for Bluetooth stack, anyone know how to disable it?

Getting the same issue, have you found a fix by any chance ?

@lecko-cngroup
Copy link

Unfortunately not, I haven't found the time. I guess the fastest way to get it working would be to use netsimd from x86_64 emulator build and let the Rosetta do its magic.

@Marietto2008
Copy link

Marietto2008 commented Oct 9, 2024

I've ran it on the Jetson Nano :

aresuser@jetson:/opt/android-sdk$ emulator @android9 -cores 2 -lowram -memory 1000 -gpu host -ports 5554,5555 -skip-adb-auth -no-boot-anim -no-snapshot -no-metrics -qemu -machine gic-version=2

INFO    | Storing crashdata in: /tmp/android-aresuser/emu-crash-34.2.8.db, detection is enabled for process: 98752
INFO    | Android emulator version 34.2.8.0 (build_id 11435509) (CL:N/A)
INFO    | Found systemPath /opt/android-sdk/system-images/android-28/google_apis/arm64-v8a/
INFO    | Storing crashdata in: /tmp/android-aresuser/emu-crash-34.2.8.db, detection is enabled for process: 98752
INFO    | Duplicate loglines will be removed, if you wish to see each individual line launch with the -log-nofilter flag.
WARNING | FeatureControl is requesting a non existing feature.
library_mode host gpu mode host
Initializing hardware OpenGLES emulation supportandroid_startOpenglesRenderer: gpu infoI0915 14:29:22.230528   98752 HealthMonitor.cpp:279] HealthMonitor disabled.
added library libvulkan.so
createGlobalVkEmulation:995 Selecting Vulkan device: NVIDIA Tegra X1 (nvgpu)
initialize: Supports id properties, got a vulkan device UUID
I0915 14:29:23.908542   98752 VkCommonOperations.cpp:1276] Initializing VkEmulation features:
I0915 14:29:23.908639   98752 VkCommonOperations.cpp:1277]     glInteropSupported: true
I0915 14:29:23.908676   98752 VkCommonOperations.cpp:1278]     useDeferredCommands: true
I0915 14:29:23.908707   98752 VkCommonOperations.cpp:1279]     createResourceWithRequirements: true
I0915 14:29:23.908738   98752 VkCommonOperations.cpp:1281]     useVulkanComposition: false
I0915 14:29:23.908768   98752 VkCommonOperations.cpp:1282]     useVulkanNativeSwapchain: false
I0915 14:29:23.908809   98752 VkCommonOperations.cpp:1283]     enable guestRenderDoc: false
I0915 14:29:23.908839   98752 VkCommonOperations.cpp:1284]     ASTC LDR emulation mode: 2
I0915 14:29:23.908879   98752 VkCommonOperations.cpp:1285]     enable ETC2 emulation: true
I0915 14:29:23.908908   98752 VkCommonOperations.cpp:1286]     enable Ycbcr emulation: false
I0915 14:29:23.908944   98752 VkCommonOperations.cpp:1287]     guestUsesAngle: false
I0915 14:29:23.908972   98752 VkCommonOperations.cpp:1288]     useDedicatedAllocations: false
I0915 14:29:23.909777   98752 FrameBuffer.cpp:506] Graphics Adapter Vendor Google (NVIDIA Corporation)
I0915 14:29:23.909904   98752 FrameBuffer.cpp:507] Graphics Adapter Android Emulator OpenGL ES Translator (NVIDIA Tegra X1 (nvgpu)/integrated)
I0915 14:29:23.909952   98752 FrameBuffer.cpp:508] Graphics API Version OpenGL ES 3.0 (4.5.0 NVIDIA 32.7.3)
I0915 14:29:23.909983   98752 FrameBuffer.cpp:509] Graphics API Extensions GL_OES_EGL_sync GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint GL_OES_texture_float GL_OES_texture_float_linear GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_packed_depth_stencil GL_OES_vertex_half_float GL_OES_texture_npot GL_OES_rgb8_rgba8 GL_OVR_multiview2 GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_texture_format_BGRA8888 GL_APPLE_texture_format_BGRA8888 GL_EXT_texture_buffer
I0915 14:29:23.910022   98752 FrameBuffer.cpp:510] Graphics Device Extensions N/A
OpenGL Vendor=[Google (NVIDIA Corporation)]OpenGL Renderer=[Android Emulator OpenGL ES Translator (NVIDIA Tegra X1 (nvgpu)/integrated)]OpenGL Version=[OpenGL ES 3.0 (4.5.0 NVIDIA 32.7.3)]Could not init `oss' audio driver
I0915 14:29:24.439422   98794 FrameBuffer.cpp:2853] setDisplayConfigs w 320 h 640 dpiX 160 dpiY 160
I0915 14:29:24.439551   98794 FrameBuffer.cpp:2866] setDisplayActiveConfig 0
WARNING | FeatureControl is requesting a non existing feature.
WARNING | Cold boot: requested by the user

Screenshot_2024-09-15_13-46-59

And after compiling ANGLE and the library libshadertranslator.so,I've been able to use the native GPU of the Jetson Nano with Android 13 using these parameters...

$ emulator @android13 -cores 2 -lowram -memory 1000 -gpu host -ports 5554,5555 -skip-adb-auth -no-boot-anim -no-snapshot -no-metrics -qemu -machine gic-version=2

@Marietto2008
Copy link

Marietto2008 commented Oct 9, 2024

Instead,I haven't been able to boot succesfully Android Cuttlefish neither on top of Ubuntu 24.04 x64 bit nor on the Jetson Nano on arm64.

@backpapp
Copy link

backpapp commented Oct 9, 2024

Unfortunately not, I haven't found the time. I guess the fastest way to get it working would be to use netsimd from x86_64 emulator build and let the Rosetta do its magic.

I eventually used Ubuntu Server 24.04 LTS x86_64 (ami-001f2488b35ca8aad) on a c5n.metal with this script and it worked fine :

#!/bin/bash
echo "Updating package list..."
sudo apt update && echo "Package list updated." || echo "Failed to update package list."
echo "Upgrading installed packages..."
sudo apt upgrade -y && echo "Packages upgraded." || echo "Failed to upgrade packages."
echo "Installing required packages..."
yes | sudo apt install default-jdk python3-pip repo python-is-python3 unzip libpcre2-dev adb && echo "Required packages installed." || echo "Failed to install required packages."
echo "Downloading command line tools..."
wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip && echo "Command line tools downloaded." || echo "Failed to download command line tools."
echo "Unzipping command line tools..."
unzip commandlinetools-linux-11076708_latest.zip -d android-sdk && echo "Command line tools unzipped." || echo "Failed to unzip command line tools."
echo "Moving command line tools to /opt..."
sudo mv android-sdk /opt/ && echo "Moved command line tools to /opt." || echo "Failed to move command line tools."
echo "Creating cmdline-tools directory..."
mkdir -p /opt/android-sdk/cmdline-tools/latest && echo "Cmdline-tools directory created." || echo "Failed to create cmdline-tools directory."
echo "Moving files to the latest cmdline-tools directory..."
mv /opt/android-sdk/cmdline-tools/* /opt/android-sdk/cmdline-tools/latest && echo "Moved files to latest cmdline-tools directory." || echo "Failed to move files to latest cmdline-tools directory."
echo "Setting up environment variables..."
echo "export ANDROID_SDK_ROOT=/opt/android-sdk" >> ~/.bashrc
echo "export ANDROID_HOME=/opt/android-sdk" >> ~/.bashrc
echo "export ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=60" >> ~/.bashrc
echo "export PATH=\$PATH:/opt/android-sdk/cmdline-tools/latest/bin" >> ~/.bashrc
echo "Sourcing .bashrc to apply changes..."
source ~/.bashrc
echo "Updating sdkmanager..."
sdkmanager --update && echo "Sdkmanager updated." || echo "Failed to update sdkmanager."
echo "Accepting licenses..."
yes | sdkmanager --licenses && echo "Licenses accepted." || echo "Failed to accept licenses."
echo "Changing directory to /opt/android-sdk..."
cd /opt/android-sdk/ && echo "Changed directory to /opt/android-sdk." || echo "Failed to change directory."
echo "Installing emulator..."
sdkmanager "emulator" && echo "Emulator installed." || echo "Failed to install emulator."
echo "Installing system images..."
sdkmanager "system-images;android-31;google_apis;x86_64" && echo "System images installed." || echo "Failed to install system images."
echo "Creating AVD..."
no | avdmanager -v create avd -f -n Pixel4 -k "system-images;android-31;google_apis;x86_64" -p "/opt/android-sdk/avd" && echo "AVD created." || echo "Failed to create AVD."
echo "Creating directories for platforms and platform-tools..."
mkdir -p /opt/android-sdk/platforms && echo "Platforms directory created." || echo "Failed to create platforms directory."
mkdir -p /opt/android-sdk/platform-tools && echo "Platform-tools directory created." || echo "Failed to create platform-tools directory."
echo "Setting Vulkan and GLDirectMem options..."
echo "Vulkan = off" >> ~/.android/advancedFeatures.ini
echo "GLDirectMem = on" >> ~/.android/advancedFeatures.ini
echo "Configuration for Vulkan and GLDirectMem set."
sudo gpasswd -a $USER kvm
echo "Script execution completed."

echo "logout and re-login"
echo "Then start an emulator using : /opt/android-sdk/emulator/emulator @Pixel4 -no-window -no-audio -ports 5554,5555 -skip-adb-auth -no-boot-anim -show-kernel"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment