Android : First step – Download and build

This document provides a wiki for setting up a local environment on Linux Ubuntu to work on Android source code.
1. Getting Android source code
a. Prerequisites : Android build requires some tools. Some of them are automatically installed while Linux is installed. Other can be installed using following command from shell:
$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl sun-java5-jdk zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev
b. Repo : repo is infact a shell script works as a tools which makes it easier to work with Git in the context of Android. To install, initialize and configure Repo, follow these steps:
- Create a “bin” directory in $HOME and make sure that directory is in our path:
$cd ~
$mkdir bin
$export PATH=$PATH:$HOME/bin
- Download Repo :
$curl  http://android.git.kernel.org/repo >~/bin/repo
$chmod a+x ~/bin/repo
- Initializing a Repo client behind Polimi proxy.
$mkdir myandroid
$cd myandroid
Because of the proxy, git protocol will not work and we are going to receive a

“connection refused” message.

android.git.kernel.org[0: 204.152.191.45]: errno=Connection refused

android.git.kernel.org[0: 149.20.20.141]: errno=Connection refused

if we try to execute the init process

$ repo init -u git://android.git.kernel.org/platform/manifest.git
To fix this problem we have to follow below steps to force repo to work using http protocol instead of git.

$export http_proxy = http://<your_proxy>:8080

$git config –global http.proxy http://<your_proxy>:8088

//Now we have to make some modification to original Repo tools

$ gedit ~/bin/repo

//Change the line

//REPO_URL=’git://android.git.kernel.org/tools/repo.git’

// by a new one

// REPO_URL=’http://android.git.kernel.org/tools/repo.git’

//Now we can initialize Repo

$ repo init -u http://android.git.kernel.org/platform/manifest.git
//This step will download some file which are stored in the hidden folder “.repo”
// In Linux, it is possible to press Ctrl + H to show the hidden folder
// Now we need to take 2 more modification to make Repo to be possible to work
// using http protocol.
$ gedit  .repo/manifest.xml
//replace this line git:// android.git.kernel.org” with “http://android.git.kernel.org”

$gedit .repo/repo/repo

//Replace this line with “git:// android.git.kernel.org/tools/repo.git” with “http://android.git.kernel.org/tools/repo.git”

- Sync: Now it’s possible to do sync process to download source code from repository server$repo sync

Since August 2009 the kernel is no longer part of the standard Repo’s manifest that you get when you follow the instructions to download the source code for the android open source project. The steps that are needed to successfully download, build and run a specific kernel on the emulator are as follows:

  • Get the Android kernel either by adding it to your repo manifest or manually by running: $git clone http://android.git.kernel.org/kernel/common.git

Check out the correct branch for working with the emulator, i.e. goldfish: git checkout -t origin/android-goldfish-2.6.29 -b goldfish

  • Generate the emulator configuration (qemu emulator runs arm code, i.e. an arm config): make ARCH=arm goldfish_defconfig
  • Now build the kernel using the cross compilation tools distributed with the open source project: make ARCH=arm CROSS_COMPILE=mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
  • The kernel built this way should end up in the arch/arm/boot folder of your kernel tree (where you put the code from git clone). To run the emulator with your kernel there are two alternatives, either copy it to the prebuilt kernel folder of the open source project to replace the standard kernel. The other option is to start the emulator with the kernel option set:
  • emulator -avd my_avd -kernel mydroid/kernel/common/arch/arm/boot/zImage (my_avd is created using Android SDK; emulator can be found in SDK/tools directory)

Note that the description above for default path, we need to change them to what applies to our setup. 
Some extra information: In the standard Android open source distribution the kernel is distributed as a pre-built binary in the mydroid/prebuilt/android-arm/kernel folder and the source code is not included. The common branch for the kernel is the one used by the emulator. There are also branches for experimental, msm (Qualcomm platforms) and Omap (TI platform) and maybe some more.

你可能感兴趣的:(Android : First step – Download and build)