Archive for November 2013

This is an update from our last post of Building Android from Source for Nexus 7 on Ubuntu 13.04 : Step-by-Step. This time we upgrade our Ubuntu Installation to 13.10 Saucy Salamander along with the update Android Version 4.4 KitKat for the Latest Nexus 5 device code named 'hammerhead'.
UPDATE: New build instructions for Ubuntu 14.04 LTS version
As discussed in the previous post the procedure remains nearly the same. There are minor changes that would help to make this updated build work. But First:
DISCLAIMER: If you proceed on the steps provided it will surely cause damage to your Nexus 5 device and the Author of this article will not be held responsible for any losses or damages of any type caused by following the steps below.

Now for the steps.

[0] PC and Other Requirements:

The basic system requirement are same as stated in the earlier post.

# PC configuration to have a decent build performance:
  • Processor: Quad Core 2.6GHz Intel Core i5 and above
  • RAM: 4GB DDR3 1066MHz and above
  • HDD Space: 120GB Free (build tools + Android source + build cache)
  • Internet Connection: 2mbps and above
# Nexus 5 with PC Cable

[1] Prepare Ubuntu 13.10 for building Android

The update package requirements from Ubuntu have changed so the particular step would need some correction to help install the required packages needed to build the Android Kitkat.

[1._ ] Most of the commands need to run in a terminal window so we need to open it before starting any of the below steps. The easy way on Ubuntu is to press the keyboard combination Ctrl + Alt + 't' else one can also go to the app launcher icon and type "terminal"

[1.a] Correcting and Installing Java

First thing that we need to perform is removing the Icedtea Java or OpenJDK
sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*

This time the problem is that we can not use the offical Java update from Oracle.
Instead we need to use the Last java version available in the JDK1.6 SE pacakge.
To do so one needs to signup at Oracle Java website: https://login.oracle.com/mysso/signon.jsp
After sign-up and login into the Oracle website use the JDK1.6SE u46 version link to get to the download area.
Now one needs to select the correct package:
Finally after downloading these files one needs to extract them and add to the path here are the commands:
chmod +x jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
echo "export PATH=$PATH :"`pwd`" >> $HOME/.bashrc
This would help to place the directory to path. Next there would be restart needed for the Terminal to enable the new path to take effect.
Note: If you have multiple Java installation then better ignore the last line and add it as per your requirement. We use both Java7 SE for application development and Java6 for Android. Hence we modify the path when needed.

[1.b] Installing the package dependencies into Ubuntu

This is a long an time taking process, where nearly 1050MByte+ data is downloaded. So be careful if you have limited bandwidth connection like ours. This might take up a lot of your Internet connection bandwidth.
sudo apt-get install git-core gnupg flex bison \
gperf build-essential zip curl \
zlib1g-dev zlib1g-dev:i386 libc6-dev \
lib32ncurses5-dev lib32ncurses5 \
lib32bz2-1.0 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 \
lib32z1-dev libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 \
tofrodos python-markdown libxml2-utils \
xsltproc readline-common \
libreadline6-dev libreadline6 \
lib32readline-gplv2-dev libncurses5-dev \
lib32readline5 lib32readline6 \
libreadline-dev libreadline6-dev:i386 \
libreadline6:i386 bzip2 libbz2-dev \
libbz2-1.0 vim libghc-bzlib-dev \
lib32bz2-dev libsdl1.2-dev libesd0-dev \
squashfs-tools pngcrush schedtool \
libwxgtk2.8-dev python

This would update the base packages needed to compile the Android source.

This would take some time to get the complete download done and then the dependency fixes need to be applied:
sudo apt-get install -f
After this we need to do the following linking:
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 \
/usr/lib/i386-linux-gnu/libGL.so

This completes the installation of dependencies and necessary packages to begin our build

[2] Downloading the Google Repository tool - repo

In order to obtain the Android source code from Google there is a special tool called "repo". This tool enables us to download all the component repositories sources that come together to make Android OS source for a specific version.

First lets create a local directory which would hold our executable code:
mkdir ~/bin
Now let us download the repo tool into this directory and apply the executable permission:
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo >\
~/bin/repo && chmod a+x ~/bin/repo


Finally adding this to the path to help us get the tool working
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc && \
source ~/.bashrc

We are now ready to obtain the source code from Google for Android OS

[3] Downloading the Android Sources & Vendor Binaries

For the Nexus 5 Device we have the 'hammerhead' Google code release:
Build: KRT16M
Repository Tag: android-4.4_r1

To start the download we need to first create a folder eg. android-4.4_r1
mkdir android-4.4_r1
cd android-4.4_r1


Now lets Initialize the Repository for GIT configuration
git config --global user.name {Your Name}
git config --global user.email {Your@Email}


This would set up your identity that would be part of this source code checkout
Finally we can Initialize the Repository using the following command:
repo init -u https://android.googlesource.com/platform/manifest -b android-4.4_r1
This command will take some time to finish as it creates the basis for the list of location from which the different components are downloaded.

Now we are ready to receive the real code:
repo sync -j4

The Vendor Specific Binaries located at :
https://developers.google.com/android/nexus/drivers

For 'hammerhead' and Android Kitkat Release download the binaries at this link:
https://developers.google.com/android/nexus/drivers#hammerheadkrt16m

Go to the android-4.4_r1 directory and Download the drivers:
cd android-4.4_r1
wget -c https://dl.google.com/dl/android/aosp/broadcom-hammerhead-krt16m-bf9b8548.tgz
wget -c https://dl.google.com/dl/android/aosp/lge-hammerhead-krt16m-0efa9c33.tgz
wget -c https://dl.google.com/dl/android/aosp/qcom-hammerhead-krt16m-53cf1896.tgz
tar -xvf broadcom-hammerhead-krt16m-bf9b8548.tgz
tar -xvf lge-hammerhead-krt16m-0efa9c33.tgz
tar -xvf qcom-hammerhead-krt16m-53cf1896.tgz
rm *.tgz


Finally extract the Vendor Specific binaries by the following commands:
./extract-<filename>.sh
You need to enter the "I ACCEPT" at the end of license notices to execute the program.

Perform this for all the three files extracted above.
Now we are ready for the next big step - Compiling!

[4] Building the Sources

First open another Termial window and go the Android directory:
cd android-4.4_r1
. ./build/envsetup.sh


Now to select the type of device we give the following command:
lunch

This would display a menue:
You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_x86-eng
     3. aosp_mips-eng
     4. vbox_x86-eng
     5. mini_x86-userdebug
     6. mini_armv7a_neon-userdebug
     7. mini_mips-userdebug
     8. aosp_tilapia-userdebug
     9. aosp_flo-userdebug
     10. aosp_deb-userdebug
     11. aosp_grouper-userdebug
     12. aosp_manta-userdebug
     13. aosp_hammerhead-userdebug
     14. aosp_mako-userdebug

Which would you like? [aosp_arm-eng] 13


Select the option '13. aosp_hammerhead-userdebug' choice by entering '13'.
Now we are ready to start the build.
make -j4

Here the "-j4" switch would help to run the build on Quad core.

This process would take some time ranging from 30minutes to 3hours depending of your PC performance and configuration.
After this is done you are ready with your source to flash the image into your device.
DISCLAIMER: If you proceed on the steps provided it will surely cause damage to your Nexus 5 device and the Author of this article will not be held responsible for any losses or damages of any type caused by following the steps below.

[5] Flashing the Device

This would definitely damage your device and load the image of Android OS built in the previous steps. In order to perform this step one needs to unlock the bootloader as explained in the XDA forum post.
Connect your device into the Linux PC. And give the command in the existing terminal prompt from the earlier step.
adb root
adb reboot bootloader
cd out/target/product/grouper


This would help you enter the bootloader mode. And change the directory to the place where the actual build image files are located
Final command that would kill the device and load your compiled image:
fastboot oem unlock && fastboot -w flashall

This would load the complete image into your device and then reboots it.

Now in order to restore the device back to its original os follow the steps outline in another post. Although this is for the Nexus 7 device the similar steps work for Nexus 5 device also.
We have been working on some Java based projects recently. The compile mechanism of Java is a bit different from the way each of the IDEs implement them. We have used Netbeans-IDE and Eclipse. We figured that both have radically different way of implementing the compile time and jar time constrains. However we wanted some thing as simple as "make clean" and "make compile". That's when we came across Ant.

Apache Ant is internal build system used by many of the IDEs, this is the build framework in the world of Java. Kind of like 'make' for Java but apparently bit easier than makefiles. We need a consistent build framework across our Linux, Mac OS and Windows. We made a generic build system and configured in the way to make building Java projects a breeze.

In this article we would be discussing how we went about setting up the all the three system to have a common build framework for our up coming project jNeelSer which would be detailed later.

[1] Obtain Java

The  Ant framework is written in Java and hence to execute the same we would need to have Java compiler and run time available. To do this we simply get the JDK and place it into our path.
One can obtain the Java SE JDK from the Oracle Website. For now one can use the Latest JDK Java SE 7 releases.
A word of caution for the Linux users - if one intend to use the JDK to compile Android and use it for general purpose Java programming then they need to have JDK 6 version separately for Android from the Oracle Java Archive and if JDK 7 is used for development then the Path needs to appended accordingly. We actually do this so we will show how to do this in the next steps.

[2] Obtain Ant

The Ant package is available in binary form at Apache Ant website. Its designed in such a way that one can easily run it in any platform. So to setup extract the Ant package into the desired directory.
We are using Ant 1.9.2. So we have the directory apache-ant-1.9.2/bin and we add this to our Path in all the three platforms. Its easy to understand the Zipped version is for windows and the .tar.gz & .tar.bz2 are for Linux or MacOS.

[3] Ant Environment Script

In order the Ant build system to work one needs to setup the system Environment in the correct way.
Lets try to spend a moment to understand the system variable and what they mean:
  • JAVA_HOME = Location of the Java Installed Directory. Not the 'bin' directory but the root directory of Java installation.
    Eg. JAVA_HOME=C:\jdk1.6.0_45 and not C:\jdk1.6.0_45\bin
  • ANT_HOME = Location of the Ant Installed Directory. Again not the 'bin' but the extracted directory.
    Eg. ANT_HOME=/home/efb/local/apache-ant-1.9.2 and not /home/efb/local/apache-ant-1.9.2/bin
  • PATH = Need to be modified to add the Ant as well as Java ahead of all parsing. We will show this how
 Now lets look at how we can configure these environment variables:
Windows Batch file script (Save this text into a .bat file replacing the 'path' strings):
For Linux / MacOS we can create a small shell script to do this:
However this also means that the file needs to executable, so below is the command:
chmod +x antconf.sh

Next lets progress with writing a simple build script.

[4] Writing the Build Script for Ant

The Ant build framework is written in Java and uses XML based format to write the build scripts. This is a complete paradigm shift from the conventional Makefile business that we have seen countless number of times. Have a look at the basic framework of the build script:

Here the first XML tag defines the usual DTD as per the W3C. This is similar to the one used in any conventional XML data file.
Next the header <Project> gives details about the project that we plan to compile/build. Its important to remember the name specified by the parameter 'name="jNeelSer"' gives the project its true name. The compiled output would use this parameter to name the file build output.
The parameter 'basedir="."' helps to determine the path to the source code base where the build.xml is present.

Forgot to mention that  build.xml is the default name of the build script for Ant.

The 'default="compile"' option helps to determine the default step to be performed when the build is invoked.
Here is the complete source for the jNeelSerial project, we would use this as an example to detail the way of writing the Ant build script.
In the above build script there are many additional tags that help to define more information about the project and help in correct build generation.
  • Fail tag shown in line 26 is used to declare that one can use this build script with 1.8.0 or higher version of Ant build.
  • Property Tag shown in line 34 is used to fine the source and build location directories using the location value. The Property tag can also have other values if needed.
  • Target Tag shown in line 38 is like a configuration which contains a set of actions to be perfomed when the build is invoked. One can also add some description to each of the targets if needed as shown in the Compile configuration. Lets have a detailed look at this:
    • Init configuration: This is the Initial target that helps to create the necessary directories or build related info before hand.
    • Compile configuration: This is used to actually build the classes for the source code with the correct Class path. This build target need to run the Init in case it was not explicitly called.
    • jar configuration: This is used to generate the executable manifest information and create the required JAR file that contains the supporting libraries in one place. jNeelSerial uses the jSSC library stored in the lib directory. Again Jar depends on the Compile configuration as the class files to be packaged need to be available.
    • clean configuration: This is used to clear the build and intermediate directories.
  • mkdir Tag shown in line 42 helps to create directories with reference to build.xml file directory path as the reference.
  • delete Tag shown in line 67 can be used to delete files(use file attribute) or directories (use dir attribute)
  • javac Tag shown in line 48 is the most important tag that actually performs the compilation. The srcdir attribute helps to locate the java source code. The destdir attribute specified the location where the compiled classes should be placed. The includeantruntime attribute helps to run the java compilation under ant system control to help produce useful output of the commands being executed.
    • Classpath Tag in line 49 helps to define and include the necessary classes/packages and their locations. It require the Pathelement Tag to declare the paths. There can be two types - Package/Class locations(Eg. Line 50) or Absolute includes (Eg. Line 51)
  • jar Tag shown in line 58 is used to generate the executable java archive. In this the destfile attribute defines the destination jar file and the basedir attribute specifies the location for the class files complied earlier.
    • Manifest Tag in line 59 is used to define the default executable class which contains the 'main'. This is achived by using the Attribute Tag for 'Main-Class' with the value of the exact class with namespace.
    • zipgroupfileset Tag in line 62 helps to include some additional files if needed into the final jar. In the above example shows how to specify the directory and include files using a wildcard sequence.
This concludes the description of he build script.
Now how to run this thing.

[5] Running the Build

In order to run the build, first we need to use the scripts that we wrote earlier to setup the Ant build environment inside a Terminal window. Then change directory to the desired project directory and run the ant command.
Here is the syntax:
ant [target]
Here the important point is that [target] should be a valid one specified in the build.xml file. And this is run in the directory of the project containing the build.xml file.
In our above example for jNeelSerial there are 3 main targets - compile, jar and clean
In case the file name of the build script is different then use the following syntax:
ant -f [build script.xml] [target]

For example in jNeelSerial the name of the build script is make.xml and hence the command would be:
ant -f make.xml compile

Hope that you like this tutorial, let us know your feedback on this article.
Welcome to Boseji's Blog

Popular Post

Blogger templates

Welcome

Creation by Electronics Hobbyists from Bharat(India) to encourage & help people. This blog hosts the numerous innovations, discoveries and projects we provide.
Our Research Wing Adhar Labs
Contact Form | Email Address
We Support Open Source Hardware Definition v1.0
Creative Commons License
All works on this blog are licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at forbharat.wordpress.com and m8051.blogspot.com.

Permissions beyond the scope of this license may be available at http://forbharat.wordpress.com/permissions/.
Thank you for all your support.

© A.D.H.A.R Labs Research 2008-2013 . Powered by Blogger.

Follow by Email

Followers

PCB Unit Converter

mils
mm

- Copyright © Electronics for Bharat -Robotic Notes- Powered by Blogger - Designed by Johanes Djogan -