How to compile Android AOSP core and test it with Android emulator?

Has anyone successfully compiled the Android kernel and tested it in the Android emulator, and if so, is there something special that needs to be done?

The documentation for the SDK is excellent, but the documentation for compiling the kernel and setting up the user machine in the emulator is hard for me to find.

+51
android android-emulator emulation android-source
Nov 27 '09 at 16:59
source share
8 answers

Since August 2009, the kernel is no longer part of the standard repo manifest that you get when you follow the instructions to download the source code for an Android open source project. The steps required to successfully load, build, and run a specific kernel on the emulator are as follows:

  • Get the Android kernel either by adding it to the repo manifest or manually by doing:
    git clone https://android.googlesource.com/kernel/goldfish.git
  • Check the correct branch for working with the emulator, i.e. goldfish:
    git checkout -t origin/android-goldfish-2.6.29 -b goldfish
  • Create the emulator configuration (the qemu emulator runs the command code, i.e. the console):
    make ARCH=arm goldfish_defconfig
    • If this does not work, try make ARCH=arm goldfish_armv7_defconfig
  • Now create the kernel using the cross-compilation tools distributed with the open source project:
    make ARCH=arm CROSS_COMPILE=mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
  • The kernel built in this way should get into the arch / arm / boot folder of your kernel tree (where you put the code from git clone)
  • To run the emulator with your kernel, there are two alternatives: either copy it to the previously created open source project kernel folder to replace the standard kernel. Another option is to run the emulator using the kernel option:
    emulator -kernel mydroid/kernel/common/arch/arm/boot/zImage

Please note that I used the default paths in the above description, you need to change them to what is relevant to your setting. It's been a while since I last tested it, but I think it should work.

Additional information: In the standard open-source distribution of Android, the kernel is distributed as a pre-built binary in the mydroid/prebuilt/android-arm/kernel folder, and the source code is not included. The kernel outcome was removed from the default manifest for two reasons. One of them is that the platform components require a lot of bandwidth and disk space, with which most people will not work with great difficulty. Another reason is that since the kernel is built using the kernel build system, and not as part of the aosp build system, it makes sense to separate it. A common branch for the kernel is the one used by the emulator. There are also branches for experimental, msm (Qualcomm platform) and Omap (TI platform), and possibly a few more. If you want to use the Android kernel with hardware, this may be more interesting to you.

+55
Feb 17 '10 at 9:26 a.m.
source share

Just to fix a few things from the BMB post (it was very useful for me, it saved my project):

  • git clone git: //android.git.kernel.org/kernel/common.git (kernel skipped);
  • git checkout -t origin / android-goldfish-2.6.29 -b goldfish (same);
  • make ARCH = arm goldfish_defconfig (idem);
  • make ARCH = arm CROSS_COMPILE = mydroid / prebuilt / linux-x86 / toolchain / arm-eabi-4.2.1 / bin / arm-eabi- (idem)
  • emulator -avd my_avd -kernel mydroid / kernel / common / arch / arm / boot / zImage (here I added avd to the command, this did not work without me).

+19
Jul 20 '10 at 16:45
source share

Fully automated Android 8.1 guest on Ubuntu 17.10 host

 # Download the source. Takes several minutes. curl https://storage.googleapis.com/git-repo-downloads/repo >repo chmod a+x repo ./repo init -b android-8.1.0_r1 --depth 1 -u https://android.googlesource.com/platform/manifest ./repo sync -c -j $(($(nproc) - 2)) --no-tags --no-clone-bundle # Do the actual build. Takes minutes / hours. . build/envsetup.sh lunch aosp_x86_64-eng USE_CCACHE=1 CCACHE_DIR=ccache make -j $(($(nproc) - 2)) # Run the emulator. emulator -show-kernel 

The out/ build directory is about 90 GB, and the rest of the tree is about 40 GB, with the exception of CCACHE.

1-2 minutes after starting the emulator, the main screen displays:

Lu8vJ.png

and if you press Enter on the host terminal from which Android was launched, you will get a shell for the Android system on the host terminal:

enter image description here

Notes:

  • ./repo init -b MUST point to a tag . the master branch is always broken, as are the -release branches.

    A list of tags can be found at: https://android.googlesource.com/platform/manifest or by cloning this repo.

    There are probably two reasons why branches always break:

    • Android is being developed behind closed doors and the code has crashed. Therefore, Google and OEM developers already have tons of paches on top of the public wizard and have already fixed the problem.

      For the same reason, it is probably futile to try to report any build errors to master: they have already been registered and fixed. In addition, I dare you to even find a suitable official place to report assembly failures.

    • repo sync on a branch simply retrieves any latest version of all 650 git repositories that make up the AOSP for that branch, without synchronizing them as submodules. Therefore, nothing guarantees their compatibility. However, tags retrieve the specific tag of all repositories.

  • --depth 1 and sync -c --no-tags --no-clone-bundle were an attempt to speed up a painfully slow clone. Not sure how successful it was. See also: AOSP repository synchronization takes too long

  • We use lunch aosp_x86_64-eng instead of ARM because it works much faster thanks to x86 host virtualization extensions.

    Instead, to create an ARM version, simply use lunch aosp_arm-eng .

    In addition, the ARM image is buggy, perhaps due to slowness? When the GUI starts up (if you're lucky), it shows "The system interface is not responding." See also: Process system not responding in Android emulator

  • -show-kernel binds the terminal to the serial -show-kernel , that is, you see boot messages and at the end you get a shell, which is very useful for debugging.

  • type emulator shows that it is simply an alias for emulator with no arguments. Run custom ROM on Android Emulator will ask how to pass some arguments to explicitly select your ROM.

    -help emulator -help surprisingly insightful:

     emulator -help emulator -help-build-images emulator -help-disk-images 

    You can determine the exact QEMU command line arguments specified with:

     emulator -verbose | grep 'emulator: argv' 

    as mentioned on: How to show what options are passed to QEMU when the Android emulator starts?

    Some user options are shown here, such as -android-hw , so they should be forked. QEMU: QEMU vs. Android emulator: command line options The source moves every 5 minutes, obviously: Changing the source code of the Android emulator

+11
Jan 17 '18 at 21:09
source share

This update is for BMB and Arnaud LM answers.
It seems goldfish have been changed since 2011/03/03. When checking out a golden fish branch, use this:

 git checkout -t origin/archive/android-gldfish-2.6.29 -b goldfish 

Note the lack of "o" in android-gldfish-2.6.29!

Hope this saves time for someone.

+8
Mar 03 '11 at 23:08
source share

Since 2012, kernel downloads have been well documented at source.google.com, however I found that it took several attempts to compile it. Here are the commands I used to build the kernel for the ARM emulator:

 cd /kernel/source/root make mrproper adb pull /proc/config.gz # from the emulator gunzip config mv config .config # now you have a (perhaps slightly outdated kernel .config) make ARCH=arm silentoldconfig # update the .config - take the defaults if prompted make ARCH=arm menuconfig # make any further changes time make -j4 ARCH=arm CROSS_COMPILE=/path/to/android/source/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- 2>&1 | tee ../../logs/$(date +%Y%m%d-%H%M)-make-kernel.log emulator -kernel /kernel/source/root/kernel/goldfish/arch/arm/boot/zImage -avd myAVD & 

Thanks to everyone who answered this question - I was able to do this with pieces and answers. The "you need AVD" Amound was the last thing that caused me problems.

+8
May 03 '12 at 12:06 pm
source share

It is easy. Follow the instructions at http://source.android.com/download to get and compile source code for all of Android. It takes some time, but it is not so difficult.

Having built this, you will get the output in the <android>/out directory. In addition to the ROM images, there are many tools, including an emulator. My emulator is located in <android>/out/host/linux-x86/bin/emulator . Just set the environment variable named ANDROID_PRODUCT_OUT to <android>/out/target/product/generic , and then run the emulator without any parameters by running the compiled ROM.

+6
Nov 28 '09 at 12:56
source share

As of May 2012, I discovered that you cannot use 'goldfish_defconfig' to compile the kernel. You need to use goldfish_armv7_defconfig '. This explains why the JonnyLambada method for extracting the config from the emulator (for a previously created kernel) works and is necessary.

Goldfish_defconfig configures the kernel to run on an ARM 926 processor, but the emulator is configured to run as Coretex A8 (which is an ARM V7 processor). Therefore, you need to use the new defconfig if you want it to work (or pull the configuration from the emulator).

Just FYI.

+4
May 04 '12 at 17:33
source share

How I was able to download the AOSP rom that I compiled was to copy the system.img file, which was compiled to ~ / .android / avd / Froyo.avd / But when I extract system.img and add the root version of su and busybox, then redo system.img, the emulator does not load. I'm still trying to understand this part: S

+1
Sep 04 2018-10-09T00:
source share



All Articles