Android porting Series 1. Android compilation system

Source: Internet
Author: User

 

Translation: http://source.android.com/porting/build_system.html

 

Android uses a custom Generation System Generation Tool, binary files, and documents. This document provides an overview of how to build an android compilation system.

 

The android compilation system requires the latest version of GNU make. (Please note that android uses GNU's advanced functions and may not be available on the website of GNU make ). Run % make-v. Query your make version. If you do not have version 3.80 or later, you must upgrade your make version.

 

Learn more about makefile

Makefile defines how to create a specific application. Makefile usually contains the following content:

Name: Create a name for you (local_module: = <build_name> ).

Local variables: Use clear_vars to clear local variables (include $ (clear_vars ))..

Files: Determine which files depend on your application (local_src_files: = Main. C ).

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

Template File: contains a template file to define, emphasizing as a specific target (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 preceding snippets include artificial line breaks to keep a print-friendly file.

 

Layer

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

 

Each layer is related to one of the one-to-many relationships above it. For example, arch can have multiple boards, and each Board can have more than one device. You can define a Layer Element specialized in the same Layer Element to eliminate replication and simplify maintenance.

Layer

Example

Description

Product

Myproduct, myproduct_eu, myproduct_eu_fr, J2, SDK

The Product Layer defines the complete specifications of a single ship, the modules to be built, and how to configure them. You may set regions on the basis of several devices provided by different versions, such as functions such as cameras.

Device

Mydevice, mydevice_eu, mydevice_eu_lite

The device layer represents the plastic Physical Layer on the device. For example, devices in North America may include sales devices, while QWERTY keyboards in France may include AZERTY keyboards. Peripherals are usually connected to the device layer.

Board

Sardine, trout, goldfish

The Board layer represents the schematic diagram of a product. You may still be connected to the peripheral board layer.

Arch

Arm (arm5te) (arm6), x86, 68 K

The arch layer describes the processor running on your board.

 

Construction on the Android platform

This section describes how to create a default version of Android. Once you build a general-purpose comfort, you can start to modify your target device's robot.

 

Device code

For general robot construction, the source construction/envsetup. Sh contains the necessary variables and function definitions, which are described as follows.

% cd $TOP
 
% . build/envsetup.sh
 
# pick a configuration using choosecombo
% choosecombo
 
% make -j4 PRODUCT-generic-user

You can also replace it with the user debugging project:

% make -j4 PRODUCT-generic-eng

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

 

Clear

Run % m clean to clear the binary file you just created. You can also clear all the composite binary files obtained by % m clobber. % M clobber is equivalent to deleting the storage location of all files generated in the // output/directory.

 

Speed up re-build

The binary files of each combination are stored as different sub-/output/, so that you can switch between attacks quickly without having to recompile all the source directories each time.

However, it is necessary to execute clean reconstruction if the system does not generate environment variables or file changes captured by the system. In this case, you should define the use_ccache environment variable as follows:

% export USE_CCACHE=1

This will force the compiler of the compilation system to use the ccache cache tool, thus reducing the re-compilation of all sources.

In the ccache binary file, // preset/... does not need to be installed on your system.

 

Troubleshooting

The following errors may be caused by outdated Java versions.

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 existing Java version 1.5 first. Execute % in Shell
Check the Java version you are using. You should see something similar:

java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-164)
Java HotSpot(TM) Client VM (build 1.5.0_07-87, mixed mode, sharing)

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

 

Build the android Kernel

This section describes how to build the default Android kernel. Once you build a generic build, you can start to modify the driver of your android target device.

 

To build the kernel, switch to the Device directory (/home/Joe/Android/device) to create variables and run:

% . build/envsetup.sh
% partner_setup generic

Switch to the 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, make your local branch the same name as the remote branch trace (as shown in the preceding section. Switch between branches by executing % git checkout <branchname>.

Verifying location

Find the existing branch (including local and remote) which is active by executing the following (star Mark ):

% Git
Branch-

Android

*
Android-mydevice

ORIGIN/head

ORIGIN/android

ORIGIN/Android-mydevice

ORIGIN/Android-mychipset

Read Only local branch, omitted-
A flag.

Building the kernel

To build the kernel, run:

% Make-J4

 

Build variable

When a product is built, it is often useful. What is 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.

• Installation module Tag: ENG,
Debug, user, or development ..

• Install the non-APK module without being marked.

• Install apks according to the product definition file, except the marked apks.

• Ro. Secure
= 0

• Ro. debuggable
= 1

• Ro. kernel. Android. checkjni
= 1

• ADB is enabled by default.

User

Make user

This is the lavor of the final version.

• Users of the installation module.

• Install the non-APK module, which is not specified in the tag.

• Install the apks APK module that is ignored according to the product definition file.

Ro. Secure = 1

·
Ro. debuggable = 0

·
ADB is disabled by default.

Userdebug

Make userdebug

Like the user,:

·
Also install the debug tag module.

·
Ro. debuggable = 1

·
ADB is enabled by default.

If you create a flavor and want to create one, you should run make installclean. Ensure that the two make files do not accept the previous installclean flavor. Make
Clean is enough, but it takes a longer time.

 

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.