Skip to main content

How to Build Android Lollipop in Ubuntu 14.04?

How to build Android Lollipop in Ubuntu 14.04?

How to build Android Lollipop in Ubuntu 14.04?

image.png

Introduction

There is a way that help you to build Android Lollipop (Android 5.0, API 21). We will arrange some script shell to help you after development. I hope everyone that enjoys to quickly comfortable development environment.

Equipment

Operation System: Ubuntu 14.04 LTS

Usage

  1. To Install the necessary libraries and tools for Ubuntu 14.04 LTS.


# su   
Password:   
$ sudo apt-get install git 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 tofrodos  python-markdown libxml2-utils xsltproc zlib1g-dev:i386   
$ sudo apt-get install bison g++-multilib git gperf libxml2-utils   
(… More)   


  1. The Android in the Android Open Source Project (AOSP) requires Java 7. On Ubuntu, use OpenJDK.

2.1. Generally, The tool (update-alternatives) has been installed your Linux system. It is a very usefully tool and it is able to help you easily switch to different compilers. Of course, you need to make sure you have the tool.



$ sudo update-alternatives --version
Debian update-alternatives version 1.16.15.

This is free software; see the GNU General Public License version 2 or later for copying conditions. There is NO warranty.

2.2. Moreover, you have tried to install more than one compilers. For example, you will install various kinds of the compilers, such as gcc, g++, Java, Open JDK, etc.



$ sudo apt-get install gcc-4.4 gcc-4.6 gcc-4.7 gcc-4.8 g++-4.4 g++-4.6 g++-4.7 g++-4.8


2.3. Nonetheless, just only one can be a symbolic link. Let me explain more detail about how to set up the tool. Now, you will install symbol links for those compilers respectively.

2.4. Installation a symbolic link.
In this case, you can follow the format of parameters as below. Format: sudo (change to be a root) update-alternatives (the tool name) –install (To make up a symbolic link) /usr/bin/gcc (your gcc symbol link) gcc (a configuration name) /usr/bin/gcc-4.4 (your gcc installation path) 1 (priority)



$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 1
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 4
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 5
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 2


2.5. The choice you want to a compiler to be default.



$ sudo update-alternatives --config gcc


There are 4 choices for the alternative gcc (providing /usr/bin/gcc).

Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/gcc-4.7 5 auto mode
1 /usr/bin/gcc-4.4 1 manual mode
2 /usr/bin/gcc-4.6 4 manual mode
3 /usr/bin/gcc-4.7 5 manual mode
* 4 /usr/bin/gcc-4.8 2 manual mode

Press enter to keep the current choice[*], or type selection number:

2.6. Notwithstanding the initial confusion, the tool (update-alternatives) was a success. I think you should spend a few times doing this, because you will be to earn more time to develop.



$ sudo update-alternatives --config java


There are 8 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
* 2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
3 /usr/lib/jvm/jdk1.6.0_37-i586/bin/java 1 manual mode
4 /usr/lib/jvm/jdk1.6.0_37-x64/bin/java 2 manual mode
5 /usr/lib/jvm/jdk1.6.0_45-i586/bin/java 3 manual mode
6 /usr/lib/jvm/jdk1.6.0_45-x64/bin/java 4 manual mode
7 /usr/lib/jvm/jdk1.7.0_67-i586/bin/java 5 manual mode
8 /usr/lib/jvm/jdk1.7.0_67-x64/bin/java 6 manual mode

Press enter to keep the current choice[*], or type selection number:



$ sudo update-alternatives --config javac


There are 8 choices for the alternative javac (providing /usr/bin/javac).

Selection Path Priority Status
------------------------------------------------------------

0 /usr/lib/jvm/java-7-openjdk-amd64/bin/javac 1071 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/bin/javac 1061 manual mode
* 2 /usr/lib/jvm/java-7-openjdk-amd64/bin/javac 1071 manual mode
3 /usr/lib/jvm/jdk1.6.0_37-i586/bin/javac 1 manual mode
4 /usr/lib/jvm/jdk1.6.0_37-x64/bin/javac 2 manual mode
5 /usr/lib/jvm/jdk1.6.0_45-i586/bin/javac 3 manual mode
6 /usr/lib/jvm/jdk1.6.0_45-x64/bin/javac 4 manual mode
7 /usr/lib/jvm/jdk1.7.0_67-i586/bin/javac 5 manual mode
8 /usr/lib/jvm/jdk1.7.0_67-x64/bin/javac 6 manual mode

Press enter to keep the current choice[*], or type selection number:



$ sudo update-alternatives --config javaws


There are 8 choices for the alternative javaws (providing /usr/bin/javaws).

Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/javaws 1071 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws 1061 manual mode
* 2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/javaws 1071 manual mode
3 /usr/lib/jvm/jdk1.6.0_37-i586/bin/javaws 1 manual mode
4 /usr/lib/jvm/jdk1.6.0_37-x64/bin/javaws 2 manual mode
5 /usr/lib/jvm/jdk1.6.0_45-i586/bin/javaws 3 manual mode
6 /usr/lib/jvm/jdk1.6.0_45-x64/bin/javaws 4 manual mode
7 /usr/lib/jvm/jdk1.7.0_67-i586/bin/javaws 5 manual mode
8 /usr/lib/jvm/jdk1.7.0_67-x64/bin/javaws 6 manual mode

Press enter to keep the current choice[*], or type selection number:



$ sudo update-alternatives --config gcc


There are 4 choices for the alternative gcc (providing /usr/bin/gcc).

Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/gcc-4.7 5 auto mode
1 /usr/bin/gcc-4.4 1 manual mode
2 /usr/bin/gcc-4.6 4 manual mode
3 /usr/bin/gcc-4.7 5 manual mode
* 4 /usr/bin/gcc-4.8 2 manual mode

Press enter to keep the current choice[*], or type selection number:



$ sudo update-alternatives --config g++


There are 4 choices for the alternative g++ (providing /usr/bin/g++).

Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/g++-4.7 5 auto mode
1 /usr/bin/g++-4.4 1 manual mode
2 /usr/bin/g++-4.6 4 manual mode
3 /usr/bin/g++-4.7 5 manual mode
* 4 /usr/bin/g++-4.8 2 manual mode

Press enter to keep the current choice[*], or type selection number:

3.. Installing Repo
Repo is a tool that makes it easier to work with Git in the context of Android.
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 tool and ensure that it is executable:
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

3.1. Initializing a Repo client and download it.
After installing Repo, set up your client to access the Android source repository:
Create an empty directory to hold your working files.

$ mkdir (your working directory)
$ cd (your 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
$ repo sync

This may take a long time, take a break. To wait it to download finished.

4.. To install the python switch tool.

4.1. If you haven't used GIT, you should install it before you get started.
$ sudo apt-get install curl git-core

4.2. For automatically install pyenv.
$ curl https://raw.github.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash

4.3. Open up .bashrc located in your home directory with a text editor and add the following.
File Name: .bashrc
# Python environment switch
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
(Save it)

$ source ~/.bashrc

4.4. To Verify pyenv is installed properly
$ pyenv --version
pyenv 20140924-1-g737e0f1

4.5. List of Python versions.
$ pyenv install –list
Available versions: 2.1.3 2.2.3 2.3.7 2.4 2.4.1 (… More)

4.6. To install a python version.
$ pyenv install 3.3.4 -v
/tmp/python-build.20150111112656.5021 ~
Downloading Python-3.3.4.tgz...
HTTP/1.1 200 OK
Server: GitHub.com
Content-Type: application/octet-stream
Last-Modified: Tue, 04 Nov 2014 09:32:24 GMT
Expires: Sun, 11 Jan 2015 03:36:56 GMT
Cache-Control: max-age=600
Content-Length: 16843278
Accept-Ranges: bytes
Date: Sun, 11 Jan 2015 03:27:01 GMT
Via: 1.1 varnish
Age: 5
Connection: keep-alive
X-Served-By: cache-ty67-TYO
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1420946816.328055,VS0,VE4793
Vary: Accept-Encoding
-> http://yyuu.github.io/pythons/ea055db9dd004a6ecd7690abc9734573763686dd768122316bae2dfd026412af
(… More)

4.7. To list python versions.
$ pyenv versions
* system (set by /home/brianlai/.python-version)
2.6.6
3.3.4
4.8. To switch another python version.
$ export PYENV_VERSION=3.3.4
$ pyenv versions
system
2.6.6
* 3.3.4 (set by PYENV_VERSION environment variable)
$ export PYENV_VERSION=system
$ pyenv versions
* system (set by PYENV_VERSION environment variable)
2.6.6
3.3.4

5.. To write a bash shell scription.
File Name: build-android-L.sh
#!/bin/bash
root_path=`pwd`
cd $root_path/(your working directory)/
# gcc 4.8
sudo update-alternatives --set gcc /usr/bin/gcc-4.8
sudo update-alternatives --set g++ /usr/bin/g++-4.8
# OpenJava 1.7.0_amd64
sudo update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
sudo update-alternatives --set javaws /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/javaws
# python 2.7.6
pyenv local system
# Android
source build/envsetup.sh
lunch
# make 3.81
make -j8
(Save it)

6.. To additional export parameter into the bash shell environment.

File Name: .bashrc
export ARCH=arm
export SUBARCH=arm
export USE_CCACHE=1
export CCACHE_DIR=~/.ccache
export PATH=~/bin:$PATH
export PATH=/(your ARM tool chain path)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH
export CROSS_COMPILE=arm-eabi-
(Save it)

7.. To build your Android Lollipop by bash shell scription.
$ bash build-android-L.sh

Exception

1.. If your operation system is not Ubuntu 14.04 LTS, Please, refer to as below.

On Ubuntu 10.10:
$ 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
$ sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so
On Ubuntu 11.10:
$ 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
$ sudo apt-get install libx11-dev:i386
On Ubuntu 12.04 (64 bit)
$ sudo apt-get install git 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 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

2.. To check out a branch other than "master", specify it with -b:
$ repo init -u https://android.googlesource.com/platform/manifest -b android-5.0.2_r1

Reference

[1] http://source.android.com/source/build-numbers.html
[2] http://source.android.com/source/initializing.html
[3] http://source.android.com/source/downloading.html
[4] http://source.android.com/source/building-running.html

Acknowledge

Thank you (Google, Android, OpenJDK, Python, GNU) very much for this great development utility.

Popular posts from this blog

Python 日期與時間的處理

Visual Basic 6.0 (VB6) 程式語言案例學習 (10. 條碼列印程式)

寫作:波蘭文學習之旅:1-1. 波蘭文字母與發音(注音版)

Python 日期與時間的處理

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (10. 條碼列印程式)

Image

寫作:波蘭文學習之旅:1-1. 波蘭文字母與發音(注音版)

Image

數位影像處理:最佳化處理策略之快速消除扭曲演算法

Image

用10種程式語言做影像二值化(Image binarization)

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (04. 人事考勤管理系統)

Image

Visual Basic .Net (VB.Net) 程式語言案例學習 (06. 題庫測驗系統)

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (11. 生產線拍照程式)

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (07. 收據列印程式)

Image

Visual Basic .Net (VB.Net) 程式語言案例學習 (03. 場地預約系統)

Image