Android source code compilation of the entire process record

Source: Internet
Author: User

The writing article mainly refers to official documents and some information on the Internet, but for the latest Android code, some of the online information is outdated. The steps in this article have been experimented by authors, and you can try it out yourself. There is no eclipse-related configuration because it is not used by eclipse.

Compilation environment: The Ubuntu9.10,widnows platform is not currently supported.

1) Install the necessary software environment

$ sudo apt-get install git-core gnupg SUN-JAVA5-JDK Flex Bison gperf Libsdl-dev libesd0-dev Libwxgtk2.6-dev Build-essentia L Zip Curl Libncurses5-dev Zlib1g-dev

The official recommendation is that these, if found in the compilation process some commands can not find, apt-get it. The packages you may need are:

$ sudo apt-get install make
$ sudo apt-get install gcc
$ sudo apt-get install g++
$ sudo apt-get install Libc6-dev

$ sudo apt-get install patch
$ sudo apt-get install Texinfo

$ sudo apt-get install Zlib1g-dev
$ sudo apt-get install Valgrind
$ sudo apt-get install python2.5 (or later)

It is important to note that official documents say that if you use SUN-JAVA6-JDK, you have to use SUN-JAVA5-JDK. The test found that if only make (make does not include the Make SDK), using SUN-JAVA6-JDK is no problem. The Make SDK, there will be a problem, strictly speaking in the cause of the issue, it requires the Javadoc version of 1.5.

Therefore, we'd better install the SUN-JAVA5-JDK after installing SUN-JAVA6-JDK, or just install SUN-JAVA5-JDK. Here Sun-java6-jdk and SUN-JAVA5-JDK are installed, and only modify javadoc.1.gz and Javadoc. Because only these two are used by the Make SDK. In this case, except the Javadoc tool is in version 1.5, the others are in version 1.6:

$ sudo apt-get install SUN-JAVA6-JDK

To modify Javadoc Link:

$ cd/etc/alternatives
$ sudo rm javadoc.1.gz
$ sudo ln-s/usr/lib/jvm/java-1.5.0-sun/man/man1/javadoc.1.gz javadoc.1.gz
$ sudo rm javadoc
$ sudo ln-s/usr/lib/jvm/java-1.5.0-sun/bin/javadoc Javadoc

2) Setting environment variables

$ emacs ~/.BASHRC

Add or integrate the path variable in. BASHRC, as follows:

#java Some environment variables for program development/Run

Java_home=/usr/lib/jvm/java-6-sun
Jre_home=${java_home}/jre
Export Android_java_home= $JAVA _home
Export classpath=.:${java_home}/lib: $JRE _home/lib: $CLASSPATH
Export Java_path=${java_home}/bin:${jre_home}/bin
Export Java_home;
Export Jre_home;
Export CLASSPATH;
home_bin=~/bin/
Export Path=${path}:${java_path}:${home_bin};

After saving, synchronize updates:

SOURCE ~/.BASHRC

3) Install repo (used to update Android source code)

Create the ~/bin directory to hold the repo program, as follows:

$ cd ~
$ mkdir Bin

and added to the environment variable path, which was added in the 2nd step.

Download the repo script and make it executable:

$ Curl Http://android.git.kernel.org/repo >~/bin/repo
$ chmod a+x ~/bin/repo

4) Initialize repo

Repo is an android-to-git package that simplifies some git operations.

To create a project catalog:

$ mkdir Android
$ cd Android

Repo initialization:

$ repo Init-u git://android.git.kernel.org/platform/manifest.git

You will need to enter your name and email address during this process. After the initialization is successful, it displays:

Repo initialized in/android

Under the ~/android there will be a hidden directory of. Repo.

5) Synchronizing source code

$ repo Sync

This step takes a long, long time.

6) Compile the Android source code and get the ~/android/out directory

$ CD ~/andoird
$ make

This is a long process.

7) Run the compiled Android on the emulator

After compiling Android, emulator under ~/android/out/host/linux-x86/bin, Ramdisk.img,system.img and userdata.img in ~/android/out/ Under the Target/product/generic.

$ CD ~/android/out/host/linux-x86/bin

Add Environment variables

$ emacs ~/.BASHRC

New environment variables in. BASHRC, as follows

#java Some environment variables for program development/Run

Export Android_product_out=~/android/out/target/product/generic
Android_product_out_bin=~/android/out/host/linux-x86/bin
Export Path=${path}:${android_product_out_bin}:${android_product_out};

Finally, synchronize these changes:

$ source ~/.BASHRC
$ CD ~/android/out/target/product/generic
$ emulator-system system.img-data Userdata.img-ramdisk ramdisk.img

The final entry to the Android desktop is a good indication of success.

8) Compile the module

An application in Android can be compiled separately and rebuilt system.img after compilation.

Execute under the source directory

$ . Build/envsetup.sh (. There are spaces behind)

Just a few more commands:

-Croot:changes directory to the top of the tree.
-M:makes from the top of the tree.
-Mm:builds all of the modules in the current directory.
-Mmm:builds all of the modules in the supplied directories.
-Cgrep:greps on all local C + + files.
-Jgrep:greps on all local Java files.
-Resgrep:greps on all local res/*.xml files.
-Godir:go to the directory containing a file.

You can add-help to view usage.

We can use MMM to compile modules for the specified directory, such as compiling contacts:

$ mmm packages/apps/contacts/

Two files are generated after the completion of the compilation:

out/target/product/generic/data/app/contactstests.apk
out/target/product/generic/system/app/contacts.apk

can use

$ make Snod

Regenerate the system.img and run the emulator again.

9) Compiling the SDK

Direct execute make is not included with the Make SDK. The Make SDK is used to generate the SDK so that we can use the SDK to synchronize with the source code to develop Android.

a) Modify/frameworks/base/include/utils/asset.h

' Uncompress_data_max = 1 * 1024 * 1024 ' changed to ' Uncompress_data_max = 2 * 1024 * 1024 '

The reason is that the Eclipse compilation project requires a buffer greater than 1.3M;

b) Compiling ADT

Because I do not use eclipse, so did not take this step;

c) Execute the Make SDK

Note that the Javadoc version required here is 1.5, so you need to install SUN-JAVA5-JDK at the same time in step 1

$ Make SDK

Compilation is slow. The compiled SDK is stored in out/host/linux-x86/sdk/, which has a directory of Android-sdk_eng.xxx_linux-x86.zip and android-sdk_eng.xxx_linux-x86. Android-sdk_eng.xxx_linux-x86 is the SDK directory.

In fact, when compiling the module with the MMM command, the output file of the SDK will be erased as well, so it is best to move the android-sdk_eng.xxx_linux-x86 out.

After this application development, it is on the SDK, so put 7) for the ~/.BASHRC modification comments out, add the following line:

Export Path=${path}:~/android/out/host/linux-x86/sdk/android-sdk_eng.xxx_linux-x86/tools

Pay attention to replace XXX with the real path;

d) About environment variables, options for Android tools

The current Android tools are:

A, we download the Android SDK from the Internet, if you downloaded (Tools have many Android tools, lib/images under the IMG image)
B, we use the Make SDK compiled by the SDK (Tools also have many Android tools, lib/images under the IMG image)
C, we use make compiled out directory (Tools also have many Android tools, lib/images under the IMG image)

So what are we supposed to do with those tools and IMG?

First of all, we generally do not use the A option of the tool and IMG, because generally it is older, but also the source is out of sync. Second, there is no use of the C option tools and IMG, because these tools and IMG does not have the SDK collation processing, there will be no tools and configuration can not be found, in fact, the Make SDK generated many tools and IMG, when make compiled out the out directory, has been compiled generated, made The SDK just made copy.

e) Install and configure ADT
Skip over;

f) Create Android Virtual Device

The compiled SDK is no AvD (Android Virtual Device) and we can view it through the Android tool:

$ Android List

To create an AVD:

$ android Create avd-t 1-n MYAVD

You can android–help to see the use of the above command options. There are some options in the creation, which is the default.

To perform the Android list, you can see where the AVD is stored.

Each time you run emulator, add-AVD myavd or @myavd options:

$ EMULATOR-AVD MYAVD

10) Compiling the Linux kernel image

a) Prepare the cross-compilation tool chain

There is a prebuilt project in the Android code tree that contains the cross-compilation tools we need to compile the kernel.

b) Setting environment variables

$ emacs ~/.BASHRC

Add the following two lines:

Export path= $PATH: ~/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin
Export Arch=arm

After saving, sync changes:

$ source ~/.BASHRC

c) Get the right kernel source code

$ CD ~/android

Get the kernel source code repository

$ git clone git://android.git.kernel.org/kernel/common.git kernel
$ CD Kernel
$ git Branch

Show

* android-2.6.27

It means that you are now on the android-2.6.27 branch and the default main branch of Kernel/common.git.

Show all head branches:

$ git branch-a

Show

* android-2.6.27
Remotes/origin/head-origin/android-2.6.27
remotes/origin/android-2.6.25
remotes/origin/android-2.6.27
remotes/origin/android-2.6.29
remotes/origin/android-goldfish-2.6.27
remotes/origin/android-goldfish-2.6.29

We select the latest android-goldfish-2.6.29, where goldfish is the Android emulator for the simulated CPU.

$ git checkout-b android-goldfish-2.6.29 origin/android-goldfish-2.6.29
$ git Branch

Show

android-2.6.27
* android-goldfish-2.6.29

We have been working on the Android-goldfish-2.6.29 branch.

d) Setting cross-compilation parameters

Open the makefile file in the kernel directory and point the cross_compile to the Arm-eabi compiler in the prebuilt you just downloaded.

Cross_compile? = arm-eabi-

Put

ldflags_build_id = $ (patsubst-wl$ (comma)%,%,\
$ (Call ld-option,-wl$ (comma) –build-id,))

This line is commented out and an empty ldflags_build_id definition is added, as follows:

ldflags_build_id =

e) Compiling the kernel image

$ CD ~/android/kernel
$ make Goldfish_defconfig
$ make

f) Test the generated kernel image

$ EMULATOR-AVD Myavd-kernel ~/android/kernel/arch/arm/boot/zimage

Android source code compilation of the entire process record

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.