Please remember to add a category to the bottom of each page that you create.
See categories help for further details, but most will probably be [[Category:HTC ModelName]].

Samsung Galaxy S/SGH-T959V/Set Up A Build Environment

From XDA-Developers
Jump to: navigation, search
Warning: Currently building Android with Windows is not supported. It is something better suited for Linux or Mac OSX anyhow.

Note: Building on a 64-bit machine is recommended, 32-bit is still experimental.

This tutorial will give you a quick rundown on how to setup an environment for building Android source files.

On Linux

Note: It is possible to build Android in a virtual machine, using VirtualBox for example, but this tutorial will not cover that. If you are running Linux in a virtual machine, you will need at least 16GB of RAM/swap and 30GB or more of disk space in order to build the Android tree.

While I personally set this up on Linux Minut 12, which is based on Ubuntu, just about any distribution should offer the required build tools. Most, if not all, should be available from your distribution's package manager like apt, yum, or pacman.

  • Python 2.5 - 2.7, from here.
  • GNU Make 3.81 - 3.82, from here.
  • Java Development Kit, from here.
    • Version 6 for Gingerbread or newer.
    • Version 5 for Froyo or older.
  • Git 1.7 or newer, from here.

Installing JDK on Ubuntu 10.04+

Taken from here.

JDK 6 (Gingerbread or newer)

Note that installing the sun-java6-sdk will only work on Ubuntu 11.10 and older! The PPA repository referenced here doesn't have any packages for Ubuntu Precise (12.04).

$sudo add-apt-repository ppa:ferramroberto/java
$sudo apt-get update
$sudo apt-get install sun-java6-jdk

JDK 5 (Froyo or older)

$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy main multiverse"
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy-updates main multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk

Installing JDK on Linux Mint

On my personal Linux box I did not have to add a third-party repository in order to use apt to install the JDK.

JDK 6 (Gingerbread or newer)

$ sudo apt-get install sun-java6-jdk

JDK 5 (Froyo or newer)

$ sudo apt-get install sun-java5-jdk

Installing Required Packages

Since Linux Mint x64 is my distribution of choice I am going to list the steps I took in order to get my environment up and running. I will include further steps listed on the Android page only for thoroughness. The steps should remain pretty much the same throughout, only minor changes in the actual commands used.

64-Bit (recommended)

$ 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 lib32readline-gplv2-dev lib32z-dev \
  libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
  libxml2-utils xsltproc

32-Bit (experimental)

$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
  zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev \
  libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown \
  libxml2-utils xsltproc

Additional Steps

If you're running an Ubuntu version listed below you will need to run one additional command.

Ubuntu 10.10

$ sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so

Ubuntu 11.10

$ sudo apt-get install libx11-dev:i386

Ubuntu 12.04

Currently Android does list instructions for building on Ubuntu 12.04, which is still in beta, so I will not list those steps here. You can check them out here.

Configure USB Access

Under GNU/Linux systems, specifically Ubuntu, regular users can't directly access USB devices by default. You will need to configure the system to allow this. The easiest approach is to create a file /etc/udev/rules.d/51-android.rules, as a root user, and copy the following lines into it. Be sure to replace <username> with the username of the user who has access to USB devices.

# adb protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"
# fastboot protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"
# adb protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"
# fastboot protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"
# adb protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"
# fastboot protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"
# adb protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"
# fastboot protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"
# adb protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"
# fastboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"
# usbboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"

These rules will take effect the next time you plug in a USB devices, so if your phone was already plugged in, unplug it then plug it back in.

OPTIONAL Setup ccache

You can optionally tell the build to use the ccache compilation tool. Ccache acts as a compiler cache that can be used to speed-up rebuilds. This works very well if you do "make clean" often, or if you frequently switch between different build products.

Put the following into your ~/.bashrc (or equivalent):
export USE_CCACHE=1
By default the cache will be stored in ~/.ccache. If your home directory is on NFS or some other non-local filesystem then you will need to specify the location for the cache. Add the following line below the line you just added to .bashrc.
export CCACHE_DIR=<path-to-your-cache-directory>
The recommended cache size is between 50 and 100 gigabytes. Once you have downloaded the source code run the following command to complete your setup of ccache.
prebuilt/linux-x86/ccache/ccache -M 50G

On Mac OSX

Coming Soon!