2013年8月5日星期一

Android source compiler order summary

 After several days of agonizing

finally successfully compiled under Ubuntu source, sdk and adt, and successfully used to great difficulty real fee. Even where there are still many do not understand, these are summarized below their problems, and to leave to later encounter problems of people like me some help

 

1. 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

 

I found that there has been relatively full years, but there are some linux systems should be built, if the lack of it follow the prompts to install it

 

install java environment, where it is necessary to say something, when we installed the environment many people packed together, but I recommend java and other separate because java is installed might fail, causing others also fail < / p>  

sudo apt-get install sun-java6-jdk

 

here comes above that many people would install java failure, the author also from the Internet to find a solution together now sorted out:

 

ubuntu10.04 lucid removed sun-java6-jre, sun-java6-jdk source, so if it is a direct apt-get install tips are not available now
package sun-java6-jdk, but it is referenced by other packages.
This may mean that the package is missing may have been abandoned,
or only in other published sources
E: Package sun-java6-jdk is not available candidates for installation
solutions (can choose one):
1, System -> Administration -> Software Sources -> "Other Software" to add a deb http: / / archive.canonical.com / lucid partner
before performing apt-get install

 

If you downloaded java5 to add deb http://us.archive.ubuntu.com/ubuntu/ jaunty multiverse "
2, himself from the sun website to download the appropriate Jre, JDK installation can
3, the new Leader Software Manager search openJDK, instead of using openJDK

 

Note: The official documentation says that if sun-java6-jdk can go wrong, have to use sun-java5-jdk. Been tested and found, if only make (make not including make sdk), with sun-java6-jdk is not a problem. And make sdk, there will be a problem, strictly speaking, is make doc problems, it needs javadoc version 1.5.

 

Therefore, we install sun-java6-jdk after the best before you install sun-java5-jdk, or just install the sun-java5-jdk. This sun-java6-jdk and sun-java5-jdk are installed, and only modify the javadoc.1.gz and javadoc. Because only these two are make sdk used. In this case, in addition to javadoc tool with version 1.5, the other with the 1.6 version are:

 

sudo apt-get install sun-java5-jdk

 

modify the 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, set the environment variable

 

vim ~ /. bashrc

 

in. bashrc PATH variable to add or integrate, as

 

# java application development / run some environment variables

 

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 the android source code)

 

create ~ / bin directory, used to store repo procedure is as follows:

 

$ cd ~ $ mkdir bin

 

and added to the PATH environment variable, in the second step has been added

 

download 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 on the git package, simplifying some git operations.

 

create a project directory:

 

$ mkdir android

 

$ cd android

 

repo initialization

 

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

 

This contains the latest source android

 

in this process need to enter the name and email address. Initialization is successful, it will show:

 

repo initialized in / android

 

in ~ / android will be a next. repo hidden directory.

 

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

 

repo init-u git :/ / android.git.kernel.org / platform / manifest.git-b cupcake branch grasping down here is cupcake, online articles about the compiler to mostly for cupcake branch is andoird 1.5 version, but I had not entered the back of the parameters, so that the code is next to the main line of code, is android 2.1 version. There are some differences between the two directory structures, leading to the instructions when I follow the steps to perform online encounters an error, do not know is the version for different reasons or other reasons. Therefore wondered why the online article are saying cupcake, but did not say how the main line of the source code is compiled.

 

5. sync source code

 

$ repo sync

 

this step take a long time, depending on the individual network speed

 

6. compile android source code, and get ~ / android / out directory

 

$ cd ~ / andoird

 

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

 

this process for a long time, mainly to see the machine configuration

 

If cupcake, then directly make the time, you receive the following error:
1.frameworks/policies/base/PolicyConfig.mk: 22: *** No module defined for the given PRODUCT_POLICY ( android.policy_phone). Stop. mistake.
Solution:
In build / tools / findleaves.sh in the 89th row,
This is a find "$ {@: 0: $ nargs}" $ findargs-type f-name "$ filename"-print |
to find "$ {@: 1: $ nargs-1}" $ findargs-type f-name "$ filename" -print |
2.frameworks/base/tools/aidl/AST.cpp: 10: error: 'fprintf' was not declared in this scope error
Solution:
Download gcc-4.3 and g+ + -4.3
apt-get install gcc-4.3 g+ + -4.3
because ubuntu 9.10 comes to being gcc 4.4, so need to re-download gcc 4.3, gcc soft finally set Connect to gcc 4.3
into / usr / bin
cd / usr / bin
build a flexible connection
ln-s gcc-4.3 gcc
ln-s g+ + -4.3 g+ +
then enter the android directory and run make, on it.
mainline code does not have this problem 7. compiled to run on the emulator android

 After

compiled android, emulator in ~ / android/out/host/linux-x86/bin down, ramdisk.img, system.img and userdata.img in ~ / android / out / target / product / generic Next

 

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

 

increase environmental variables

 

$ emacs ~ /. bashrc

 

in. bashrc add the environment variable as follows

 

# java application development / run some environment variables

 

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

 

finally into android desktop, and it shows a success.

 

8. compiled modules

 

android an application can be compiled separately compiled to regenerate system.img

 

in the source directory, run

 

$. build / envsetup.sh (. followed by a space)

 

the more out of some 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 / 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.

 

can be added-help Show usage

 mmm

we can use to compile the specified directory module, such as compiling contact:

 

$ mmm packages / apps / Contacts /

 

compiled after completing generates two files:

 

out / target / product / generic / data / app / ContactsTests. apk

 

out / target / product / generic / system / app / Contacts.apk

 

can use

 

$ make snod

 

regenerate system.img, and then run the simulator

 

9. compile SDK

 

direct execution make is not including make sdk's. make sdk used to generate SDK, so that we can use to synchronize with the source code of the android SDK to develop.

 

a) modify the / frameworks / base / include / utils / Asset.h

 

'UNCOMPRESS_DATA_MAX = 1 * 1024 * 1024' changed 'UNCOMPRESS_DATA_MAX = 2 * 1024 * 1024'

 

reason is to compile the project requires more than 1.3M eclipse the buffer;

 

this step, I compiled the main thread in Asset.h file not found above constants, so I can not do this step, but it is also a success.

 

b) compile ADT.

 

If you want to develop android application with eclipse, it is best to install the ADT, so that you can create in eclipse android project.
generate ADT eclipse plugins $ development / tools / eclipse / scripts / build_server.sh ~ / adt / recommended settings before using it ECLIPSE_HOME environment variables, or will that not installed eclipse, and then help you download down .
here to be very aware that I once stuck in here, but always compiled. The eclipse will be prompted to start something and can not find the jar, so fail. This is mainly because I have to ECLIPSE_HOME to the environment variable is set incorrectly. Before I installed the eclipse was only from Sony grasping down above, seem to find the directory where the eclipse which, the result set up a folder called eclipse as an environment variable. So later directly from the official eclipse online one, thinking that it would. Results cup is next to an eclipse Galileo, the end, or what prompted eclipse what file not found. Finally It is impossible, simply delete the eclipse a clean, let the program go under their own eclipse, was found caught eclipse ganymede. In this solemnly explain themselves to the next, then you should download jee's ganymade, but not the java ganymade, try to know the specific reasons.

 

mainline ADT when the code is compiled in the same way, but no development / tools / eclipse this directory, but in the / sdk / eclipse this directory

 

c) execute make sdk.

 

Note that this requires the javadoc version 1.5, so you need to install both in step 1 sun-java5-jdk

 

$ make sdk

 

compilation is very slow. SDK generated compiled stored in out/host/linux-x86/sdk /, this directory has android-sdk_eng.xxx_linux-x86.zip and android-sdk_eng.xxx_linux-x86 directory. android-sdk_eng.xxx_linux-x86 is the SDK directory

 

In fact, when using mmm command to compile the module, the same output file will clear the SDK, so it is best to android-sdk_eng.xxx_linux-x86 moved out

 

subsequent application development, it is on the SDK, so the 7) for ~ /. bashrc modification comment, add the following line:

 

export PATH = $ {PATH}: ~ / android/out/host/linux-x86/sdk/andr oid-sdk_eng.xxx_linux-x86/tools

 

attention should replace xxx true path;

 

same author compiled the main thread, so compiled, and found ~ / android/out/host/linux-x86/sdk/android-sdk_eng.x xx_linux-x86 / directory has two folders one is tools one is platform-tools, and then point to this directory when the eclipse will be prompted to find the ADB, this time as long as the platform-tools under the ADB copy tools folder on OK

 

d) on environmental variables, android tool of choice

 

current android tools:

 

A, we downloaded from the Internet of the SDK, if you downloaded it (tools under many android tools, lib / images under the img image)

 

B, we make sdk compiled out of the SDK (tools, there are many android tools under, lib / images under the img image)

 

C, we make the translation of the out directory (tools, there are many android tools under, lib / images under the img image)

 

then we should use those tools and img it?

 

First, we generally do not use the A option of tools and img, because in general it is relatively old, and source code is not synchronized. Secondly, it will not use the C option of tools and img, because these tools and the SDK has not been classified img processing tools, and configuration will not find the situation; fact, make sdk img produced many tools and , compiled out in the make directory, is already compiled generated, make sdk just do a copy only.

 

e) to install, configure ADT

 

~ / adt / android-eclipse / next file compression, and then install from the eclipse on the line, of course, there are other ways

 

10. compile linux kernel image

 

a) preparing cross compiler tool chain

 

android source tree has a prebuilt project, we compile the kernel contains a cross compiler tools required.

 

b) set the environment variable

 

$ emacs ~ /. bashrc

 

add the following two lines:

 

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

 

export ARCH = arm

 

saved, synchronous changes:

 

$ source ~ /. bashrc

 

c) to obtain the appropriate 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

 

display * android-2.6.27

 

that you are now in the android-2.6.27 This branch is also kernel / common.git default master branch.

 

show all head branch:

 

$ git branch-a

 

display * 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 selected the latest android-goldfish-2.6.29, where goldfish is android emulator simulate the 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 in the android-goldfish-2.6.29 branch on.

 

d) cross-compiler parameter setting

 

open kernel directory Makefile file, CROSS_COMPILE point in just downloaded prebuilt arm-eabi compiler

 

CROSS_COMPILE? = arm-eabi-

 

the LDFLAGS_BUILD_ID = $ (patsubst-Wl $ (comma)%,%, \

 

$ (call ld-option,-Wl $ (comma) build-id,))

 

comment out this line and add an empty LDFLAGS_BUILD_ID defined as follows:

 

LDFLAGS_BUILD_ID =

 

e) compile 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

 

written references many online resources, to the point after watching comment, thank you! !

没有评论:

发表评论