Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build a custom kernel for Android emulator
git clone https://android.googlesource.com/kernel/goldfish/ -b android-goldfish-3.18
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9
cd goldfish
export CROSS_COMPILE=x86_64-linux-android-
export ARCH=x86_64
export PATH=$PATH:/path/to/x86_64-linux-android-4.9/bin
make x86_64_ranchu_defconfig
make menuconfig  # enable overlayfs and namespaces support here
make -j8

Then create an Android virtual device via android avd. Here I use x86-64 image for API 24 (7.0 Nougat). Don't forget to use a larger internal memory size when creating the virtual device. (The default is 200MB and I use 2000MB) After that run the emulator with:

emulator -avd (avd_name) -kernel /path/to/goldfish/arch/x86/boot/bzImage -show-kernel
@palratnesh05
Copy link

palratnesh05 commented Mar 29, 2019

Hi I did not find #enable overlayfs and namespaces support here in menu

rudra@rudra-ThinkPad-E470:~/aosp7/goldfish$ make menuconfig
HOSTCC scripts/kconfig/mconf.o
HOSTCC scripts/kconfig/lxdialog/checklist.o
HOSTCC scripts/kconfig/lxdialog/util.o
HOSTCC scripts/kconfig/lxdialog/inputbox.o
HOSTCC scripts/kconfig/lxdialog/textbox.o
HOSTCC scripts/kconfig/lxdialog/yesno.o
HOSTCC scripts/kconfig/lxdialog/menubox.o
HOSTLD scripts/kconfig/mconf
scripts/kconfig/mconf Kconfig

*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.

make completed successfully (02:23 (mm:ss))

rudra@rudra-ThinkPad-E470:~/aosp7/goldfish$ make -j4
make: x86_64-linux-android-gcc: Command not found
scripts/kconfig/conf --silentoldconfig Kconfig
make: x86_64-linux-android-gcc: Command not found
SYSHDR arch/x86/syscalls/../include/generated/asm/unistd_32_ia32.h
SYSTBL arch/x86/syscalls/../include/generated/asm/syscalls_32.h
HOSTCC scripts/basic/bin2c
CHK include/config/kernel.release
UPD include/config/kernel.release
SYSHDR arch/x86/syscalls/../include/generated/asm/unistd_64_x32.h
SYSTBL arch/x86/syscalls/../include/generated/asm/syscalls_64.h
WRAP arch/x86/include/generated/asm/clkdev.h
WRAP arch/x86/include/generated/asm/cputime.h
WRAP arch/x86/include/generated/asm/dma-contiguous.h
WRAP arch/x86/include/generated/asm/early_ioremap.h
WRAP arch/x86/include/generated/asm/mcs_spinlock.h
WRAP arch/x86/include/generated/asm/scatterlist.h
SYSHDR arch/x86/syscalls/../include/generated/uapi/asm/unistd_32.h
CHK include/generated/uapi/linux/version.h
UPD include/generated/uapi/linux/version.h
SYSHDR arch/x86/syscalls/../include/generated/uapi/asm/unistd_64.h
CHK include/generated/utsrelease.h
HOSTCC scripts/genksyms/genksyms.o
UPD include/generated/utsrelease.h
SHIPPED scripts/genksyms/parse.tab.c
SYSHDR arch/x86/syscalls/../include/generated/uapi/asm/unistd_x32.h
CC scripts/mod/empty.o
/bin/sh: 1: x86_64-linux-android-gcc: not found
scripts/Makefile.build:257: recipe for target 'scripts/mod/empty.o' failed
make[2]: *** [scripts/mod/empty.o] Error 127
scripts/Makefile.build:402: recipe for target 'scripts/mod' failed
make[1]: *** [scripts/mod] Error 2
make[1]: *** Waiting for unfinished jobs....
SHIPPED scripts/genksyms/lex.lex.c
SHIPPED scripts/genksyms/keywords.hash.c
SHIPPED scripts/genksyms/parse.tab.h
HOSTCC scripts/genksyms/parse.tab.o
kernel/Makefile:145: *** No X.509 certificates found ***
HOSTCC scripts/genksyms/lex.lex.o
HOSTLD scripts/genksyms/genksyms
Makefile:556: recipe for target 'scripts' failed
make: *** [scripts] Error 2
make: *** Waiting for unfinished jobs....

make failed to build some targets (2 seconds)

please help me how to resolve this problem?

@PGoski
Copy link

PGoski commented Jan 19, 2020

rudra@rudra-ThinkPad-E470:~/aosp7/goldfish$ make -j4
make: x86_64-linux-android-gcc: Command not found

checkout the correct branch in x86_64-linux-android-4.9 repository:

  1. cd x86_64-linux-android-4.9
  2. git checkout pie-b4s4-release

now kernel should start compiling

@johnnyboy18
Copy link

johnnyboy18 commented Jan 23, 2020

rudra@rudra-ThinkPad-E470:~/aosp7/goldfish$ make -j4
make: x86_64-linux-android-gcc: Command not found

checkout the correct branch in x86_64-linux-android-4.9 repository:

1. cd x86_64-linux-android-4.9

2. git checkout pie-b4s4-release

now kernel should start compiling

Thank You!

@ysun
Copy link

ysun commented May 6, 2020

Hi, as Android kernel is moving on to v5.4, do you have guide to boot Android emulator with customized kernel v5.4 ?
As I know, latest kernel use clang instead of gcc to compile. And android 5.4 have dozens of modules (.ko) packaged in ramdisk, which make it difficult to customize kernel.

@newbit1
Copy link

newbit1 commented Apr 21, 2021

Hi, as Android kernel is moving on to v5.4, do you have guide to boot Android emulator with customized kernel v5.4 ?
As I know, latest kernel use clang instead of gcc to compile. And android 5.4 have dozens of modules (.ko) packaged in ramdisk, which make it difficult to customize kernel.

Hi, I know your post was a while ago, but I ran into the same issue and fixed it. Check out my script rootAVD, there is a little Guide linked to XDA, on how to compile the AVD Kernel, its Modules and install the Modules into the ramdisk.img
It also installs Magisk on the same shot.

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