Building Android

19
Building And roid AOSP release 4.2.2_r1 on a 32 bit Linux 1. Introduction In order to really get to know a system in depth, one of the best things you can do is to build it from scratch source. My motivation to do build Android from source is to be able to create my own custom Android build with extra functionality which generally is not provided in the binary deliveries provided  by the tablet, smartphone, smartv and other vendors of this world. There are ways to root your devices and make your own custom roms by pulling the origal firmware and replace or add binary content in order to push those changes back to your device. The real power however is when you are able to start from source and hence have full control about what your RM will contain in the end. !xamples of extra functionality I might want to add one day are the following"  Integrate extra kernel drivers and modules in order to support extra peripherals. #eg" add printer drivers, wifi dongles drivers...$.  Integrate extra binaries and libraries which are probably already available on your favorite %inux distro, but have not ye t been included in the default Android user land.  Integrate new or update existing &ava packages that are made available in Android's (alvik )M using the *(+. #eg" upgrade unit support from version - to $. As you'll probably know, Android provides an *(+ and an /(+, to develop ava and /ative 0102  based applications and libraries. Although they are great and many cool things can be done with it, some of the above items are not possible without building your own Android from source. 3urthermore, some applications or libraries built with the /(+ or *(+, might be candidate to include in the system section of your Android RM, so users cannot uninstall or thamper them #I assume most users do not root there device the day they buy it$. The reason I want all of thi s to work on my -4 bit %inux is tha t I don't have a 5 60 #poor me$ and I also don't want to use a )M image. 7uilding Android from source is a task which is already heavy enough, so installing and starting a 5 bit )M would only make things worse performance and memory wise. I am currently using 8buntu 94.:.4 %T* and intend to keep using this for ;uiet some time. The  problem however is that since <ingerbread #4.-.x$, including the master branch, a 5 bit environment is re;uired. More concrete this means that the cross compilation tool chains provided are 5 bit and the  build system itself has some hard coded 5 bit assumptions. 3or those wondering why <oogle switched to 5 bit, I ;uote the Technical %ead from the Android pen *ource 6ro&ect at <oogle, as he explained it to me on the '  Android Building ' <oogle <roup. They had some very good reasons to switch to 5 bit" 7art )an 7os = :-.:-.4:9- 6age 9

description

build android

Transcript of Building Android

Page 1: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 1/18

Building Android AOSP release 4.2.2_r1 on a 32 bit Linux

1. Introduction

In order to really get to know a system in depth, one of the best things you can do is to build it from

scratch source. My motivation to do build Android from source is to be able to create my own custom

Android build with extra functionality which generally is not provided in the binary deliveries provided by the tablet, smartphone, smartv and other vendors of this world. There are ways to root your devices

and make your own custom roms by pulling the origal firmware and replace or add binary content in

order to push those changes back to your device. The real power however is when you are able to startfrom source and hence have full control about what your RM will contain in the end.

!xamples of extra functionality I might want to add one day are the following"

 – Integrate extra kernel drivers and modules in order to support extra peripherals. #eg" add printer

drivers, wifi dongles drivers...$.

 – Integrate extra binaries and libraries which are probably already available on your favorite%inux distro, but have not yet been included in the default Android user land.

 – Integrate new or update existing &ava packages that are made available in Android's (alvik )M

using the *(+. #eg" upgrade unit support from version - to $.

As you'll probably know, Android provides an *(+ and an /(+, to develop ava and /ative 0102

 based applications and libraries. Although they are great and many cool things can be done with it,some of the above items are not possible without building your own Android from source. 3urthermore,

some applications or libraries built with the /(+ or *(+, might be candidate to include in the system

section of your Android RM, so users cannot uninstall or thamper them #I assume most users do notroot there device the day they buy it$.

The reason I want all of this to work on my -4 bit %inux is that I don't have a 5 60 #poor me$ and I

also don't want to use a )M image. 7uilding Android from source is a task which is already heavy

enough, so installing and starting a 5 bit )M would only make things worse performance and memorywise. I am currently using 8buntu 94.:.4 %T* and intend to keep using this for ;uiet some time. The

 problem however is that since <ingerbread #4.-.x$, including the master branch, a 5 bit environment is

re;uired. More concrete this means that the cross compilation tool chains provided are 5 bit and the build system itself has some hard coded 5 bit assumptions.

3or those wondering why <oogle switched to 5 bit, I ;uote the Technical %ead from the Android

pen *ource 6ro&ect at <oogle, as he explained it to me on the ' Android Building ' <oogle <roup. They

had some very good reasons to switch to 5 bit"

7art )an 7os = :-.:-.4:9- 6age 9

Page 2: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 2/18

 – >e had to move to 5?bit for <ingerbread anyway because of ava 9.5 dropping -4?bit support

on Mac*.

 – >e have several parts of the build that come very close to filling a -4?bit address space #and

some advanced internal builds at <oogle go over the limit$.

 –0ompiling gcc as 5?bit measurably speeds up the build.

7eside the fact that you consider this as a useful exercise or not, one thing is for sure" it forced me to

see how the build system worked in more detail and learned me a lot of things I did not know before.

The rest of this document focusses on the following things"

9. Initialise your environment and getting the correct sources.

4. 0reate your own kernel and user space cross compilation tool chains.

-. Ad&ust the build system in order to build Android on a -4 bit machine, using your newly createdtool chain.

. 0ompile your build and check the results.

I am targeting the ARM target achitecture #armeabi?v@a$ using a tool chain with <00 .5, used by

default on the android?.4.4r9 branch #Android .4.4 release 9" 94 3eb 4:9-$. I guess, similartechni;ues can be used on other branches with other tool chains for other target architectures. Armeabi

stands for ARM !mbedded Application 7inary Interface and is being used within the 0ortex family,

including their AB, AC, AD and A9B series. Most tablets and smartphones today use AC and AD cores.

Device Manufacturer CPU Processor Family

 /exus * *amsung *amsung Eummingbird 0ortex AC

Foom Motorola /vidia Tegra 4 0ortex AD dual core

<alaxy Tab @'' *amsung *amsung Eummingbird 0ortex AC

<alaxy Tab 9:.9 *amsung /videa Tegra 4 0ortex AD dual core

%e6hone %enovo Gualcomm *napdragon 0ortex AC based

M+C:D E(MI *martT) 6ointf)iew R+-:55 0ortex AD dual core

7art )an 7os = :-.:-.4:9- 6age 4

Page 3: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 3/18

2. Initializing and getting the sources

As mentioned in the introduction, we are going to focus on the following A*6 branch"  Android 4.2.2release 1. The first thing we need to do is to get the sources, both for building Android and the tool

chains. 3or the sake of clarity, I will define two shell environment variables that will point to the

corresponding folders, where the sources &ust mentioned are checked out. 3eel free to set thoseaccording to your own preference.

export ANDROID_TOOLCHAIN='/home/boeboe/android-toolchain'

export ANDROID_AO!='/home/boeboe/android-"rc'

"#do c#rl http"$//dl-""l%&oo&le%com/dl/&oo&le"o#rce/&it-repo/repo /#"r/local/bin/repo

"#do chmod ax /#"r/local/bin/repo

nce we have installed repo #a wrapper around git used by <oogle$ we can fetch the sources. 7eware

this might take ;uiet some time to complete #around half an hour$.

cd (ANDROID_TOOLCHAIN

repo init -# http"$//android%&oo&le"o#rce%com/toolchain/mani)e"t

repo "*nc

cd (ANDROID_AO!

repo init -# http"$//android%&oo&le"o#rce%com/plat)orm/mani)e"t -b android-+%,%,_r

repo "*nc

 /ext step is to get the necessary dependancies or re;uired packages on your 8buntu system"

"#do apt-&et in"tall &it &n#p& )lex bi"on &per) b#ild-e""ential .

  ip c#rl libc0-de1 libnc#r"e"2-de1$i340 xproto-core-de1 .

  libx-de1$i340 libreadline0-de1$i340 lib&l-me"a-&lx$i340 .

  lib&l-me"a-de1 &-m#ltilib min&53, to)rodo" .

  p*thon-mar6do5n libxml,-#til" x"ltproc lib&-de1$i340

 

As a last step, we will set?up the ccache compilation tool. 0cache acts as a compiler cache that can be

used to speed?up rebuilds. This works very well if you do Hmake cleanH often, or if you fre;uently

switch between different build products. 7y default the cache will be stored in 1.ccache. If your homedirectory is on /3*, you will want to specify the directory in your .bashrc as well. The suggested cachesiJe is B:?9::<7.

export 78_CCACH8=

export CCACH8_DIR=9path-to-*o#r-cache-director*:

preb#ilt"/mi"c/lin#x-x40/ccache/ccache -; 2<

7art )an 7os = :-.:-.4:9- 6age -

Page 4: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 4/18

3. Cross compilation tool chain creation

7efore we can start compiling our tool chains, we will need to find out how the original 5 bit tool

chains were created. I had to do this because in my first attempt I &ust compiled the latest greatest tool

chain #gcc @. based$ using the specs from the main A*6 branch. 8sing that tool chain resulted in a

unrecogniJed linker option #??icfKsafe$ during linking of my compiled A*6 ob&ects. Investigating theissue pointed out that I was missing ld.gold. <old is a linker for !%3 files, that was added to binutils

from version 4.9D onwards. <old was developed by a small team at <oogle. The motivation for writinggold was to make a linker that is faster than the </8 linker ld.bdf, especially for large applications

coded in 022.

%earning the hard way, I decided to remain as close as possible of what was available for 5 bit on the

exact same branch. %et's have a look where those original binary 5 toolchains are located and howthey were compiled by google. 6recompiled tool chains are available in the A*6 source tree under the

 prebuilds1gcc folder for the following target architectures" ARM, Eost, MI6* and FC5. 3or ARM you'll

find two of them" arm?eabi?.5 and arm?linux?androideabi?.5. The first being the kernel toolchain, thelatter being the normal toolchain for user space compilation and linking. The toolchains locations

contain a file called *8R0!*, that will tell you the details we are looking for.

cat (ANDROID_AO!/preb#ilt"/&cc/lin#x-x40/arm/arm-eabi-+%0/O7RC8

  Con)i&#re option"$

  export CC=>&cc -m0+>

  export C??=>& -m0+>

  export A@I=0+

  path/to/b#ild/con)i&#re --tar&et=arm-eabi .

  --ho"t=x40_0+-lin#x-&n# --b#ild=x40_0+-lin#x-&n# .

  --5ith-&cc-1er"ion=+%0 --5ith-bin#til"-1er"ion=,%, .

  --5ith-&mp-1er"ion=+%,%+ --5ith-mp)r-1er"ion=,%+% .

  --5ith-&db-1er"ion=%3%x --5ith-arch=arm12te .

  --5ith-"*"root=Bic" &eneric "*"root .

  --5ith-&old-1er"ion=,%, --di"able-&old .

  --di"able-m#ltilib

  &cc/ "*nced to commit 4,d2dbc3+ad)a4a,<)4+eb3b3)24a

  bin#til"/ "*nced to commit +)a40c<b23a4<a,dae<2)0d0b42ed0e<,ed

  &db/ "*nced to commit d3)bc+c+,<,b)d342a3d3b443d<d343

  &mp/ "*nced to commit )b,+,add,,d)b)40da)20,<dba0,bd,e

  mp)r/ "*nced to commit da0d)de40a)b20)<)+e)2de0d<3)a4a)<

  b#ild/ "*nced to commit bdb2<d+ede<c,cd0bd30b<ec<,03d2)

  expat/ "*nced to commit +<,a<aed+<a<04)ea+4))c)0acc)02ed2

cat (ANDROID_AO!/preb#ilt"/&cc/lin#x-x40/arm/arm-lin#x-androideabi-+%0/O7RC8

  Con)i&#re option"$

7art )an 7os = :-.:-.4:9- 6age

Page 5: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 5/18

  export CC=>&cc -m0+>

  export C??=>& -m0+>

  export A@I=0+

  path/to/b#ild/con)i&#re --tar&et=arm-lin#x-androideabi .

  --ho"t=x40_0+-lin#x-&n# --b#ild=x40_0+-lin#x-&n# .

  --5ith-&cc-1er"ion=+%0 --5ith-bin#til"-1er"ion=,%, .

  --5ith-&mp-1er"ion=+%,%+ --5ith-mp)r-1er"ion=,%+% .

  --5ith-&db-1er"ion=%3%x --5ith-arch=arm12te .

  --5ith-"*"root=Bic" &eneric "*"root .

  --5ith-&old-1er"ion=,%, --enable-&old=de)a#lt

  &cc/ "*nced to commit 4,d2dbc3+ad)a4a,<)4+eb3b3)24a

  bin#til"/ "*nced to commit +)a40c<b23a4<a,dae<2)0d0b42ed0e<,ed

  &db/ "*nced to commit d3)bc+c+,<,b)d342a3d3b443d<d343

  &mp/ "*nced to commit )b,+,add,,d)b)40da)20,<dba0,bd,e

  mp)r/ "*nced to commit da0d)de40a)b20)<)+e)2de0d<3)a4a)<

  b#ild/ "*nced to commit bdb2<d+ede<c,cd0bd30b<ec<,03d2)

  expat/ "*nced to commit +<,a<aed+<a<04)ea+4))c)0acc)02ed2

>e can see the configure arguments and git checkouts used on the toolchain sources. It also tells us

which extra <00 modules #and versions$ we need to make available during our compilation. Eereby a

small overview of those modules, including some used in the latest <00 .@ of the A*6 MAI/ branch.

Module What? 4.2.2_r1 version M!" version

<(7 </8 (ebugger @.-.x @.-.x

<M6 </8 Multiple 6recision %ibrary .4. B.:.B

7in8tils </8 0ollection of binary tools 4.49 4.44

M63R Multiple 6recision 3loating point computations

with correct Rounding

4..9 -.9.9 L 4..9

M60 Multiple 6recision 0omplex ? 9.:.9 L :.C.9

<old !%3 %inker from <oogle 4.49 ?

<raphite 6olyhedral 0ompilation 6ackage disabled enabled

0loog 0hunky %oop <enerator ? :.9@.:

66% 6arma 6olyhedra %ibrary ? 9.:

As you can see, <oogle is continuously updating their <00 and needed modules to stay ahead of the

game. ou will find tarballs containing the sources of most of those modules in the toolchain source

tree. ou will need to extract those in the location where <oogle conveniently checked in those tarballs,

in order for configure to pick them up correctly, as mentioned in the official <00 build documentation.

7art )an 7os = :-.:-.4:9- 6age B

Page 6: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 6/18

cd (ANDROID_TOOLCHAIN/&mp

tar x1)E &mp-+%,%+%tar%b,

cd (ANDROID_TOOLCHAIN/mp)r

tar x1)E mp)r-,%+%%tar%b,

<(7 and 7in8tils are available as sources directly, so no need to extract them. n main, you'll need to

extract some extra tarballs, but I guess you get the point.

In order for our -4 bit build to match as closely as possible to the 5 bit one, we now line?up thetoolchain source tree with the git hash values mentioned earlier. ust &ump to the corresponding

directories and do the correct checkout. ne example for gcc"

cd (ANDROID_TOOLCHAIN/&cc

&it chec6o#t 4,d2dbc3+ad)a4a,<)4+eb3b3)24a

 /ow is the time we start constructing our configure statements needed. I left out anything that smellslike 5 bit stuff and came up with the following configure lines"

%/con)i&#re --tar&et=arm-eabi --ho"t=i040-lin#x-&n# --b#ild=i040-lin#x-&n# --di"able-&old .

  --5ith-&cc-1er"ion=+%0 --5ith-bin#til"-1er"ion=,%, --5ith-&mp-1er"ion=+%,%+ .

  --5ith-mp)r-1er"ion=,%+% --5ith-&db-1er"ion=%3%x --5ith-&old-1er"ion=,%, .

  --pre)ix=/tmp/arm-eabi-+%0 --di"able-m#ltilib .

  --pro&ram-tran")orm-name='"FGFarm-eabi-F' .

  --5ith-lib"=(ANDROID_AO!/preb#ilt"/nd6/4/plat)orm"/android-+/arch-arm/#"r/lib .

  --5ith-header"=(ANDROID_AO!/preb#ilt"/nd6/4/plat)orm"/android-+/arch-arm/#"r/incl#de .

  --5ith-arch=arm12te --di"able-option-chec6in&

%/con)i&#re --tar&et=arm-lin#x-androideabi --ho"t=i040-lin#x-&n# --b#ild=i040-lin#x-&n# .

  --5ith-&cc-1er"ion=+%0 --5ith-bin#til"-1er"ion=,%, --5ith-&mp-1er"ion=+%,%+ .

  --5ith-mp)r-1er"ion=,%+% --5ith-&db-1er"ion=%3%x --5ith-&old-1er"ion=,%, .

  --pre)ix=/tmp/arm-lin#x-androideabi-+%0 --enable-&old .

  --pro&ram-tran")orm-name='"FGFarm-lin#x-androideabi-F' .

  --5ith-lib"=(ANDROID_AO!/preb#ilt"/nd6/4/plat)orm"/android-+/arch-arm/#"r/lib .

  --5ith-header"=(ANDROID_AO!/preb#ilt"/nd6/4/plat)orm"/android-+/arch-arm/#"r/incl#de .

  --5ith-arch=arm12te -di"able-option-chec6in&

The disable-option-checking  flag was added in order for configure to accept all arguments, especiallythe two new flags added" with-libs and with-headers. If you do not include those two flags, you'll get

the following compilation error"

In )ile incl#ded )rom %%/%%/%/&cc/&thr-de)a#lt%h$$<

7art )an 7os = :-.:-.4:9- 6age 5

Page 7: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 7/18

  )rom %%/%%/%%/combined/lib&cc/%%/&cc/&thr%h$0<

  )rom %%/%%/%%/combined/lib&cc/%%/&cc/#n5ind-d5,%c$3$

  %%/%%/%%/combined/lib&cc/%%/&cc/&thr-po"ix%h$+$,$ )atal error$ pthread%h$

No "#ch )ile or director*% compilation terminated%

I searched online for a solution on this one, but could not find a working one, so I turned to the

documentation of the toolchain build system located in build1R!A(M!"

 

,%3 @#ildin& a "tandalone toolchain%

  The de)a#lt i" b#ildin& a barebone toolchain )or the Android de1ice tree%

  the barebone toolchain E#"t ha1e bin#til" &cc and &db% There are not

  tar&et C librar*% Thi" i" not con1enient to #"e )or application de1elopment%

  It i" po""ible to b#ild a "tandalone toolchain 5ith pre-b#ilt librarie" and

  header"%

  %%%

  The other 5a* i" to "peci)* the header" and librarie" 5ith --5ith-header" and

  --5ith-lib" "eparatel*% I) *o# con)i&#re *o#r tree 5ith a pre)ix% The header"

  and librarie" 5ill be copied to the in"tall director* "peci)ied b* the pre)ix%

 /ext ;uestion I needed to ask myself was what folder am I going to pass along with those 4 new flags

documented over here. I tried to use the build-sysroot.sh script included in the same build folder, but

failed to create a sysroot #an alternative method mentioned in R!A(M!$. The errors I got there pointed me to some files, which I grepped for and found in the ndk1C1platforms1android?9 folders. I

found more of them, but /(+ vC combined with platform?9 was the latest greatest I could found, so Igave it a shot. In the end it compiled and seemed to work. I've asked more information about thistowards the <oogle developers working on the toolchain build system, but did not get a response so far.

I'll update this section once I have some reply.

After issuing the configure statements from within the build folder we can start the building and

installation of both toolchains using the standard procedure.

ma6e

ma6e in"tall

our -4 bit versions of the <00 5. based ARM cross compilation toolchains are now located in the

 prefix folders stated earlier in the configure flags" 1tmp1arm?eabi?.5 and 1tmp1arm?linux?androideabi?

.5. /ow you need to place them in exactly the same place as where the original 5 bit prebuildtoolchains are located, that is in the A*6 tree under file prebuilts1gcc1linux?xC51arm. In my case, I

moved the 5 bit versions to different subfolders and put the -4 bit version in there. ust to make sure

the correct toolchain is available, the following verification step"

7art )an 7os = :-.:-.4:9- 6age @

Page 8: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 8/18

cd (ANDROID_AO!

)ile preb#ilt"/&cc/lin#x-x40/arm/arm-eabi-+%0/bin/arm-eabi-&cc

  preb#ilt"/&cc/lin#x-x40/arm/arm-eabi-+%0/bin/arm-eabi-&cc$ 8LJ 3,-bit L@ exec#table

Intel 4<340 1er"ion KM d*namicall* lin6ed K#"e" "hared lib" %%%

)ile preb#ilt"/&cc/lin#x-x40/arm/arm-lin#x-androideabi-+%0/bin/arm-lin#x-androideabi-&cc

  preb#ilt"/&cc/lin#x-x40/arm/arm-lin#x-androideabi-+%0/bin/arm-lin#x-androideabi-&cc$

8LJ 3,-bit L@ exec#table Intel 4<340 1er"ion KM d*namicall* lin6ed

It seems we have a winner. ou can also decide to use a different toolchain as the one originally

integrated in the build system, but it will re;uire you to do some extra modifications in the build folder

of the A*6 source tree. <repping for arm?linux?androideabi?.5 and renaming those strings to whatyou want will work, as I did so in order to use the .@ toolchain before$. I believe it took me - more

changes which I'll not mention in the next section, since we use the same toolchain as integrated.

3or me, the hardest part was over after this. The next section I found out by trial and error doing around

4: iterations of building, failing, editing make files and restarting make again #no cleaning in between$.

This took ;uiet some time, since you have to wait ;uiet some time between each iteration like this.

4. Tweak the build system for 32 bit usage

n a 5 bit machine, the normal procedure to start a build is documented very well. >e will build the

 full-eng  target, is this is the development configuration with additional debugging tools for an emulator,

fully configured with all languages, apps and input methods.

cd (ANDROID_AO!

"o#rce b#ild/en1"et#p%"h

l#nch )#ll-en&

ma6e K-E+

I put the &obs parameter of make between brackets on purpose, because when you are doing builditerations to patch all needed files in the A*6 build system, you don't want to get lost in parallel

traces. nce your build system is properly patched however, choose a values that e;uals 4 times the

number of cores of your machine #which was in my case$.

7efore we proceed patching the first files related to 5 bit compilation issues, a small remark onmemory of the )M used. I got the following error after building for a while"

 &ava.lang.utfMemory!rror" <0 overhead limit exceeded

7art )an 7os = :-.:-.4:9- 6age C

Page 9: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 9/18

The solution, commonly documented online, was to patch the following file in the build folder,

changing &ava's maximum heap siJe"

di)) --&it a/core/de)inition"%m6 b/core/de)inition"%m6

- (Ki) (K)ind"trin& 5indo5"(KHOT_O-P?m"0; -P?mx,<+4; .

(Ki) (K)ind"trin& 5indo5"(KHOT_O-P?m"0; -P?mx<,+; .

 /ow let's start the build as mentioned before #skipping parallel &obs$. The first error you'll probably getis the following"

8RROR$ preb#ilt"/tool"/&cc-"d6/%%/%%/&cc/lin#x-x40/ho"t/x40_0+-lin#x-&libc,%-+%0/bin/x40_0+-lin#x-&cc onl* r#n on 0+-bit lin#x

This is due to the fact that in  prebuilts/tools/gcc-sdk/gcc the incorrect E*T toolchains is selected bydefault. The options are checked and based on the length, a decision is made to select the -4 bit or the

5 bit host toolchain. I commented out the if condition leading to a 5 bit selection to always select the-4 bit variant # prebuilts/gcc/linux-x8/host/i8-linux-glibc2.!-4./bin/i8-linux$.

!R8JI?3,=%%/%%/&cc/lin#x-x40/ho"t/i040-lin#x-&libc,%-+%0/bin/i040-lin#x

option"=> (QS > "entinel pre)ix/"#))ix "pace to "impli)* pattern match belo5

"#))ix_m3,=(Qoption"U -m3, S "#))ix a)ter the la"t -m3,

len_m3,=(Q"#))ix_m3,S len&th o) "#))ix a)ter the la"t -m3,

Al5a*" choo"e 3,-bit

;_TOOL=Vdirname (<V/(Q!R8JI?3,S-(Q!RONA;8S

ou will also have noticed the error discussed here when running lunch, because it also does some

 basic checks on the same file we &ust edited. After this modification lunch should complete cleanly,

without any warnings or errors.

l#nch )#ll-en&

============================================

!LATJOR;_M8RION_COD8NA;8=R8L

!LATJOR;_M8RION=+%,%,

TAR8T_!ROD7CT=)#ll

TAR8T_@7ILD_MARIANT=en&TAR8T_@7ILD_T!8=relea"e

TAR8T_@7ILD_A!!=

TAR8T_ARCH=arm

TAR8T_ARCH_MARIANT=arm1-a

HOT_ARCH=x40

7art )an 7os = :-.:-.4:9- 6age D

Page 10: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 10/18

HOT_O=lin#x

HOT_O_8?TRA=Lin#x-3%,%<-34-&eneric-i040-5ith-7b#nt#-,%<+-preci"e

HOT_@7ILD_T!8=relea"e

@7ILD_ID=PDW3

O7T_DIR=o#t

============================================

6roceed making and let's discuss the next error you will encounter. This will take a long time, so en&oy

yourself with some well deserved break in the meanwhile.

In"tall$ o#t/ho"t/lin#x-x40/bin/em#lator-x40

tar&et enerated$ em#lator0+-arm 9= external/Xem#/Xem#-monitor%hx

tar&et enerated$ em#lator0+-arm 9= external/Xem#/Xem#-option"%hx

8xport incl#de" )ile$ external/Xem#/;a6e)ile%android -- o#t/ho"t/lin#x-x40/obE/TATIC_LI@RARI8/em#lator0+-lib#i_intermediate"/export_incl#de"

%%%

Import incl#de" )ile$ o#t/ho"t/lin#x-x40/obE/8?8C7TA@L8/em#lator0+-arm_intermediate"/import_incl#de"

ho"t C$ em#lator0+-arm 9= external/Xem#/a#dio/a#dio%c

8RROR$ preb#ilt"/tool"/&cc-"d6/%%/%%/&cc/lin#x-x40/ho"t/x40_0+-lin#x-&libc,%-+%0/bin/x40_0+-lin#x-&cc onl* r#n on 0+-bit lin#x

ma6e$ UUU Bo#t/ho"t/lin#x-x40/obE/8?8C7TA@L8/em#lator0+-arm_intermediate"/a#dio/a#dio%o8rror

>hen I saw this error, courage almost sunk into my shoes, since it looked a lot like the one we &ustfixed in the previous step. Are there two different code paths leading to the E*T toolchain selectionN

>e gonna need to do some patching in the external/"e#u folder this time. G!M8 is a fast processor

emulator using a portable dynamic translator.

This time, a lot of files are involved. If I forget to mention several, I will also provide my diffed patchfiles besides this document so can make sure you did not miss anything.

cd (ANDROID_AO!/external/Xem#

cat ;a6e)ile%common

  %%%

  8nable lar&e-)ile "#pport Ki%e% ma6e o))_t a 0+-bit 1al#e

  i)eX K(KHOT_Olin#x

  8;7LATOR_CO;;ON_CJLA = -D_JIL8_OJJ8T_@IT=0+ -D_LAR8JIL8_O7RC8

  8;7LATOR_CO;;ON_CJLA = -D_JIL8_OJJ8T_@IT=3, -D_LAR8JIL8_O7RC8

  endi)

  %%%

another )or 0+-bit

  NOT8$ onl* lin#x and dar5in in non-"tandalone mode i" "#pported beca#"e

  Jor Yindo5"$ amd0+-min&53,m"1c-&cc doe"n't 5or6 "ee http$//b/i""#eZid=2+2,%

7art )an 7os = :-.:-.4:9- 6age 9:

Page 11: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 11/18

  , tandalone ha" --tr*-0+

  i)neX K(K)ilter lin#x dar5in(KHOT_O

  i)neX K(K@7ILD_TANDALON8_8;7LATORtr#e

  (Kcall "tart-em#lator-librar* em#lator0+-common

  LOCAL_CJLA = (Kcommon_LOCAL_CJLA -m0+

  LOCAL_RC_JIL8 = (Kcommon_LOCAL_RC_JIL8

  (Kcall &en-h5-con)i&-de)"

  (Kcall end-em#lator-librar*

  endi) @7ILD_TANDALON8_8;7LATOR == nil

  endi) HOT_O == lin#x [[ dar5in

  %%%

  another )or 0+-bit "ee note in em#lator0+-common

  i)neX K(K)ilter lin#x dar5in(KHOT_O

  i)neX K(K@7ILD_TANDALON8_8;7LATORtr#e

  (Kcall "tart-em#lator-librar* em#lator0+-lib#i

  LOCAL_CJLA = (Kcommon_LOCAL_CJLA -m0+

  LOCAL_RC_JIL8 = (Kcommon_LOCAL_RC_JIL8

  (Kcall &en-h5-con)i&-de)"

  (Kcall end-em#lator-librar*

  endi) @7ILD_TANDALON8_8;7LATOR == nil

  endi) HOT_O == lin#x [[ dar5in

  %%%

  i)eX K(KHOT_ARCHx40

  COR8_;IC_O7RC8 = i340-di"%c

  endi)

  i)eX K(KHOT_ARCHx40_0+  COR8_;IC_O7RC8 = i340-di"%c

  endi)

  i)eX K(KHOT_ARCHppc

  COR8_;IC_O7RC8 = ppc-di"%c .

  cache-#til"%c

  endi)

  99 3 more bloc6" 5ith the comment \another )or 0+-bit "ee note in em#lator0+-common] ::

7esides the changes made on the (3I%!33*!T7IT*K-4 flag, all other changes embody the

commenting out #you can delete them if you want of course$ 5 bit specific blocks that start with thecomment Oanother for 4-bit$ see note in e#ulator4-co##onP. I used this techni;ue for all upcoming patches made in various components in the A*6 source tree, so its important to stress this out over

here.

>ith regards to the ;emu component, apply similar changes in the %akefile.target  file. The last two file

we need to patch are android-configure.sh and android/build/co##on.sh.

7art )an 7os = :-.:-.4:9- 6age 99

Page 12: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 12/18

cat android-configure.sh (set 64 bit option to no)

  ...

  #--try-64) OPTION_T!_64"yes

  --try-64) OPTION_T!_64"no

  ...

cat androidbui$dco%%on.sh (re%o&e if condition)

  ...

  # this function shou$d be ca$$ed to enforce the bui$d of '-bit binaries on 64-bit syste%s

  # that support it.

  O*+_',IT"yes

  force_'bit_binaries ()

 

  # if /*P0 " 126_64 3 then

  O*+_',IT"yes

  case /O5 in

  $inu1-126_64) O5"$inu1-126

  darin-126_64) O5"darin-126

  freebsd-126_64) O5"freebsd-126

  esac

  7O5T_8*7"126 

  *P0"126 

  co%pute_host_tag 

  $og 9*hec:',its; orcing generation of '-bit binaries (--try-64 to disab$e)9

  # fi

  <

  ...

This should cover all changes made on the ;emu component so proceed building with make. The nextcomponent causing problems is located in the external/oprofile folder. profile is a continuous system?

wide profiler for %inux.

host +1ecutab$e; obbtoo$ (outhost$inu1-126ob=+>+*0T8,?+5obbtoo$_inter%ediatesobbtoo$)

Insta$$; outhost$inu1-126binobbtoo$

+1port inc$udes fi$e; e1terna$oprofi$e$ibpp8ndroid.%: -- outhost$inu1-

126ob=5T8TI*_?I,8I+5$iboprofi$e_pp_inter%ediatese1port_inc$udes

+1port inc$udes fi$e; e1terna$oprofi$e$ibdb8ndroid.%: -- outhost$inu1-

126ob=5T8TI*_?I,8I+5$iboprofi$e_db_inter%ediatese1port_inc$udes

+1port inc$udes fi$e; e1terna$oprofi$e$ibrege18ndroid.%: -- outhost$inu1-

126ob=5T8TI*_?I,8I+5$iboprofi$e_op_rege1_inter%ediatese1port_inc$udes

+1port inc$udes fi$e; e1terna$oprofi$e$ibopt@@8ndroid.%: -- outhost$inu1-

126ob=5T8TI*_?I,8I+5$iboprofi$e_opt@@_inter%ediatese1port_inc$udes

+1port inc$udes fi$e; e1terna$oprofi$e$ibuti$@@8ndroid.%: -- outhost$inu1-

7art )an 7os = :-.:-.4:9- 6age 94

Page 13: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 13/18

126ob=5T8TI*_?I,8I+5$iboprofi$e_uti$@@_inter%ediatese1port_inc$udes

+1port inc$udes fi$e; e1terna$oprofi$e$ibpopt8ndroid.%: -- outhost$inu1-

126ob=5T8TI*_?I,8I+5$iboprofi$e_popt_inter%ediatese1port_inc$udes

+1port inc$udes fi$e; e1terna$oprofi$e$ibop8ndroid.%: -- outhost$inu1-

126ob=5T8TI*_?I,8I+5$iboprofi$e_op_inter%ediatese1port_inc$udes

+1port inc$udes fi$e; e1terna$oprofi$e$ibuti$8ndroid.%: -- outhost$inu1-

126ob=5T8TI*_?I,8I+5$iboprofi$e_uti$_inter%ediatese1port_inc$udes

%a:e; AAA No ru$e to %a:e target Bouthost$inu1-126ob=5T8TI*_?I,8I+5$ibbfd_inter%ediatese1port_inc$udesCD needed by Bouthost$inu1-

126ob=+>+*0T8,?+5opannotate_inter%ediatesi%port_inc$udesC. 5top.

*earching for the error online, pointed me to a solution to disable the  &A'()*+BB, flag set in the

co##on.#k  makefile.

cd (ANDROID_AO!/external/opro)ile

cat common%m6

  %%%

  HAM8_LI@@JD $= tr#e

  HAM8_LI@@JD $= )al"e  %%%

This flag is responsible for enabling or disabling the 7inary 3ile (escriptor %ibrary in your oprofile. I

cannot elaborate on the actual impact of disabling this functionality, because I don't know. I have asked

a ;uestion regarding the impact or a possible other solution on the ' Android Building ' <oogle <roup, somaybe there is a better solution. ne thing I did notice is that the 73( library is in fact available as a

static library in the toolchain we are using.

cd (ANDROID_AO!/preb#ilt"/&cc/lin#x-x40/arm/arm-lin#x-androideabi-+%0/lib3,

l" -

  libb)d%a  libb)d%la

  libibert*%a

  libintl%a

cat libb)d%la

  %%%

  Director* that thi" librar* need" to be in"talled in$

  libdir='/tmp/toolchain/i040-pc-lin#x-&n#/arm-lin#x-androideabi/lib'

The libbfd.la file is suggesting something about a folder where the library should be installed, but I did

not try this so don't know if it would work either. 3eel free to try so and keep me up to date of yourfindings. (isabling the flag is what I did and now we can compile oprofile.

The following list of final changes on various components in the A*6 source tree, all include thestrategy I mentioned earlier on commenting out 5 bit blocks in the  Android.#k  makefiles of those

specific components. The comments on top of those blocks might vary a little bit, but in general will

contain some 5?bit reference. I will show the first change and then provide a list of makefiles that also

7art )an 7os = :-.:-.4:9- 6age 9-

Page 14: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 14/18

need to be patched, in order to keep this document more concise.

cd (ANDROID_AO!

cat em#lator/open&l/ho"t/lib"/L81_dec/Android%m6

  %%%

  ho"t librar* 0+-bit   (Kcall em#&l-be&in-ho"t-"tatic-librar*lib0+L81_dec

  (Kcall em#&l-import lib0+Open&lCodecCommon lib0+Open&lO"7til"

  (Kcall em#&l-exportC_INCL7D8(KLOCAL_!ATH

  (Kcall em#&l-&en-decoder(KLOCAL_!ATH&l

  LOCAL_RC_JIL8 $= LDecoder%cpp

  (Kcall em#&l-exportCJLA(Kho"t_common_deb#&_CJLA -m0+

  (Kcall em#&l-end-mod#le

  %%%

The list of other components and makefiles that need similar patching"

"d6/em#lator/open&l/ho"t/lib"/L81_dec/Android%m6

"d6/em#lator/open&l/ho"t/lib"/L81,_dec/Android%m6

"d6/em#lator/open&l/ho"t/lib"/libOpen&lRender/Android%m6

"d6/em#lator/open&l/ho"t/lib"/renderControl_dec/Android%m6

"d6/em#lator/open&l/ho"t/lib"/Tran"lator/8L/Android%m6

"d6/em#lator/open&l/ho"t/lib"/Tran"lator/L8_C;/Android%m6

"d6/em#lator/open&l/ho"t/lib"/Tran"lator/L8_M,/Android%m6"d6/em#lator/open&l/ho"t/lib"/Tran"lator/Lcommon/Android%m6

"d6/em#lator/open&l/"hared/Open&lCodecCommon/Android%m6

"d6/em#lator/open&l/"hared/Open&lO"7til"/Android%m6

"*"tem/core/liblo&/Android%m6

"*"tem/core/libc#til"/Android%m6

)rame5or6"/nati1e/lib"/#til"/Android%m6

<ood newsQ In case I did not forget any changes, these are the last changes needed on order for the fill build to succeed. The build traces at the end for your information"

%%%

enerated$ Ko#t/tar&et/prod#ct/&eneric/android-in)o%txt

Insta$$ed  )ile li"t$ o#t/tar&et/prod#ct/&eneric/in"talled-)ile"%txt

Tar&et "*"tem )" ima&e$

7art )an 7os = :-.:-.4:9- 6age 9

Page 15: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 15/18

o#t/tar&et/prod#ct/&eneric/obE/!AC^AIN/"*"temima&e_intermediate"/"*"tem%im&

R#nnin&$ m6*a))",ima&e -) o#t/tar&et/prod#ct/&eneric/"*"temo#t/tar&et/prod#ct/&eneric/obE/!AC^AIN/"*"temima&e_intermediate"/"*"tem%im&

In"tall "*"tem )" ima&e$ o#t/tar&et/prod#ct/&eneric/"*"tem%im&

Tar&et ram di"6$ o#t/tar&et/prod#ct/&eneric/ramdi"6%im&

Tar&et #"erdata )" ima&e$ o#t/tar&et/prod#ct/&eneric/#"erdata%im&

R#nnin&$ m6*a))",ima&e -) o#t/tar&et/prod#ct/&eneric/datao#t/tar&et/prod#ct/&eneric/#"erdata%im&

9%%% and they $i&ed happi$y  e1er a)ter $ %%%:

The emulator is added to your path automatically by the build process. *tart this emulator to verify

your end result.

em#lator F

7art )an 7os = :-.:-.4:9- 6age 9B

Page 16: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 16/18

5. Chec the result

nce you compiled your A*6 build succesfully, you probably want to use parallel &obs, after doingyour code changes, to speed up the build process.

ma6e -E+

The resulting output of your build is locate in the out  folder. It is possible to change this by setting anextra shell environment variable.

export O7T_DIR_CO;;ON_@A8=9path-to-*o#r-o#t-director*:

 /ow lets have a look at the structure of the output.

cd (ANDROID_AO!

tree -d -L 3 o#t

  o#t

  `` ho"t

  `` common

  `` obE

  `` lin#x-x40

  `` bin

  `` )rame5or6

  `` lib

  `` obE

  `` #"r

  `` tar&et

  `` common

  `` doc"

  `` obE

  `` R

  `` prod#ct

  `` &eneric

The resulting image files are locate in the following directory"

l" - o#t/tar&et/prod#ct/&eneric/

android-in)o%txt

  clean_"tep"%m6

7art )an 7os = :-.:-.4:9- 6age 95

Page 17: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 17/18

  data

  dex_bootEar"

  in"talled-)ile"%txt

  obE

  pre1io#"_b#ild_con)i&%m6

  ramdi"6%im&

  root

  "*mbol"

  "*"tem

  "*"tem%im&

  te"t

  #"erdata%im&

#$D$% give a more extensive of what is included, possible going deeper into some more interestingsections of the output

7art )an 7os = :-.:-.4:9- 6age 9@

Page 18: Building Android

7/21/2019 Building Android

http://slidepdf.com/reader/full/building-android 18/18

!. "e#erences and other use#ul lins

fficial Android pen *ource 6ro&ect documentation

http"11source.android.com1source1index.htmlhttp"11source.android.com1source1initialiJing.html

http"11source.android.com1source1downloading.html

http"11source.android.com1source1building.html

7uild A*6 using !clipse

http"11source.android.com1source1using?eclipse.html

The ' Android Building ' <oogle <roup

https"11groups.google.com1forum1NfromgroupsKQforum1android?building

The %I773( problem in oprofile"

http"11forum.xda?developers.com1showthread.phpNpK-@BB@-

Eow to port different RM* to your device

http"11forum.xda?developers.com1showthread.phpNtK9D:C::C

et another tutorial on building Android from sources

http"11mobisocial.stanford.edu1news14:991:41yet?another?tutorial?on?building?android?from?sources1

<nu <00 documentation

http"11gcc.gnu.org1install1prere;uisites.html

http"11gcc.gnu.org1install1configure.html

http"11gcc.gnu.org1install1build.html

Android's upstream toolchain information

https"11wiki.linaro.org16latform1Android18pstreamToolchain

7rowsable Android <it repositories

https"11android.googlesource.com1NformatKETM%

Eow to rebuild Android gdbserver 

http"11www.omappedia.com1wiki1Android?Eow?toRebuildgdbserver 

Eow to build elly 7ean .9.9 on 8buntu 94.:.9 %T*

http"11osforge.blogspot.be14:9-1:91how?to?build?&elly?bean?99?on?ubuntu.html

Android *ensor 6orting<uide"

http"11processors.wiki.ti.com1index.php1Android*ensor6orting<uide

7art )an 7os = :-.:-.4:9- 6age 9C