"Android Deep Exploration" (Vol. 1) Hal and Driver development

Source: Internet
Author: User
Tags using git

The 4th chapter: Download and compile the source code

This chapter is mainly about using git to download two sets of source code, one set is the Android source code, another set of Linux source code. Because the Android kernel is based on the Linux kernel, Android porting is primarily the porting of the Linux kernel. The Linux kernel porting is primarily a Linux-powered migration. So in order to develop and test Linux drivers. Two sets of development environments need to be built under Linux. Android application development environment and Linux kernel development environment. The main purpose of this chapter is to describe how to build these two development environments.

In order to successfully develop the Android drive, the two environments must be built.

The book describes the following:

First, download, pre-compile, and test the Android source code core steps:

1. Configure the Android source code download environment

(1) Create a directory to hold the download script file (repo)

(2) Download repo script file

(3) Create a directory to hold the Android source code

(4) initialization

(5) Start downloading Android source code

2.Android Source code directory structure analysis

3. Download part of the Android source code

There are two ways to download an item in the Android source code: Method One, using the Repo Sync command method Two, using the git clone command

4. Compiling Android source code

First step: Initializing the compilation Environment Step two: Select Target step three: compiling Android source code

5.OUT Directory Structure Analysis

6. Publish your apk as an Android built-in program

7. Test the System.img file with the simulator

Second, the core steps of downloading and compiling the Linux kernel source code:

1. Download the Linux kernel source code

Directory structure of 2.Linux kernel source code

3. Install the Android kernel's build environment

1>: Preparing for work

2>: Unzip the compiler

3>: Verify that the Cross compiler is successfully installed

4>: Installing LIBNCURSES5

4. Configuring and compiling the Linux kernel

Find information through the network on the Android Source code compilation Summary:

. The necessary Software environment

sudo apt-get install build-essential

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 Libncurses-dev

sudo apt-get install Git-core GnuPG

sudo apt-get install Flex Bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential Zip Curl

sudo apt-get install Ncurses-dev

sudo apt-get install Zlib1g-dev

sudo apt-get install Valgrind

sudo apt-get install python2.5

The author found here has been compared to all, but there are some should be the Linux system comes with, if missing, follow the prompts to install

Install the Java environment, it is necessary to say, we install the environment when a lot of people will be installed together, but I suggest that Java and other separate, because loading Java is likely to fail, resulting in other also fail

sudo apt-get install SUN-JAVA6-JDK

Here it says a lot of people will install Java failures, the author is also looking for solutions from the Internet now together to sort out:

ubuntu10.04 Lucid removed the source of the SUN-JAVA6-JRE,SUN-JAVA6-JDK, so if the direct Apt-get install prompt is

There is no package sun-java6-jdk available now, but it is referenced by other packages.

This may mean that the missing package may have been discarded,

Or can only be found in other publishing sources

E: Package SUN-JAVA6-JDK not yet available for installation candidate

Workaround (Select one):

1. Add a Deb Http://archive.canonical.com/lucid partner under "Other software", software source, System management

After that, execute the Apt-get install again

If you are downloading Java5, add the Deb Http://us.archive.ubuntu.com/ubuntu/jaunty Multiverse "

2. Download the corresponding JRE,JDK installation from Sun website

3. Search OpenJDK in the new software manager, replace with OpenJDK

Note: Official documents say that if the use of sun-java6-jdk can be problematic, 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-JAVA5-JDK

Modify the link of Javadoc

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

Vim ~/.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: $CLASSP ATH

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}:${jre_path}:${home_bin};

#echo $PATH;

Finally, synchronize these changes:

SOURCE ~/.bashr

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

This contains the latest Android source code.

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.

If you want to take a branch rather than the main line of code, we need to use the-B parameter to make branch name, such as:

Repo Init-u git://android.git.kernel.org/platform/manifest.git-b cupcake here to grab down the branch is cupcake, online about compiling to the article mostly for cupcake branch, It is Andoird 1.5, but I did not enter the following parameters, so that the next code is the main line of code, is the Android 2.1 version. There are some differences between the two directory structures, which leads to the fact that when I follow the instructions on the web, I do not know the reason for the different version or some other reason. So it is very strange why the articles on the internet are said cupcake, and not how to say the main line of the source code compilation.

5. Synchronizing source code

$ repo Sync

This step takes a long time, depends on the personal network speed

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

$ CD ~/andoird

$ make-j2 The author's computer is dual-core so it is-j2, and so on 8 cores can-j8

This process for a long time, mainly look at the machine configuration

If it is a cupcake, the following error will occur when you make it directly:

1.FRAMEWORKS/POLICIES/BASE/POLICYCONFIG.MK:22: * * * No module defined for the given product_policy (android.policy_phone ). Stop. Error.

Workaround:

In the 89th line of build/tools/findleaves.sh,

This sentence find "${@:0: $nargs}" $findargs-type f-name "$filename"-print |

Change to find "${@:1: $nargs-1}" $findargs-type f-name "$filename"-print |

2.frameworks/base/tools/aidl/ast.cpp:10:error: ' fprintf ' is not declared in this scope error

Workaround:

Download gcc-4.3 and g++-4.3

Apt-get Install gcc-4.3 g++-4.3

Because Ubuntu 9.10 comes with GCC 4.4, you need to re-download gcc 4.3 and finally set up GCC soft connect to gcc 4.3

Enter/usr/bin

Cd/usr/bin

Build a soft connection

Ln-s gcc-4.3 GCC

Ln-s g++-4.3 g++

Then go to the Android directory and execute make to do it.

The mainline code does not have this problem 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/ Target/product/generic under

$ 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/g Eneric

Android_product_out_bin=~/android/out/host/linux-x 86/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. Compiling 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;

This step, I compiled the main thread, in the Asset.h file did not find the above constants, so did not do this step, but also succeeded.

b) Compile ADT.

If you want to develop an Android app with Eclipse, it's best to install ADT so you can create an Android project under Eclipse.

Producing ADT Eclipse plugins

$ development/tools/eclipse/scripts/build_server.sh ~/adt/

It is recommended to set the ECLIPSE_HOME environment variables before use, otherwise you will think that you have not installed Eclipse, and then help you download down.

Here to be very careful, I have been stuck here, always compiled but. At the outset, I will be prompted for what jar in Eclipse is not found, so fail. This is mostly because I went to eclipse_home to set the environment variable incorrectly. The eclipse I installed was only scratched from the top of the new force, as if I couldn't find where Eclipse was located, and as a result, a folder named Eclipse was set as an environment variable. So it went straight from Eclipse's official web site and thought it would. The result of the cup is the next Eclipse Galileo, which eventually prompts eclipse what files are missing. Finally, it is impossible to simply delete the eclipse and let the program go to eclipse, and find out that the eclipse Ganymede is caught. Here to solemnly explain, you should download the Ganymade of Jee, and not Java Ganymade, specific reasons to try to know.

The main Line code compiles ADT in the same way, but does not development/tools/eclipse this directory, but in/sdk/eclipse this directory

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's 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/andr Oid-sdk_eng.xxx_linux-x86/tools

Pay attention to replace XXX with the real path;

The same author compiled is the main thread, so after compiling, found ~/android/out/host/linux-x86/sdk/android-sdk_eng.x xx_linux-x86/ There are 2 folders under the directory one is the tools one is Platform-tools, and then with Eclipse point to this directory will be prompted to find the ADB, this time as long as the platform-tools under the ADB copy to the Tools folder is OK

d) About environment variables, options for Android tools

The current Android tools are:

A, we download the SDK from the Internet, if you have downloaded the words (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

~/adt/android-eclipse/file compression, then install from Eclipse, and of course there are other ways

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

Http://www.cnblogs.com/Mr-zsj/p/5413596.html

"Android Deep Exploration" (Vol. 1) Hal and Driver development

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.