Digging deep inside the build

Hi guys,
This blog is gonna help you in building the android from source code.The Android is an open source and hence available freely over the internet on some privately owned repositories like git , google etc.
The build we are gonna work on is the android build.Which can be downloaded via a repo tool.The repo tool is just a wrapper around the git commands.So basically it shortens it up.Use this tool to download the source as it like git provides flexible environment to work with.
This tutorial demands the following pre-requisites


  1. Knowledge of android operating system.
  2. Repo/Git knowledge.
  3. Linux environment
So Before starting up let me just place the environment of my pc on which i ran this test.The pc was an acer laptop aspire5733 with an ubuntu10.04 64bitos inside it with the following configuration
RAM -1 gb
SwapSpace - nill
HDD-500 gb
Now it's time to build the environment for the build to run.The build requires a set of pre-installed softwares inside it for it to work.That includes python2.7 for the some repo scripts , some android monkeyrunner scripts,then there is make all those guys using linux must have heard this since they started using it.Make as the name suggests is used to compile and build large no. of files using a rule that is defined in the rules,but lets not dive into it.Just download the latest make software from the gnu site.Coming up is the java jdk1.6_u45(update 45) is what i got.

NOTE : Don't use open jdk as it's likely to cause some errors during the build.
The jdk can be installed via this link
https://help.ubuntu.com/community/Java , just browse down to the sun java as this is what we require for this to work.
Then lastly install the git atleast 1.7 or newer. i used git1.8.4

Don't worry i have made a script that you can just download and install these softwares to start building it.
here's a link to it,

if after installing this script doesn't install few things just install them manually
using the old way "sudo apt-get install blah blah"

Okay now the Initialization part is complete so now lets download the source code from android.The source i downloaded was android4.0.1_r1

Steps
    1. Make sure you have a bin/ directory in your home directory and that it is included in your path:
      $ mkdir ~/bin
      $ PATH=~/bin:$PATH
    2. Download the Repo tool and ensure that it is executable:
      $ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
      $ chmod a+x ~/bin/repo

      Initializing a Repo client


      After installing Repo, set up your client to access the Android source repository:
      1. Create an empty directory to hold your working files. If you're using MacOS, this has to be on a case-sensitive filesystem. Give it any name you like:
        $ mkdir WORKING_DIRECTORY
        $ cd WORKING_DIRECTORY
      2. Run repo init to bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest, which specifies where the various repositories included in the Android source will be placed within your working directory.
        $ repo init -u https://android.googlesource.com/platform/manifest
        To check out a branch other than "master", specify it with -b:
        $ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
      3. When prompted, configure Repo with your real name and email address.
      A successful initialization will end with a message stating that Repo is initialized in your working directory. Your client directory should now contain a .repo directory where files such as the manifest will be kept.

Downloading the Android Source Tree


To pull down the Android source tree to your working directory from the repositories as specified in the default manifest, run
$ repo sync
The Android source files will be located in your working directory under their project names. The initial sync operation will take few hours to complete.

After all this stuff is done,and you could see the directories inside the WORKING_DIRECTORY, just start with this process

Initialize


Initialize the environment with the envsetup.sh script. Note that replacing "source" with a single dot saves a few characters, and the short form is more commonly used in documentation.
$ source build/envsetup.sh
or
$ . build/envsetup.sh
Run these commands now to make it all well
export JAVA_HOME=/opt/jdk1.6  (press tab for hint of the complete version of java) then press enter
export PATH=/opt/jdk1.6<presstab>:$PATH
export ANDROID_JAVA_HOME=$JAVA_HOME

Choose a Target


Choose which target to build with lunch. The exact configuration can be passed as an argument, e.g.
$ lunch full-eng
The example above refers to a complete build for the emulator, with all debugging enabled.
If run with no arguments lunch will prompt you to choose a target from the menu.
All build targets take the form BUILD-BUILDTYPE, where the BUILD is a codename referring to the particular feature combination. Here's a partial list:
Build nameDeviceNotes
fullemulatorfully configured with all languages, apps, input methods
full_maguromagurofull build running on Galaxy Nexus GSM/HSPA+ ("maguro")
full_pandapandafull build running on PandaBoard ("panda")
and the BUILDTYPE is one of the following:
BuildtypeUse
userlimited access; suited for production
userdebuglike "user" but with root access and debuggability; preferred for debugging
engdevelopment configuration with additional debugging tools

Build the Code


Build everything with make. GNU make can handle parallel tasks with a -jN argument, and it's common to use a number of tasks N that's between 1 and 2 times the number of hardware threads on the computer being used for the build. E.g. on a dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), the fastest builds are made with commands between make -j16 and make -j32.
I used make  -j4 as it made more sense according the asus laptop,so suit yourself .
$ make -j4

Running it


The emulator is added to your path automatically by the build process. To run the emulator, type
$ emulator
That's it.now you'll be seeing the emulator running that source you downloaded.

Comments

  1. I did sync the code android_5.1.0_r3 but it is still running.. The. repo file is 15.3gb and I dono how much is remaining.. Can someone help..

    ReplyDelete

Post a Comment

Popular posts from this blog

Success with AndroVM

Setting up continuous integration on linux