{"id":99,"date":"2020-04-05T18:49:44","date_gmt":"2020-04-06T01:49:44","guid":{"rendered":"http:\/\/junsun.net\/wordpress\/?p=99"},"modified":"2020-09-20T12:00:20","modified_gmt":"2020-09-20T19:00:20","slug":"how-to-build-run-android-cuttlefish-emulator-on-aws","status":"publish","type":"post","link":"https:\/\/junsun.net\/wordpress\/2020\/04\/how-to-build-run-android-cuttlefish-emulator-on-aws\/","title":{"rendered":"How to build\/run Android Cuttlefish emulator on AWS"},"content":{"rendered":"<h3>Background<\/h3>\n<p>Cuttlefish is new virtual-machine based Android emulator.\u00a0 Earlier I have written\u00a0 <a href=\"http:\/\/junsun.net\/wordpress\/2019\/09\/how-to-build-run-cuttlefish-on-pc-arm64\/\">an article<\/a> on how to build\/run it on PC and ARM64 machines.\u00a0 Towards the end of 2019, AWS has introduced a1.metal instance which allows KVM to run on their ARM64 machines.\u00a0 It opens the possibility of running cuttlefish on AWS (which itself opens <em>a lot<\/em> of possibilities!)<\/p>\n<p>The steps are similar to those I mentioned before.\u00a0 This article summarizes them here specifically for AWS a1.metal instance, running Ubuntu 19.10.<\/p>\n<h3>Build AOSP cuttlefish images on x86_64<\/h3>\n<p>This step is done on PC, while all the rest steps are done on AWS a1.metal instance.<\/p>\n<ul>\n<li>Refer to\u00a0<a href=\"https:\/\/source.android.com\/setup\/build\/building\">https:\/\/source.android.com\/setup\/build\/building<\/a> to set up your host machine<\/li>\n<li>Check out the source from master and build distribution packages, which will be transferred to a1.metal instance later.\u00a0 This step takes very loooong time.<\/li>\n<\/ul>\n<pre>mkdir cuttlefish<br \/>repo init -u https:\/\/android.googlesource.com\/platform\/manifest<br \/>repo sync -j8 <br \/>source build\/envsetup.sh<br \/>lunch aosp_cf_arm64_phone-userdebug<br \/>make dist<\/pre>\n<p>If you like to download from a branch and like to download as little as possible, the following command do so with android10-gsi branch without git history.<\/p>\n<pre>repo init --depth=1 -u https:\/\/android.googlesource.com\/platform\/manifest -b android10-gsi<br \/>repo sync  -f --force-sync --no-clone-bundle --no-tags -j$(nproc)<\/pre>\n<h3>Setup AWS a1.metal<\/h3>\n<p>Start an Ubuntu 19.10 instance on a1.metal.\u00a0 First,\u00a0 we install GUI for better debugging and viewing.\u00a0<\/p>\n<pre>sudo apt-get update -y <br \/>sudo apt-get install lxde xrdp -y<br \/>sudo passwd ubuntu<\/pre>\n<h3>Setup to run x86_64 binaries<\/h3>\n<p>Many tools (e.g., cros_vm) in cuttlefish are still built as x86_64 binaries, not as arm64.\u00a0 Current solution is to use qemu-user to run those binaries (*ouch!*).\u00a0 As such, we set up x86_64(amd64) as the secondary architecture on a1.metal.<\/p>\n<ul>\n<li>Override \/etc\/apt\/sources.list file with the following content<\/li>\n<\/ul>\n<pre>deb [arch=arm64,armhf] http:\/\/ports.ubuntu.com\/ubuntu-ports eoan main restricted universe multiverse<br \/>deb [arch=arm64,armhf] http:\/\/ports.ubuntu.com\/ubuntu-ports eoan-updates main restricted universe multiverse<br \/>deb [arch=arm64,armhf] http:\/\/ports.ubuntu.com\/ubuntu-ports eoan-backports main restricted universe multiverse<br \/>deb [arch=arm64,armhf] http:\/\/ports.ubuntu.com\/ubuntu-ports eoan-security main restricted universe multiverse<br \/>deb [arch=amd64] http:\/\/archive.ubuntu.com\/ubuntu\/ eoan main restricted universe multiverse<br \/>deb [arch=amd64] http:\/\/archive.ubuntu.com\/ubuntu\/ eoan-updates main restricted universe multiverse<br \/>deb [arch=amd64] http:\/\/archive.ubuntu.com\/ubuntu\/ eoan-backports main restricted universe multiverse<br \/>deb [arch=amd64] http:\/\/archive.ubuntu.com\/ubuntu\/ eoan-security main restricted universe multiverse<\/pre>\n<ul>\n<li>Install qemu-user-static and add amd64 secondary architecture<\/li>\n<\/ul>\n<div>\n<pre><code>sudo apt install qemu-user-static\n<\/code><code>sudo dpkg --add-architecture amd64<\/code><code>\n<\/code><code>sudo apt install libc6:amd64<\/code><\/pre>\n<\/div>\n<ul>\n<li>After this you should be able to run simple x86_64 binaries such as \u201ccat\u201d.\n<ul>\n<li>scp over &#8220;cat&#8221; program from your x86_64 linux machine<\/li>\n<li>it should run!<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>Build and install cuttlefish-common package<\/h3>\n<ul>\n<li>install packages needed for build<\/li>\n<\/ul>\n<pre><code>sudo apt install dpkg-dev<br \/>sudo apt install cdbs config-package-dev debhelper<\/code><\/pre>\n<ul>\n<li>Download and build<\/li>\n<\/ul>\n<pre><code>mkdir cuttlefish-common<br \/>cd cuttlefish-common<br \/>git clone https:\/\/github.com\/google\/android-cuttlefish.git<br \/>cd android-cuttlefish<br \/>dpkg-buildpackage --no-sign<br \/><\/code><\/pre>\n<ul>\n<li>Install<\/li>\n<\/ul>\n<pre><code>sudo apt install bridge-utils dnsmasq-base f2fs-tools libarchive-tools libfdt1 libwayland-client0 net-tools python2<br \/>sudo dpkg -i ..\/cuttlefish-common_0.9.13_arm64.deb<\/code><code><\/code><\/pre>\n<h3>Setup cuttlefish for running<\/h3>\n<ul>\n<li>copy (scp) the following \u00a0the files from x86_64 PC host:<\/li>\n<\/ul>\n<div>\n<pre><code>out\/dist\/aosp_cf_arm64_phone-img-eng.jsun.zip\n<\/code><code>out\/dist\/cvd-host_package.tar.gz<\/code><\/pre>\n<\/div>\n<ul>\n<li>untar cvd-host_package.tar.gz to ~\/cuttlefish\/host directory<\/li>\n<li>unzip the zip file to ~\/cuttlefish\/image directory<\/li>\n<li>Add user to proper groups before running; power off machine; then power on again.\u00a0<\/li>\n<\/ul>\n<div>\n<pre><code>sudo usermod -aG kvm $USER\n<\/code><code>sudo usermod -aG cvdnetwork $USER<\/code><\/pre>\n<\/div>\n<h3>Run Cuttlefish<\/h3>\n<p>You have 2 choices to view the screen of emulated Android device:<\/p>\n<ol>\n<li>Use remote desktop and view screen via local VNC connection to Cuttlefish emulator<\/li>\n<li>Use a web browser and view the screen via remote WebRTC connection<\/li>\n<\/ol>\n<h4>View via Local VNC<\/h4>\n<ul>\n<li>Start a remote desktop viewer and connect to your EC2 a1.metal instance (Note: you need to open port 3389)<\/li>\n<li><em><strong>Below steps are running on remote EC2 a1.metal instance via remote desktop<\/strong><\/em><\/li>\n<li>Start a LXTerminal and run the following commands to start cuttlefish<\/li>\n<\/ul>\n<div>\n<pre><code>export ANDROID_PRODUCT_OUT=~\/cuttlefish\/image\/\n<\/code><code>export ANDROID_HOST_OUT=~\/cuttlefish\/host\/\n<\/code><code>export PATH=$PATH:$ANDROID_HOST_OUT\/bin\n<\/code><code>launch_cvd -decompress_kernel=true<\/code><\/pre>\n<\/div>\n<ul>\n<li>Start browser and download VNC viewer\n<ul>\n<li>download tightvnc viewer (jar file): https:\/\/www.tightvnc.com\/download.php<\/li>\n<li>install java if not done yet: sudo apt install openjdk-11-jre<\/li>\n<\/ul>\n<\/li>\n<li>Start a second LXTerminal and run this command : java -jar tightvnc-jviewer.jar\n<ul>\n<li>Please use 127.0.0.1 as IP address and 6444 as port number<\/li>\n<\/ul>\n<\/li>\n<li>To stop cvd, run stop_cvd<\/li>\n<\/ul>\n<h4>View via WebRTC<\/h4>\n<ul>\n<li>Note you need to enable port 8443 on EC2 a1.metal instance<\/li>\n<li>On EC2 instance run<\/li>\n<\/ul>\n<pre>launch_cvd -start_webrtc -webrtc_public_ip=`curl http:\/\/169.254.169.254\/latest\/meta-data\/public-ipv4` -decompress_kernel=true<\/pre>\n<ul>\n<li>On local PC, start a browser on local machine, and connect via &#8220;https:\/\/&lt;public IP&gt;:8443&#8221;<\/li>\n<\/ul>\n<p><em>As of writing today (4\/5, 2020), the WebRTC method is not working yet.\u00a0 It shows a black screen.<\/em><\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background Cuttlefish is new virtual-machine based Android emulator.\u00a0 Earlier I have written\u00a0 an article on how to build\/run it on PC and ARM64 machines.\u00a0 Towards the end of 2019, AWS has introduced a1.metal instance which allows KVM to run on their ARM64 machines.\u00a0 It opens the possibility of running cuttlefish on AWS (which itself opens &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/junsun.net\/wordpress\/2020\/04\/how-to-build-run-android-cuttlefish-emulator-on-aws\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to build\/run Android Cuttlefish emulator on AWS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[3],"tags":[7,9,8,12,36],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts\/99"}],"collection":[{"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":18,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts\/99\/revisions\/179"}],"wp:attachment":[{"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}