Skip to content

Instantly share code, notes, and snippets.

@yan12125
Created April 14, 2017 17:32
Show Gist options
  • Save yan12125/78a9004acb1bed5faf2ffd442163e2ef to your computer and use it in GitHub Desktop.
Save yan12125/78a9004acb1bed5faf2ffd442163e2ef to your computer and use it in GitHub Desktop.
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
@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

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.

@demian-mint
Copy link

i have a black screen after start

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