We are now ready to build Android. Let's go to the directory where we downloaded Android and configure the build system:
$ cd ~/android/aosp-2.3.x
$ . build/envsetup.sh
$ lunch
You're building on Linux Lunch menu... pick a combo: 1. generic-eng 2. simulator
3. full_passion-userdebug 4. full_crespo4g-userdebug 5. full_crespo-userdebug
Which would you like? [generic-eng] ENTER
============================================ PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.3.4 TARGET_PRODUCT=generic TARGET_BUILD_VARIANT=eng TARGET_SIMULATOR=false TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm HOST_ARCH=x86 HOST_OS=linux HOST_BUILD_TYPE=release BUILD_ID=GINGERBREAD ============================================
Note that we typed a period (.), SPACE , and then build/envsetup.sh. This forces the shell to run the envsetup.sh script within the current shell. If we were to just run the script, the shell would spawn a new shell and run the script in that new shell. That would be useless since envsetup.sh defines new shell commands, such as lunch, and sets up environment variables required for the rest of the build.
We will explore envsetup.sh and lunch in more detail later. For the moment, though, note that the generic-eng combo means that we configured the build system to create images for running in the Android emulator. This is the same QEMU emulator software used by app developers to test their apps when developing using the SDK on a work- station, albeit here it will be running our own custom images instead of the default ones shipped with the SDK. It's also the same emulator that was used by the Android de- velopment team to develop Android while there were no devices for it yet. So while it's not real hardware and is therefore by no means a pefect target, it's still more than sufficient to cover most of the terrain we need to cover. Once you know your specific target, you should be able to adapt the instructions found in the rest of this book, with possibly some help from the book Building Embedded Linux Systems, to get your custom Android images loaded on your device and your hardware to boot them.
Now that the environment has been set up, we can actually build Android:
$ make -j16 ============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=2.3.4 TARGET_PRODUCT=generic TARGET_BUILD_VARIANT=eng TARGET_SIMULATOR=false TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm HOST_ARCH=x86 HOST_OS=linux HOST_BUILD_TYPE=release BUILD_ID=GINGERBREAD ============================================ Checking build tools versions...
find: `frameworks/base/frameworks/base/docs/html': No such file or directory find: `out/target/common/docs/gen': No such file or directory
find: `frameworks/base/frameworks/base/docs/html': No such file or directory find: `out/target/common/docs/gen': No such file or directory
find: `frameworks/base/frameworks/base/docs/html': No such file or directory find: `out/target/common/docs/gen': No such file or directory
find: `frameworks/base/frameworks/base/docs/html': No such file or directory find: `out/target/common/docs/gen': No such file or directory
find: `frameworks/base/frameworks/base/docs/html': No such file or directory find: `out/target/common/docs/gen': No such file or directory
host Java: apicheck (out/host/common/obj/JAVA_LIBRARIES/apicheck_intermediates/classes) Header: out/host/linux-x86/obj/include/libexpat/expat.h Header: out/host/linux-x86/obj/include/libexpat/expat_external.h Header: out/target/product/generic/obj/include/libexpat/expat.h Header: out/target/product/generic/obj/include/libexpat/expat_external.h Header: out/host/linux-x86/obj/include/libpng/png.h Header: out/host/linux-x86/obj/include/libpng/pngconf.h Header: out/host/linux-x86/obj/include/libpng/pngusr.h Header: out/target/product/generic/obj/include/libpng/png.h Header: out/target/product/generic/obj/include/libpng/pngconf.h Header: out/target/product/generic/obj/include/libpng/pngusr.h Header: out/target/product/generic/obj/include/libwpa_client/wpa_ctrl.h Header: out/target/product/generic/obj/include/libsonivox/eas_types.h Header: out/target/product/generic/obj/include/libsonivox/eas.h Header: out/target/product/generic/obj/include/libsonivox/eas_reverb.h Header: out/target/product/generic/obj/include/libsonivox/jet.h Header: out/target/product/generic/obj/include/libsonivox/ARM_synth_constants_gnu.inc host Java: clearsilver (out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/classes) target Java: core (out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes)
host Java: dx (out/host/common/obj/JAVA_LIBRARIES/dx_intermediates/classes) Notice file: frameworks/base/libs/utils/NOTICE -- out/host/linux-x86/obj /NOTICE_FILES/src//lib/libutils.a.txt
Notice file: system/core/libcutils/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//lib /libcutils.a.txt
...
Now is a good time to go for a snack or watch tonight's hockey game.‡ On a more
serious note, though, your build time will obviously depend on your system's capabil- ities. On a laptop equiped with a quad-core CORE i7 Intel processor with hyper- threading enabled and 8GB of RAM, this actua command will take about 20 minutes to build the AOSP. On an older laptop with a dual-core Centro 2 Intel processor and 2GB of RAM, a make -j4 would take about an hour to build the same AOSP. Note that the -j parameter of make allows you to specify how many jobs to run in parallel. Some say that it's best to use your number of processors times 2, which is what I'm doing here. Others say it's best to add 2 to the number of processors you have. Following that advice, I would've used 10 and 4 instead of 16 and 4.