Skip to content

Instantly share code, notes, and snippets.

@jhonatasfender
Created March 18, 2019 22:53
Show Gist options
  • Save jhonatasfender/cc219e844beaef870c4cec2599bf1537 to your computer and use it in GitHub Desktop.
Save jhonatasfender/cc219e844beaef870c4cec2599bf1537 to your computer and use it in GitHub Desktop.
para inicializar repositório do android
# Download the source. Takes several minutes.
# curl https://storage.googleapis.com/git-repo-downloads/repo >repo
# chmod a+x repo
# rm -rfd /var/www/android
mkdir /var/www/android-test
cd /var/www/android-test
export USE_CCACHE=1
ccache -M 90G
# repo init -b master --depth 1 -u https://android.googlesource.com/platform/manifest
repo init -u https://android.googlesource.com/platform/manifest
# repo sync -f --force-sync --no-clone-bundle --no-tags -j$(nproc --all)
repo sync
# Do the actual build. Takes minutes / hours.
. build/envsetup.sh
# lunch aosp_x86_64-eng
lunch aosp_arm-eng
USE_CCACHE=1 CCACHE_DIR=ccache make -j$(nproc --all)
# . build/envsetup.sh
# set_stuff_for_environment
# lunch full-eng
# lunch aosp_arm-eng
# make -j$(nproc --all)
# make clobber
# export JAVA_OPTS="-Xms512m -Xmx512m -XX:MaxPermSize=256m"
# Run the emulator.
# emulator -show-kernel
# util
# make clobber && . build/envsetup.sh && lunch aosp_x86_64-eng && USE_CCACHE=1 CCACHE_DIR=ccache make -j $(($(nproc) - 2))
# build/envsetup.sh && lunch aosp_x86_64-eng && USE_CCACHE=1 CCACHE_DIR=ccache make -j $(($(nproc) - 2))
# apt-get install build-essential zlib1g-dev pkg-config libglib2.0-dev binutils-dev libboost-all-dev autoconf libtool libssl-dev libpixman-1-dev libpython-dev python-pip python-capstone virtualenv
# sudo apt-get install libsdl1.2-dev libsdl1.2debian libsdl-gfx1.2-5 libsdl-gfx1.2-dev libsdl-gfx1.2-doc libsdl-image1.2 libsdl-image1.2-dbg libsdl-image1.2-dev libsdl-mixer1.2 libsdl-mixer1.2-dbg libsdl-mixer1.2-dev libsdl-net1.2 libsdl-net1.2-dbg libsdl-net1.2-dev libsdl-sound1.2 libsdl-sound1.2-dev libsdl-ttf2.0-0 libsdl-ttf2.0-dev
# sudo apt-get install libgtk-3-dev libspice-server-dev libusb-1.0-0-dev libusbredirparser-dev
# sudo apt install autoconf gcc-aarch64-linux-gnu libaio-dev libbluetooth-dev libbrlapi-dev libbz2-dev libcap-dev libcap-ng-dev libcurl4-gnutls-dev libepoxy-dev libfdt-dev libgbm-dev libgles2-mesa-dev libglib2.0-dev libibverbs-dev libjpeg8-dev liblzo2-dev libncurses5-dev libnuma-dev librbd-dev librdmacm-dev libsasl2-dev libsdl1.2-dev libsdl2-dev libseccomp-dev libsnappy-dev libssh2-1-dev libtool libusb-1.0-0 libusb-1.0-0-dev libvde-dev libvdeplug-dev libxen-dev valgrind xfslibs-dev xutils-dev zlib1g-dev
# Lunch menu... pick a combo:
# 1. aosp_arm-eng
# 2. aosp_arm64-eng
# 3. aosp_blueline-userdebug
# 4. aosp_car_arm-userdebug
# 5. aosp_car_arm64-userdebug
# 6. aosp_car_x86-userdebug
# 7. aosp_car_x86_64-userdebug
# 8. aosp_cf_x86_64_auto-userdebug
# 9. aosp_cf_x86_64_phone-userdebug
# 10. aosp_cf_x86_64_tablet-userdebug
# 11. aosp_cf_x86_64_tablet_3g-userdebug
# 12. aosp_cf_x86_64_tv-userdebug
# 13. aosp_cf_x86_64_wear-userdebug
# 14. aosp_cf_x86_auto-userdebug
# 15. aosp_cf_x86_phone-userdebug
# 16. aosp_cf_x86_tablet-userdebug
# 17. aosp_cf_x86_tablet_3g-userdebug
# 18. aosp_cf_x86_tv-userdebug
# 19. aosp_cf_x86_wear-userdebug
# 20. aosp_crosshatch-userdebug
# 21. aosp_marlin-userdebug
# 22. aosp_sailfish-userdebug
# 23. aosp_taimen-userdebug
# 24. aosp_walleye-userdebug
# 25. aosp_walleye_test-userdebug
# 26. aosp_x86-eng
# 27. aosp_x86_64-eng
# 28. beagle_x15-userdebug
# 29. fuchsia_arm64-eng
# 30. fuchsia_x86_64-eng
# 31. hikey-userdebug
# 32. hikey64_only-userdebug
# 33. hikey960-userdebug
# 34. hikey960_tv-userdebug
# 35. hikey_tv-userdebug
# 36. m_e_arm-userdebug
# 37. mini_emulator_arm64-userdebug
# 38. mini_emulator_x86-userdebug
# 39. mini_emulator_x86_64-userdebug
# 40. poplar-eng
# 41. poplar-user
# 42. poplar-userdebug
# 43. qemu_trusty_arm64-userdebug
# 44. uml-userdebug
# HomeNews & BlogBlogBuilding Android for Qemu: A Step-by-Step Guide
# Building Android for Qemu: A Step-by-Step Guide
# Robert Foss avatar Posted on 02/09/2016 by Robert Foss
# Share this post: Share on Twitter Share on LinkedIn Share on Facebook Share on Google + Share on Email
# Alt text
# Note: This guide only applies to aosp version 6.x.x, and has never been tested with anything else. It is unlikely to work with aosp 7.x.x, and will definitely not work with >8.x.x.
# Developing Linux for Android on Qemu allows you to do some things that are not necessarily possible using the stock emulator. For my purposes I need access to a GPU and be able to modify the driver, which is where Virgilrenderer and Qemu comes in handy.
# The guide below helps you compile Android and run it on top of Qemu with Mesa/Virgilrenderer supplying a virtual GPU. Because of this, the following guide is aimed at Linux hosts.
# This guide is based on Rob Herrings fantastic guide, but has been slightly streamlined and had physical hardware support stripped out.
# Install dependencies
# These dependencies were available on Ubuntu 16.04, some alternative packages might be needed for other distributions.
# sudo apt install autoconf gcc-aarch64-linux-gnu libaio-dev libbluetooth-dev libbrlapi-dev libbz2-dev libcap-dev libcap-ng-dev libcurl4-gnutls-dev libepoxy-dev libfdt-dev libgbm-dev libgles2-mesa-dev libglib2.0-dev libibverbs-dev libjpeg8-dev liblzo2-dev libncurses5-dev libnuma-dev librbd-dev librdmacm-dev libsasl2-dev libsdl1.2-dev libsdl2-dev libseccomp-dev libsnappy-dev libssh2-1-dev libtool libusb-1.0-0 libusb-1.0-0-dev libvde-dev libvdeplug-dev libvte-2.90-dev libxen-dev valgrind xfslibs-dev xutils-dev zlib1g-dev
# Set up paths
# Naturally all of the paths below are configurable, this is just what I used.
# export PROJECT_PATH="/var/www/qemu_android"
# export VIRGLRENDERER_PATH="${PROJECT_PATH}/virglrenderer"
# export QEMU_PATH="${PROJECT_PATH}/qemu"
# export LINUX_PATH="${PROJECT_PATH}/linux"
# export ANDROID_PATH="${PROJECT_PATH}/android"
# export ANDROID_TOOLS_PATH="${PROJECT_PATH}/android-tools"
# Virglrenderer
# Virglrenderer creates a virtual 3D GPU, that allows the Qemu guest to use the graphics capabilities of the host machine.
# git clone git://git.freedesktop.org/git/virglrenderer ${VIRGLRENDERER_PATH}
# cd ${VIRGLRENDERER_PATH}
# ./autogen.sh
# make
# sudo make install
# Qemu
# Qemu is a full system emulator, and supports a multitude of machine architectures. We're going to to use x86_64 but also build support for arm64/aarch64.
# git clone git://git.qemu-project.org/qemu.git ${QEMU_PATH}
# mkdir ${QEMU_PATH}/build
# cd ${QEMU_PATH}/build
# ../configure --target-list=aarch64-softmmu,x86_64-softmmu --enable-gtk --with-gtkabi=3.0 --enable-kvm
# make -j
# Linux kernel
# Build trunk of mainline linux kernel.
# Important: The below instructions use upstream/master but during testing of this guide, https://git.kernel.org/pub/scm/linux/kernel/git/padovan/linux.git and the fences branch was used due to SW_SYNC not yet being included in upstream. Inclusion is targeted for v4.9.
# git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ${LINUX_PATH}
# cd ${LINUX_PATH}
# wget http://memcpy.io/files/2016-08-30/Kconfig -O ${LINUX_PATH}/.config
# make oldconfig
# make -j
# Important: If you decide not to use the .config linked in this step, a few Kconfig options need to be set:
# CONFIG_ANDROID=y
# CONFIG_ANDROID_BINDER_IPC=y
# CONFIG_AUDIT=y
# CONFIG_HAVE_ARCH_AUDITSYSCALL=y
# CONFIG_AUDITSYSCALL=y
# CONFIG_AUDIT_WATCH=y
# CONFIG_AUDIT_TREE=y
# CONFIG_SECURITY_SELINUX=y
# CONFIG_SECURITY_SELINUX_BOOTPARAM=y
# CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=1
# CONFIG_SECURITY_SELINUX_DISABLE=y
# CONFIG_SECURITY_SELINUX_DEVELOP=y
# CONFIG_SECURITY_SELINUX_AVC_STATS=y
# CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE=0
# CONFIG_DEFAULT_SECURITY_SELINUX=y
# CONFIG_DEFAULT_SECURITY="selinux"
# CONFIG_VIRTIO_BLK=y
# CONFIG_SCSI_VIRTIO=y
# CONFIG_VIRTIO_NET=y
# CONFIG_VIRTIO_CONSOLE=y
# CONFIG_HW_RANDOM_VIRTIO=y
# CONFIG_DRM_VIRTIO_GPU=y
# CONFIG_VIRT_DRIVERS=y
# CONFIG_VIRTIO=y
# CONFIG_VIRTIO_PCI=y
# CONFIG_VIRTIO_PCI_LEGACY=y
# CONFIG_VIRTIO_BALLOON=y
# CONFIG_VIRTIO_INPUT=y
# CONFIG_VIRTIO_MMIO=y
# CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
# CONFIG_NET_9P=y
# CONFIG_NET_9P_VIRTIO=y
# CONFIG_SYNC=y
# CONFIG_SW_SYNC=y
# CONFIG_SYNC_FILE=y
# Android
# Build the Android Open Source Project.
# Important: When running source build/envsetup.sh make sure that you are using bash. I had issues running lunch using zsh.
# mkdir ${ANDROID_PATH}
# cd ${ANDROID_PATH}
# repo init -u https://android.googlesource.com/platform/manifest -b master
# cd .repo
# git clone https://github.com/robherring/android_manifest.git -b android-6.0 local_manifests
# cd ..
# repo sync -j
# cd device/linaro/generic
# make defconfig
# make all
# cd ../../..
# # The following snippet must be run in bash
# bash
# source build/envsetup.sh
# # Select linaro_x86_64-userdebug
# lunch
# make -j
# # We don't need to use bash any longer
# exit
# As of this writing SW_SYNC related patches by Gustavo Padovan has yet to be included into AOSP, and therefore has to be included included manually until it is upstreamed. After switching to this branch, the AOSP project has to be rebuilt again.
# cd ${ANDROID_PATH}/external/drm_hwcomposer
# git remote add padovan git://git.collabora.com/git/user/padovan/android-system-core.git
# git fetch padovan
# git checkout padovan/master
# mkbootimg
# Fetch the make boot image script. This script later assembles the boot image, boot.img.
# git clone https://android.googlesource.com/platform/system/core.git $ANDROID_TOOLS_PATH
# Run Qemu machine
# When running the below script, make sure that the all of the paths from step two have been exported.
# wget http://memcpy.io/files/2016-08-30/boot_android_qemu.sh -O ${PROJECT_PATH}/boot_android_qemu.sh
# chmod +x ${PROJECT_PATH}/boot_android_qemu.sh
# ${PROJECT_PATH}/boot_android_qemu.sh x86_64
# Conclusion
# Hopefully this guide will have enabled you build the required software and run Android on Qemu with a virtual GPU. The post was has been a part of work undertaken by my employer Collabora.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment