Download and compile Android source code

Source: Internet
Author: User

This article is a summary of this chapter in Deep Exploration for Android-HAL and driver development, recording your own learning.


The Android Source Code contains many things, such as applications embedded in the Android system.
(Photos, calculators, calendars, Dialers, etc.) source code, Android SDK with various tools
Source code, Android NDK source code, HAL source code, and so on, so the Android source code package is very large.

--- Source code download

/* Configure the download environment */
Create a directory for storing the repo of the downloaded script file (this script file can be stored)
To any directory, generally ~ /Bin)
1)
# Mkdir ~ /Bin
# PATH = ~ /BIN: PATH
2) download the repo script
# Curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo> ~ /Bin/repo
# Chmod a + x ~ /Bin/repo
The repo file is actually encapsulated in git using a Python script, mainly to simplify download
Android source code operations.
3) create and store the Android source code directory
# Mkdir android
# Cd android
4) execute Initialization
# Repo init-u https://android.googlesource.com/platform/mainfest
The above Code requires the repo to download the latest source code, that is, the master branch. If you want
For other branches, run the following command.
# Repo init-u https://android.googlesource.com/platform/mainfest-B xxxxx (Others)
5) Start download.
# Repo sync
Depending on the network speed and machine configuration, this process will last for at least a few hours.
PS: the download method of the Android source code repo is not required. If there is an available source code package, why download it?
It is also a good method to decompress the package directly.

--- Android source code directory structure analysis

Directory Name source code directory meaning

Abi | application binary interface

Bionic | C/C ++ Runtime Library. A large part of the NDK program calls this program.

Bootable | used to load and start Android programs, including the famous bootloader and recovery.
Bootloader is started before the Linux kernel starts. It is used to initialize hardware and build mappings.
Recovery can talk about a program that overwrites files in a compressed package to the system directory in the mobile phone memory.
(Flash program)

Build | a tool used to compile the Android source code and create files such as system. img and ramdisk. img.

Cts | tool for compatibility testing

Dalvik | source code of the Dalivk Virtual Machine

Development and debugging tools at the development level

Device | device-related code. It contains the device code of motto and Samsung.

Docs | Android source code project documentation and tools

External | source code of the extended Tool

Frameworks Android framework layer code. That is, the source code of the Android SDK

Hardware | hardware interface layer and library. The source code of HAL is here

Libcore | Java core library

Ndk | NDK-related code

Packages | source code of the application released with the Android system

Prebuilts | tools used before Android compilation on various platforms

Sdk | tools used in the development environment, such as DDMS, draw9patch, and sdkmanager

System: basic Android system

/* Some compilation tools are available under the prebuilts folder ~~ */

--- Compile the Android source code

/* Initialize the compiling environment */
Run
# The source build/envsetup. sh envsetup. sh script mainly initializes some compilation commands, such as mm.
Mmm.
Envsetup. sh defines some shell functions. After using the source command, you can
. Both mm and mmm can compile the specified project in the Android source code.
The difference is that the mm command must be compiled in the directory of the specified project, while the mmm command can be used in Android
Compile any specified project in any level-1 directory under the source code tree by specifying the path.
For example:
1) # cd ~ /Android/android2.3.4 _ src
# Source build/envsetup. sh
# Cd packages/apps/calculator
# Mm
2) # cd ~ /Android/android2.3.4 _ src
# Source build/envsetup. sh
# Mmm packages/apps/calculator

/* Select the compilation target */
Use the lunch command to compile and set the target
Full-eng | the Android simulator is valid for all mobile devices. Enable all debugging options.
If you cannot determine the target or forget the target, you can enter only lunch in the command line to run it.
You will be prompted with a variety of target options, from which you can select the appropriate target for compilation.
3) # make if a PC with multiple cores, multiple threads, and hyper-threading can be attached with the-jn parameter, which can speed up
Compilation speed. For example, the # make-j4 compilation process is also a long wait .~~

--- Out directory structure analysis

The out directory is the default directory for storing the target files generated by compiling Android source code.

| -- Host/Some libraries and tools required during compilation
Out -- |
| -- Target /~ /Common mainly contains the Android Java library .~ /Generic contains the target file system. img, etc.

--- Embedded apk Publishing

Embed the apk into system. img. In this way, the apk is built in the same way as the app of the native system and cannot be uninstalled without root.
1) embed the apk in the/out/target/product/generic/system/app file and repackage it to generate system. img
2) because the app that comes with the system has the apk file and the corresponding odex file, we can also use the app source code
Re-compile the app in the Android source code package, so that the apk and odex of the app will be generated under the system/app directory.
Then package system. img again.
Repackage system. img, you can use the mkyaffs2image command line tool in the out/host/linux-x86/bin directory, or
Run make snod to package

--- Download and compile the Linux kernel source code

From the Android source code tree, we can see that there are no Linux-related folders. OK, the original kernel is added separately.
Added, and the Linux kernel was modified by Google, not the native kernel of linux.kernel.org.
Download the Linux kernel from Google, decompress it, configure the kernel, and then compile it.

--- Conclusion:

Android transplantation is mainly for Linux kernel transplantation. Linux Kernel transplantation is mainly for Linux drivers.
Android source code compilation and Linux kernel compilation in Android.

Zookeeper

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.