This blog has permanently moved to

Contact Form | Email Address

© 2018 All rights reserved by Boseji

Thank you for all your support.

Thursday, August 15, 2013

Restoring Nexus 7 to Official Build on Ubuntu 13.04: Back to Google

This is in continuation to our earlier article "Building Android from Source for Nexus 7 on Ubuntu 13.04 : Step-by-Step" where we discussed on how to build a complete android distro. This article focuses on restoring the Nexus 7 [2012] Wifi (grouper) device to the official version of android.

This process would completely format the Grouper device and the user would lose all the data.
DISCLAIMER: If you proceed on the steps provided it will surely cause damage to your Nexus 7 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.

[1] Download the official Android Build

First step is to obtain the latest version of the Android OS. In order to do so we would need to visit the Google Factory Images Page At: https://developers.google.com/android/nexus/images
The correct Latest Android OS Image for Grouper is:
Official Name: nakasig
Android Version: 4.3
Build: JWR66V (more details from on Build Code Name page )
Link: http://developers.google.com/android/nexus/images#nakasijwr66v
Download Link: https://dl.google.com/dl/android/aosp/nakasig-jwr66v-factory-aebc7b11.tgz

After this extract this file into a directory just above the 'android-4.3_r1' created earlier.
In order to extract issue the following command in Ubuntu Linux Terminal prompt at the directory where the above downloaded file ".tgz" is located.

tar -xvf nakasig-jwr66v-factory-aebc7b11.tgz

This would create a directory called "nakasi-jwr66v" which would contain the required files to flash the factory Android image.

[2] Setting up and Download

 Now its time that we setup the environment to load the Image. Before we begin the Nexus 7 grouper device needs to be plugged to the Ubuntu machine. And the Android build that we did earlier needs to be present or the Android SDK must be in the path.

We will assume that you have the earlier Android build, else one can skip the steps given below if you have the Android SDK:
cd android-4.3_r1
. ./build/envsetup.sh
lunch 6

cd ..

Now we are ready to move with the installation step:

adb reboot bootloader

This would help to go into the Boot loader mode.
Now we need to go to the directory where the offical android build was extracted. And then run the command to flash the image:

cd nakasi-jwr66v

This would format the complete flash and then load a fresh copy of the Official Android build.
Finally the device would reboot on its own and would ask for the default setup needed to get the device running.

Hope that you liked our articles, let us know your comments and suggestions to improve them.
Next we would be posting on how to develop some basic low level apps in Android.

Thursday, August 8, 2013

Building Android from Source for Nexus 7 on Ubuntu 13.04 : Step-by-Step

We have been kept busy with our research work on Android operating system for mobile phones. We thought it would be nice to share a short tutorial to get started on building the Android source from scratch. There were several hurdles to pass before we could really get some thing working. Our target platform was Nexus 7 or what is called as "grouper" in Android terms.

Updated for Nexus 5 Source build on Ubuntu 13.10 >>

Nexus 7 is fairly a cheap device for now, as compared to the other high end phones. For disambiguation we are using a Nexus 7 with 16GB Storage and Only Wi-Fi. Since there are two variants available in the market, this one is called as "grouper".
However off the shelf devices are not the development units so you need to mod it to work as a development device. Here we would like to issue a warning.

DISCLAIMER: If you proceed on the steps provided it will surely cause damage to your Nexus 7 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.

[0] PC and Other Requirements:

# 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 7 with PC Cable
# Lots of patience and 1 day time ;-)

[1] Prepare Ubuntu 13.04 for building Android

In order to prepare the standard Ubuntu operation you can first update the installation to the most recent packages. Next follow the steps to install and configure the build system. Thanks to the Blog: soupdawg.wordpress.com
[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-\*
Next we need to add the official last JDK from Oracle:
sudo add-apt-repository ppa:webupd8team/java
Next perform an update on Apt Sources:
sudo apt-get update
Finally Install the Java6 version of JDK:
sudo apt-get install oracle-java6-installer
Just to make sure that you have the right stuff you run the following command:
java -version
The output would be something like:
java version “1.6.0_39″
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)
So now we are done with Java which is one of the essential components needed by the Android Dalvik compiler

[1.b] Installing the package dependencies into Ubuntu

This is a long an time taking process, where nearly 900MByte+ 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 ia32-libs 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 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 \
This completes the installation of dependencies and necessary packaes 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 https://dl-ssl.google.com/dl/googlesource/git-repo/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] Understanding and Downloading the Android Sources

There are multiple sources to obtain the Android OS source code. Here are a few of them:
1. Android Open Source Project - AOSP : This is the Google's official development project for android which would be detailed in this tutorial
2. AOKP from Team KANG : Offshoot with all bells-n-whistles loaded plus additional functionality
3. CyanogenMod : This project provides the complete Bootloader customization with specific Recovery and Andorid OS source integration. Slightly old but widely used to replace the official bootloader and recovery tool.

Digging deeper into the AOSP project we now need to know what are the Android OS distributions and what would be most suited towards our "grouper" device.
For now we would choose:
Build: JWR66V  
Repository Tag: android-4.3_r1
This is compatible to the "grouper" device so its a safe bet, there are others but possibly dont have official support for our target device.

UPDATE[4-Oct-2013] Latest version compatible for "grouper" is:
Build: JWR66Y
Repositrory Tag: android-4.3_r1.1
Please update the below commands and branch names accordingly

UPDATE[10-Nov-2013] Latest version compatible for "grouper" is:
Build: KRT16S
Repository Tag: android-4.4_r1.2
Finally we have Kitkat also for "grouper", thank to the signing campaign.
Update procedure for Kitkat have been published in another post

[3.a] Downloading the Source

To start the download we need to first create a folder eg. android-4.3_r1
mkdir android-4.3_r1
cd android-4.3_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.3_r1

The anatomy of this command is:
repo = Command
init = For Initialization
-u https://android.googlesource.com/platform/manifest = Location for all the source
-b android-4.3_r1 = Specific branch of source code that needs to be picked

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 anatomy of the command is:
repo = Command
sync = Download the code
-j4 = Use Quad core processing for downloading the source code

Once this command is completed you have the basic android source code available. Just to be sure that you have not missed any files try to run this command again. In case the download fails due to some reason you can ask for another download to fix any issues.
Once suggestion would be back up this basic source to have a copy that you can use to get back the older stage. Use this command to create the backup: (OPTIONAL)
cd .. && tar -jcvf android-4.3_r1_INIT.tar.bz2 --exclude ".git" \
--exclude ".repo" --exclude ".svn" android-4.3_r1/

[3.b] Getting Vendor Specific Binaries

In order to support the various sub-components in the "grouper" we would need to have the vendor binaries. These help to enable functionality + FW needed for the additional processors in the system.
One can find more info on this from the following link:

For "grouper" and Android JBMR2 release download the binaries from the below location:

Download all the driver binaries into the android-4.3_r1 directory:
cd android-4.3_r1
wget -c https://dl.google.com/dl/android/aosp/asus-grouper-jwr66v-15547c77.tgz
wget -c https://dl.google.com/dl/android/aosp/broadcom-grouper-jwr66v-fa38dae8.tgz
wget -c https://dl.google.com/dl/android/aosp/elan-grouper-jwr66v-4235892f.tgz
wget -c https://dl.google.com/dl/android/aosp/invensense-grouper-jwr66v-0da5128c.tgz
wget -c https://dl.google.com/dl/android/aosp/nvidia-grouper-jwr66v-2cbbe013.tgz
wget -c https://dl.google.com/dl/android/aosp/nxp-grouper-jwr66v-202ba26a.tgz
wget -c https://dl.google.com/dl/android/aosp/widevine-grouper-jwr66v-c6bdbc54.tgz
tar -xvf asus-grouper-jwr66v-15547c77.tgz
tar -xvf broadcom-grouper-jwr66v-fa38dae8.tgz
tar -xvf elan-grouper-jwr66v-4235892f.tgz
tar -xvf invensense-grouper-jwr66v-0da5128c.tgz
tar -xvf nvidia-grouper-jwr66v-2cbbe013.tgz
tar -xvf nxp-grouper-jwr66v-202ba26a.tgz
tar -xvf nxp-grouper-jwr66v-202ba26a.tgz
rm *.tgz

Optionally create a backup for these shell scripts extracted:
cd ..
tar -jcvf Nexus7Binaries.tar.bz2 ./android-4.3_r1/*.sh
cd android-4.3_r1

[3.c] Extracting the Vendor Specific Binaries

In order to install the vendor specific binaries one needs to run the .sh files generated by extracting the .tgz files in the earlier step.
The method to run the shell files:
Once you run them you would get a prompt to read the License agreement, press Enter to start reading and then Space bar to reach the end. Finally you need to type "I ACCEPT" to make the script extract the files. Finally the 'Vendor' directory would be ready after this step
Now we are ready for the next big step - Compiling!

[4] Building the Sources

First thing to do is to setup the Environment:
cd android-4.3_r1
. ./build/envsetup.sh

Anatomy of the command
'. ' = Signifies that we would be implying to execute the command in the current shell context
./build/envsetup.sh = Command to setup the environment variables and commands

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

This would display some selection menu like:

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. aosp_flo-userdebug
     6. full_grouper-userdebug
     7. full_tilapia-userdebug
     8. mini_armv7a_neon-userdebug
     9. mini_mips-userdebug
     10. mini_x86-userdebug
     11. full_mako-userdebug
     12. full_maguro-userdebug
     13. full_manta-userdebug
     14. full_arndale-userdebug
     15. full_toroplus-userdebug
     16. full_toro-userdebug
     17. full_panda-userdebug

Which would you like? [aosp_arm-eng]

For this you need to select the " 6. full_grouper-userdebug" choice by entering '6'
It would display the details of the selected "grouper" hardware.

Next major Step is to initiate big build process. This build process would take approximately 2hours 45minutes to complete on the machine specified above. If one has i7 then they can get even faster builds.
This command is:
make -j4

Here the "-j4" switch would help to run the build on Quad core.
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 7 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 that you have successfully built and flashed the code you might not find it very useful until you add all the bells-n-whistles that a professional rom has. We would try to cover that in our next tutorial. Also next tutorials we have described how to restore the factory image.
Hope that you find this post helpful, let us know your feedback and suggestions.