Compiling Android

From iDroid Project

Jump to: navigation, search

Contents

Open-Source Licenses

The iDroid Project is an Open-Source Project. Android is under Apache License, version 2.0. As such, changes to the source code must be made public.

If you plan to compile Android with your own changes to the source code, please make your changes public. What you have changed may be helpful for the iDroid Project and for helping in troubleshooting.

Android requires a 32/64-bit system to build Android Gingerbread (version 2.3, which the iDroid Project uses).

Linux Systems

Ubuntu 12.10 LTS x86_64/i386/i586/i686

  • same as for 12.04 LTS
  • java stuff changes (as We need 1.6 version instead of 1.7):
sudo apt-get install openjdk-6-jdk
  • afeter install, change alternatives:
sudo update-alternatives --config java

and choose:

/usr/lib/jvm/java-6-openjdk-*

and then

sudo update-alternatives --config javac

and choose:

/usr/lib/jvm/java-6-openjdk-*

NOTE that * means that whatever You have -i386, -i586 or -amd64 choose is same.

  • FOR EXAMPLE: quad core iNtel,dual core iNtel when ask choose:

/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java

Ubuntu 12.04 LTS i386 / Ubuntu 12.10 i386/i586/i686

The following instructions are for Ubuntu 12.04 and 12.10 32bit based systems on (mainly) Intel platforms but can be run on AMD platforms too. Building on Ubuntu 12.04/12.10 is currently only experimentally supported and is not guaranteed to work on branches other than master, so everything else is up to You! Open a Terminal and enter:

sudo apt-get install git-core gnupg flex bison gperf build-essential \
  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
  libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \
  python-markdown libxml2-utils xsltproc zlib1g-dev:i386

Then:

sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

**Java stuff is at the moment at version openSOMETHING, but We need for Gingerbread jdk 1.6 instead of 1.7/1.6(openJDK) Installation is same as bellow description of x64 build except that it is 32bit, so click on: jdk-6u34-linux-i586.bin and run:

chmod u+x jdk-6u34-linux-i586.bin
 ./jdk-6u34-linux-i586.bin
 sudo mv jdk1.6.0_34 /usr/lib/jvm/
**ENTER YOUR SU PASSWORD**
 sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_34/bin/java" 1
 sudo update-alternatives --config java
**Choose: '''/usr/lib/jvm/jdk1.6.0_34/bin/java'''
 sudo update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "/usr/lib/jvm/jdk1.6.0_34/jre/lib/i386/libnpjp2.so" 1
 sudo update-alternatives --config mozilla-javaplugin.so
**Choose: '''/usr/lib/jvm/jdk1.6.0_34/jre/lib/i386/libnpjp2.so'''

After selection, there will be: update-alternatives: using /usr/lib/jvm/jdk1.6.0_34/jre/lib/i386/libnpjp2.so to provide /usr/lib/mozilla/plugins/libjavaplugin.so (mozilla-javaplugin.so) in auto mode

NOTE than You can try with jdk-7u4-linux-i586 from Oracle's site but I don't recommend that''

Under GNU/linux systems (and specifically under Ubuntu systems), regular users can't directly access USB devices by default. The system needs to be configured to allow such access. The recommended approach is to create a file /etc/udev/rules.d/51-android.rules (as the root user) and make entry's there (take a look around and find out what/where). Those new rules take effect the next time a device is plugged in. It might therefore be necessary to unplug the device and plug it back into the computer.


Credits goes to fergy for the Ubuntu 12.04 & 12.10 i386 (32bit) guides.

Ubuntu 12.04 LTS x86_64 / Linux Mint 13 onwards

Special thanks to Bionicman08 for the Linux Mint, Ubuntu 12.04 & VirtualBox guides.

The following instructions are for Ubuntu12.04 based systems.

Gingerbread requires the Java 6 JDK. Unfortunately, this is no longer available so you need to download the jdk via oracles website: http://www.oracle.com/technetwork/java/javase/downloads/jdk6-downloads-1637591.html You then need to run

chmod u+x jdk-6u38-linux-x64.bin
 ./jdk-6u34-linux-x86.bin
 sudo mv jdk1.6.0_34 /usr/lib/jvm/
 sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_34/bin/java" 1
 sudo update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "/usr/lib/jvm/jdk1.6.0_34/jre/lib/x86/libnpjp2.so" 1

After completing this you need to run in a terminal

sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev

Ubuntu (older than 12.04)

The following instructions are for Ubuntu based systems.

Gingerbread requires the Java 6 JDK. Unfortunately, this is not in Ubuntu's default repos so you should add the repo through the following Terminal commands (open a Terminal):

sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo add-apt-repository "deb-src http://archive.canonical.com/ubuntu lucid partner"
sudo apt-get update

Enter your password when prompted. The instructions for what packages to install will be later along this guide.

Linux Mint 10 to Linux Mint 12

These instructions can now be used for the Debian based version of Mint as well as the normal versions.

The first thing to do is to update your apt-cache, in Terminal:

sudo apt-get update

Now you need to update your system using the Update Manager and not sudo apt-get upgrade (Note: apt-get upgrade WILL cause issues with your system)

x86_64

If you are using a 64-bit system (either Ubuntu or Mint), open a Terminal and enter:

sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl sun-java6-jdk zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev

You will need to accept the Java license.

i386/i686

Building Gingerbread is now supported from first guide above.

VirtualBox

If you are running Linux within a guest session in VirtualBox then for Ubuntu it is recommended that you follow this, if on Linux Mint it is essential that you do.

  1. Install the guest Additions
  2. Shutdown the guest OS
  3. Make note of the number of enabled CPU's for the guest and adjust to how you want. (using all available will speed up the compiling process)
  4. Boot the Linux guest

OS X

To build the Android files in a Mac OS environment, you need an Intel/x86 machine running MacOS 10.4 (Tiger) 10.5 (Leopard), or 10.6 (Snow Leopard). The Android build system and tools do not support the obsolete PowerPC architecture.

Creating a Case-Sensitive File System

Android must be built on a case-sensitive file system. The Android Open-Source Project recommends that you build Android on a partition that has been formatted with the Case-sensitive Journaled HFS+ file system:

  • A case-sensitive file system is required because the sources contain files that differ only in case.
  • Journaled systems are more robust. (This is optional, but recommended.)
  • HFS+ is required to successfully build Mac OS applications such as the Android Emulator for OS X.

If you want to avoid partitioning/formatting your hard drive, you can use a case-sensitive disk image instead (easier). To create the image:

  1. In OS X, launch /Applications/Utilities/Disk Utility
  2. Select "New Image"
  3. Size: 15 GB (this will work, but you can choose more if you want to, iDroid will require more than 10GB when built)
  4. Volume format: case sensitive, journaled

This will create a .dmg file which, once mounted, acts as a drive with the required formatting for Android development. For a disk image named android.dmg (or whatever you named it) stored in your home directory, you can add the following to your ~/.bash_profile to mount the image when you execute mountAndroid:

# command to mount the android file image 
function mountAndroid { hdiutil attach ~/android.dmg -mountpoint /Volumes/android; }

Once mounted, you'll do all your work in the android volume. You can eject it (unmount it) just like you would with an external drive.

Set-up the Development Environment

  1. Install XCode version 3.1.4 or newer, i.e. gcc 4.2 from http://developer.apple.com. You must sign-in or register a new account. 'There is a problem with version 4.0 (no 10.5 SDK), please bear with us and wait for a fix.
  2. Set an appropriate per-process file descriptor limit. To do this, add the following lines to your .bash_profile file:
    # set the number of open files to be 1024
    $ ulimit -S -n 1024
    Note that this may not be necessary; on some systems, the output of ulimit -S will show unlimited. In this case, there is no need to set the limit to 1024.
  3. You may then choose to complete the rest of the set-up using Homebrew or MacPorts.

Homebrew

  1. Install Homebrew if you haven't by entering the following command in a Terminal:
    ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
  2. The standard script installs Homebrew to /usr/local so that you don’t need sudo when you brew install. It is a careful script, it can be run even if you have stuff installed to /usr/local already. It tells you exactly what it will do before it does it too. And you have to confirm everything it will do before it starts.
  3. Why does Homebrew say sudo is bad? Homebrew is designed to work without using sudo. You can decide to use it but we strongly recommend not to do so. If you have used sudo and run into a bug then it is likely to be the cause. It’s too high a risk to sudo such stuff. It could break your base system, or alter it subtly.
  4. Alternate Installs
    mkdir homebrew && curl -L https://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C homebrew
  5. You can also install Homebrew into e.g. ~/Developer (or ~/.homebrew) and then symlink the brew command into /usr/local/bin (eg. ln -s path/to/homebrew/bin/brew /usr/local/bin/brew).
  6. Everything will install into ~/Developer, but your brew command is still in the path. NOTE that Homebrew will still need to create symlinks into /usr/local or nothing will work!
  7. To update homebrew:
brew update

You can now find out what is outdated with:

brew outdated

Upgrade everything with:

brew upgrade

Or upgrade a specific formula with:

brew upgrade foo

My Mac .apps don’t find /usr/local/bin utilities! GUI apps on OS X don’t have /usr/local/bin in their PATH by default. You fix this by following these instructions: [1]

MacPorts

  1. Install MacPorts if you haven't:
    1. Download and run the installer from http://www.macports.org/install.php
    2. Make sure that /opt/local/bin is in your path before /usr/bin by running:
      $ echo $PATH
    3. If you don't see /opt/local/bin, edit $HOME/.bash_profile and add the line export PATH=/opt/local/bin:$PATH after any other PATH-related lines. To verify that your path is now correct, open a new terminal and run echo $PATH again.
  2. Get the following packages from port:
    $ POSIXLY_CORRECT=1 sudo port install gmake libsdl git-core gnupg
  3. If using Mac OS 10.4, also install:
    $ POSIXLY_CORRECT=1 sudo port install bison 
  4. You must use gmake 3.81 but Macports will install 3.82 (which will not work). To install gmake 3.81:

Edit /opt/local/etc/macports/sources.conf and add a line that says

file:///Users/Shared/dports

above the rsync line. Then create this directory:

mkdir /Users/Shared/dports

In the new dports directory, run

svn co --revision 50980 http://svn.macports.org/repository/macports/trunk/dports/devel/gmake/ devel/gmake/

Create a port index for your new local repository:

portindex /Users/Shared/dports

Finally, install the old version of gmake with

sudo port install gmake @3.81

Installing the Android Repo Tool (all platforms)

Changelog:

  • 26/01/2022

Added new link to 'repo V1.19'

  1. 1 Be sure that 'repo' is not in use if You have it already installed.

-e.g. to not see:

bash: /home/U_S_E_R/bin/repo: Permission denied
  1. 2 Open a Terminal:

As from now, repo is in the version 1.19, We will use it:

cd ~
mkdir bin
curl http://git-repo.googlecode.com/files/repo-1.19 > ~/bin/repo
sudo chmod a+x ~/bin/repo

Add /bin to Your PATH:

PATH=~/bin:$PATH
Add one line
export PATH=~/bin:$PATH in file ~/.bashrc
and then
source ~/.bashrc

Make sure you have a ~/bin directory in your home directory, and check to be sure that this bin directory is in your path!

Downloading and Building iDroid

This procedure will download the source from all of the required repositories and then compile them. It would be a good idea to look through the information listed above to prepare your machine before continuing.

Open a Terminal. If you are in OSX, mount android.dmg (or whatever you called it) and in Terminal cd to /Volumes/Android (or whatever you named it).

**FOR GINGERBREAD**

mkdir pepparkaka 
cd pepparkaka
repo init -u git://github.com/iDroid-Project/platform_manifest.git -b gingerbread
repo sync

**FOR JB** NOT 100% WORKING ATM (needed patches, but work on it)

mkdir pepparkaka 
cd pepparkaka
repo init -u git://github.com/fergy/platform_manifest.git -b jb
repo sync

If You got error such as:

error: RPC failed; result=18, HTTP code = 200iB | 509 KiB/s       1558), 11.00 MiB | 1.03 MiB/s   
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
remote: Counting objects: 684, done
remote: Finding sources: 100% (82/82)
error: inflate: data stream error (incorrect data check)iB/s    
fatal: pack has bad object at offset 876877916: inflate returned -3
fatal: index-pack failed
error: Cannot fetch platform/prebuilt
error: Exited sync due to fetch errors

then simple try again command:

repo sync

until it resync it because google server can cause this kind of error due to re-syncing repo's.internet connection) then after repo sync is done:

. build/envsetup.sh && lunch

Turn on caching to speed up build

If you want to speed up subsequent builds after this one, type:

export USE_CCACHE=1

Choose which device you'd like to build for, enter the number for that device and press enter.

If you are using a 32-bit system, you must make some modifications to be able to build Gingerbread and are advised to skip the next part unless patches have been applied. 64-bit users proceed and enter this command:

make -j2
(-j = num of compile processes, 2 per core, j2 for single core, j4 for dual-core, j8 for quad-core)

VirtualBox users enter the number corresponding with the number of CPU's enabled

Wait for everything to compile and there you go. The compiled system.img will be in pepparkaka/out/target/product/***device***/system.img (Substitute ***device*** with iPhone2G, iPhone3G, or iPodTouch1G depending on what device you were planning to build it for).

TIP:

Instead of typing
cd ~/android/system
every time you want to return back to the root of the source code, here’s a short command that will do it for you:
croot
To use this command, as with brunch, you must first do
. build/envsetup.sh
from ~/android/system. Notice there is a period and space (“. ”) in that command.

TIP: If You take an adventage and change/delete files from Your repo and get error like:

error: .repo/manifests/: contains uncommitted changes

cd into .repo/manifests and make an git hard reset like this:

cd .repo/manifests
git reset –hard

Please note that there are two dashes "- -" before 'hard'

cd back to root of project and

repo sync

References