2012年11月7日 星期三

Android Build Environment Setup

Preface

Following Instructions will lead you to know how to build a Android build Environment.

Setup Your Ubuntu

In case you'd like to have both of Windows and Ubuntu can work on a computer concurrently, you can install Oracle VM VirtualBox in your Computer/Notebook and then install Ubuntu on VirtualBox. You can follow the instruction below to setup your Android Build Environment. If you want to install Ubutun on a computer only, you can ignore installation of VirtualBox.

1. Download Oracle VirtualBox from https://www.virtualbox.org/.
2. Download Ubuntu 10.04 LTE from http://releases.ubuntu.com/lucid/ and choose the file named ubuntu-10.04.4-desktop-amd64.iso.
3. Install VirtualBox and Create a Virtual Ubuntu System on VirtualBox.
4. Install Ubuntu on VirtualBox.

Configure Your Ubuntu

1. Launch a terminal on Ubuntu.
2. Follow the instructions that Google said at  http://source.android.com/source/initializing.html to install the required tools.

Detailed instructions for Ubuntu and MacOS follow. In general you will need:
  • Python 2.5 -- 2.7, which you can download from python.org.
  • GNU Make 3.81 -- 3.82, which you can download from gnu.org,
  • JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older. You can download both from java.sun.com.
  • Git 1.7 or newer. You can find it at git-scm.com.

Install the following tools by executing console command below.

sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc

Because Canonical is no longer to support Oracle Java, you need to install the Oracle JDK6 manually. It means you cannot use apt-get tool to install Oracle JDK6. Follow the instruct at following section - Installation Instruction of Oracle J2SDK 6 on Ubuntu 10.04 64 bit to install the Oracle J2SDK6.

3. Download and install repo tool from Google - http://source.android.com/source/downloading.html.


Make sure you have a bin/ directory in your home directory, and that it is included in your path:

$ mkdir ~/bin
$ PATH=~/bin:$PATH
Download the Repo script and ensure it is executable:

$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

4. Initializing a Repo client


After installing Repo, set up your client to access the android source repository:

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

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.1.2_r1

Note that the parameter -b is followed by Android version. The Android version can be assigned to the latest version or previous version that Google released.  

When prompted, please configure Repo with your real name and email address. To use the Gerrit code-review tool, you will need an email address that is connected with a registered Google account. Make sure this is a live address at which you can receive messages. The name that you provide here will show up in attributions for your code submissions.

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.

5. Get the source code by repo
$ repo sync

6. After several hours, you may receive 6 to 8 GByte file in your storage.


Installation Instruction of Oracle J2SDK 6 on Ubuntu 10.04 64 bit 


1. Download binary file from http://www.oracle.com/technetwork/java/javase/downloads/jdk6u37-downloads-1859587.html and click jdk-6u37-linux-x64.bin to download

2. Root permission is required to install J2SDK.
3. Copy the file jdk-6u37-linux-x64.bin to /usr/lib/jvm folder.
# cp /Download_Folder_Path/jdk-6u37-linux-x64.bin /usr/lib/jvm/jdk-6u37-linux-x64.bin
# cd usr/lib/jvm/
# sh jdk-6u37-linux-x64.bin

4. After folder jdk1.6.0_37 is extracted, install it by using update-alternatives as follows,

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_37/bin/java 1000
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_37/bin/javac 1000
update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_37/bin/javaws 1000
update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.6.0_37/bin/jar 1000

The command of update-alternatives is a tool which can select particular tool version to be run on Linux. To view the manual by executing console command - "man update-alternatives" on Ubuntu.

5. Choose the option of Oracle Java by following command in case your Ubuntu has installed other Java VM (E.g. OpenJava).

#update-alternatives --config java

6. Check the Java version you used on your Ubuntu by following command.
# java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01, mixed mode)

Reference:
https://www.virtualbox.org/

沒有留言:

張貼留言