Android porting series one, Android compilation system

Source: Internet
Author: User

Translated from: http://source.android.com/porting/build_system.html

Android uses a custom build system generation tool, binary files and documents. This document provides an overview of building an Android-based compilation system.

Android's build system requires the latest version of GNU make, (note that Android uses GNU's advanced features and may use GNU make, which has not yet appeared on the site). Before you continue, run%MAKE–V. Check your make version. If you do not have version 3.80 or later, you will need to upgrade your make version.

About Makefile

Makefile defines how to build a specific application. Makefile files typically include all of the following:

Name: give you a title (local_module:= <build_name>).

Local Variables: Clears the locals (include $ (clear_vars)) with Clear_vars.

Files: Determine which files depend on your application (local_src_files:= main.c).

Libraries: Defines whether your application is linked to other Libraries (local_shared_libraries:= cutils).

Template file: Contains a profile document to define, emphasizing for specific goals (tools include $ (build_executable)).

The following code snippet demonstrates a typical makefile.

Local_path: = $ (My-dir)
Include $ (clear_vars)
Local_module: = <buil_name>
Local_src_files: = main.c
Local_module_tags: = ENG Development
Local_shared_libraries: = Cutils
Include $ (build_executable)
(Host_) Executable, (Host_) java_library, (Host_) prebuilt, (host_) Shared_library,
(Host_) Static_library, Package, JAVADOC, raw_executable, Raw_static_library,
Copy_headers, Key_char_map

The above fragment includes artificial line breaks to keep a print-friendly print file.

Layer

The build hierarchy consists of an abstraction of the layers described in the following table.

Each layer relates to one of the one-to-many relationships above it. For example, arch can have multiple board, and each board can have more than one device. You can define a layer element as a specialization given in the same layer element, thus eliminating duplication and simplifying maintenance.

Layer

Example

Description

Product

MyProduct, Myproduct_eu, Myproduct_eu_fr, J2, SDK

The product layer defines a ship's product specifications, define which modules to build, and how to configure them. You may be setting up a locale based on several different versions of the device, for example, or in features such as a camera.

Device

Mydevice, Mydevice_eu, Mydevice_eu_lite

The device layer represents the physical layer of plastic on the equipment. For example, North American devices may include sales equipment, while a QWERTY keyboard in France may include a azerty keyboard. Peripherals are usually connected to the device layer.

Board

Sardine, trout, goldfish

The board layer represents a schematic diagram of a product. You may still connect the board layer of the peripheral.

Arch

Arm (ARM5TE) (ARM6), x86, 68k

The arch layer describes the processor running on your board.

Building on the Android platform

This section describes how to build the default version on Android. Once you have built a universal comfort, then you can start modifying your own target device for the robot.

Device Code

In order to do a generic construction of a robot, the source construction/envsetup.sh, which contains the necessary variables and function definitions, is described below.

% CD $TOP
% . build/envsetup.sh
# Pick a configuration using Choosecombo
% Choosecombo
% Make-j4 Product-generic-user

You can also replace debug project with a user:

% Make-j4 Product-generic-eng

These are based on different variants and package installation debugging option conditions.

Clean

Execute% m clean, cleaning up the binaries you just created. You can also perform a% m clobber to get all the combo binary files cleared. The% m clobber is equivalent to the storage location of all files generated in the delete//output/directory.

Speed up re-build

Each combination of binary files is stored as a different sub//output/, so that you can quickly switch between combos without having to recompile all the source directories each time.

However, performing a clean rebuild is necessary if you do not generate changes to the environment variables or build files that the system captures. If this happens, you should define the USE_CCACHE environment variable as follows:

% Export use_ccache=1

Doing so will force the compiler of the compiled system to use the CCache caching tool, which reduces the recompilation of all sources.

CCache in binary files//presets/... Nor does it need to be installed on your system.

Troubleshooting

The following error may be caused by an outdated version of Java running.

Device Dex:core unexpected top-level ERROR:
Java.lang.NoSuchMethodError:method Java.util.Arrays.hashCode with
Signature ([Ljava.lang.Object;) I was not found.
At Com.google.util.FixedSizeList.hashCode (fixedsizelist.java:66)
At Com.google.rop.code.Rop.hashCode (rop.java:245)
At Java.util.HashMap.hash (libgcj.so.7)
[...]

DX is a Java program that uses the facility, first in the existing Java version 1.5. Perform% java-version in the shell to check the Java version you are using. You should see something like:

Java Version "1.5.0_07"
Java (TM) 2 Runtime environment, Standard Edition (build 1.5.0_07-164)
Java HotSpot (TM) Client VMs (build 1.5.0_07-87, mixed mode, sharing)

If you have Java 1.5 or later and you receive this error, make sure that you have correctly updated your PATH variable.

Build Android Kernel

This section describes how to build the default kernel for Android. Once you have built a generic build, you can start modifying the drivers for your Android target device.

To build the kernel, switch to the device directory (/home/joe/android/device) to build the variables and run:

% . build/envsetup.sh
% partner_setup Generic

Then switch to kernel directory/home/joe/android/kernel.

Checking out a Branch

The default branch is always Android. To check out a different branch, execute the following:

% git checkout--track-b android-mydevice origin/android-mydevice

Branch Android-mydevice set up to track remote Branch

% Refs/remotes/origin/android-mydevice.

Switched to a new branch "Android-mydevice"

To simplify code management, leave your local branch with the same name as the remote branch trace (as shown in the previous fragment). By executing the% git checkout <branchname>. Switch between branches

Verifying location

Find out which branch (both local and remote) exist, which branch active by performing the following (with an asterisk tag):

% git branch-a

Android

* Android-mydevice

Origin/head

Origin/android

Origin/android-mydevice

Origin/android-mychipset

Just look at local branch, omit-a flag.

Building the Kernel

To build the kernel, execute:

% Make-j4

Build variable

When a build of a product is often useful, what is ultimately the final release version is slightly different. This is the currently defined build variable:

Eng

This is the default flavor. %make is the same as%make Eng.

• Install the module tag: ENG, debug, user, or development.

• Install the non-apk module without marking the designation.

• Install APKS According to the product definition file, in addition to the tagged APKs.

ro.secure = 0

ro.debuggable = 1

Ro.kernel.android.checkjni = 1

adb is enabled by default.

user

make user

This is the lavor that is intended for the final version bit.

the user who installed the module. The

installs the non-apk module, which is not specified in the tag.

installs APKS based on the product definition file, the tag is ignored by the APK module.

ro.secure=1

                                   ro.debuggable=0

                                   adb is disabled by default.

userdebug

make userdebug

                                    also installs with debug tag module  .

                                   ro.debuggable=1

                                   adb is enabled by default.

If you build a flavor and then want to build one, you should run make Installclean, two making rooms to ensure you don't accept the previous Installclean flavor. Make clean is enough, but it takes longer.

Android porting series one, Android compilation system

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.