Android source after downloading the directory as follows:
The size of the entire code is: 25.559GB.
First, build the system
The following instructions for building the Android source tree apply to all code branches, including the master branch.
1. Select a branch
Some requirements for building a system are determined by the version of the source code that will be selected for compilation. Use the URL http://source.android.com/source/build-numbers.html to view a list of all current Android branches. You can choose to download and build the latest source code (known as "Master"), in which case, when initializing the library, you can omit the specified branch parameters directly.
Once you have selected the branch, follow the commands below to build the system. The basic build command sequence is as follows:
2. Initialization
Use the envsetup.sh script to initialize the environment, and note that you can use "." Characters to replace the source. As follows:
[Plain]View Plaincopy
- $source build/envsetup.sh
Or
[Plain]View Plaincopy
- $ . build/envsetup.sh
and the latter short format is used more frequently in files.
3. Select a target
Use the lunch command to choose which target to build. The exact configuration can be passed as a parameter to the command, as follows:
[Plain]View Plaincopy
- $lunch Aosp_arm-eng
The above example specifies to build a completed emulator with all of its debugging enabled, after entering the command,
If there are no parameters behind the lunch, then a directory will allow you to choose the prompt. As follows:
All of the build targets are in the form of Build-buildtype, where build is the code name that represents a particular feature combination, as shown in the partial list:
and BuildType as follows:
For better information on building and running on real hardware, refer to: http://source.android.com/source/building-devices.html
4. Building Code
Using make to build everything, GNU makes can handle parallel tasks by using the-JN parameter. Here N, according to the hardware of the computer used to specify the number of cores, General n is specified as the CPU core 1 to twice times. For example, on a dual-5520 machine (2 CPUs, each CPU4 core, 2 threads per core), the fastest build is to use Make-j16 or make-j32.
[Plain]View Plaincopy
- $make-j4
5. Running
You can run the built Android system on the emulator, flash to the device, and notice that the target has been built using the lunch command. It is best not to run the target of the build on another different target.
1) simulate an Android device
Once the compilation is complete, set the environment variables and add the following variables to the Ete/profile:
Then, run the emulator by typing the following command:
[Plain]View Plaincopy
- $emulator
2) Flash to the device
For Flash to the device, you need to use FastBoot, which is included in your path after a successful build. At boot time, either manually place the device into FastBoot mode with the appropriate combination of keys. or enter FastBoot mode by entering the following command from the shell
[Plain]View Plaincopy
- $ADB reboot bootloader
Once the device is in FastBoot mode, run:
[Plain]View Plaincopy
- $fastboot flashall-w
The-w option is used to erase the/data portion of the device, which is useful for the first flash of a particular device, otherwise it is not required.
For more information about building and running on real hardware, see: http://source.android.com/source/building-devices.html
Second, the use of CCache
CCache is a compiler ccache for C and C + +. can make building faster. At the root of the source code, do the following:
[Plain]View Plaincopy
- $export use_ccache=1
- $export Ccache_dir=/<path_of_your_choice>/.ccache
- $prebuilts/misc/linux-x86/ccache/ccache-m 50G
The recommended cache size is 50-100g
You can use the following actions to see the size of the CCache used
[Plain]View Plaincopy
- $watch-n1-d Prebuilts/misc/linux-x86/ccache/ccache-s
If you use an ice Cream Sandwich (4.0.x) or older version, you need to use prebuilts instead of Prebuilts/misc
Problems during the run:
Problem: Qemu:could not load initrd ' ramdisk.img '
Workaround:
Enter the directory where the Ramdisk.img is located (~/my_android/out/target/product/generic/) and run the following command
[Plain]View Plaincopy
- chmod 777-r *
And when running emulator, add the full path name, as follows:
[Plain]View Plaincopy
- emulator-kernel/my_android/prebuilts/qemu-kernel/arm/kernel-qemu-armv7-sysdir/my_android/out/target/product/ generic/-system System.img-data Userdata.img-ramdisk/my_android/out/target/product/generic/ramdisk.img-skindir skins/-skin hvga-partition-size 768
Where skins is copied from the SDK directory.