Skip to content

Developer's Guide

ockwon9 edited this page May 30, 2017 · 10 revisions

This is a developer's guide which helps you to download the NANS source tree and build a system image proper to your target device. Further more, you can modify the project and build your own. Please try and make contributions for the project.

1. Requirements

Before you download and build the Android source, ensure your system meets the following requirements:

Hardware

  • Google Google Nexus series smartphone.
  • PC with at least 100GB of free disk space for a checkout, 150GB for a single build, and 200GB or more for multiple builds.
  • Micro 5-pin USB Cable
  • At least one of external displays supports Miracast or HDMI. For HDMI connection, you need SlimPort-to-HDMI adapter

Warning: You may need to backup the phone. Flashing system images will change entire system of the device.

Software

  • A Linux or Mac OS system (64-bit). It is also possible to build Android in a virtual machine on unsupported systems such as Windows.
  • Java Development Kit 7, which you can download from oracle.com.
  • Python 2.6 -- 2.7, which you can download from python.org.
  • GNU Make 3.81 -- 3.82, which you can download from gnu.org.
  • Git 1.7 or newer. You can find it at git-scm.com.

For more information, visit http://source.android.com/source/requirements.html

2. Establishing a Build Environment

You can get information about establishing a build environment from the manual on the official android webpage.

http://source.android.com/source/initializing.html

This is mainly about installing the JDK and other required packages for Linux or Mac OS.

3. Downloading the NANS Source

The NANS source tree is located in a Git repository. Here are the repositories of each modified source.

You can download them seperately on your own Android project or you can download whole NANS project with Android as following steps.

Installing Repo

Repo is a tool that makes it easier to work with Git in the context of Android.

To install Repo:

  1. Make sure you have a bin/ directory in your home directory and that it is included in your path:

     $ mkdir ~/bin
     $ PATH=~/bin:$PATH
    
  2. 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
    

Downloading NANS source tree

After installing Repo, set up your client to access the Android source repository:

  1. Create an empty directory to hold your working files. If you're using MacOS, this has to be on a case-sensitive filesystem. Give it any name you like:

     $ mkdir WORKING_DIRECTORY
     $ cd WORKING_DIRECTORY
    
  2. Configure git with your real name and email address:

     $ git config --global user.name "Your Name"
     $ git config --global user.email "you@example.com"
    
  3. Downloading the source tree should take several hours due to its size. To download the latest version(master branch) of repository for NANS project:

     $ repo init -u https://github.com/rubis-lab/NANS_Project_for_Android
     $ repo sync
    

Or to check out a branch other than "master", specify it with -b.

    $ repo init -u https://github.com/rubis-lab/NANS_Project_for_Android -b 5.1.1
    $ repo sync

For more information, visit http://source.android.com/source/downloading.html

4. Downloading the Binaries for Nexus Devices

For building system for your target device, additional hardware-related proprietary libraries are needed to run.

Downloading proprietary binaries

You can download official binaries for the supported devices from Google's Nexus driver page. Find out your target device's binaries for the same android version as NANS' version, and download it to your WORKING_DIRECTORY.

e.g. NANS(5.1.1) for Nexus 5  --> Nexus 5 ("hammerhead") binaries for Android 5.1.1

Extracting proprietary binaries

Each set of binaries comes as a self-extracting script in a compressed archive. Uncompress each archive, run the included self-extracting script from the root of the source tree, then confirm that you agree to the terms of the enclosed license agreement. The binaries and their matching makefiles will be installed in the vendor/ hierarchy of the source tree.

5. Building the System

The basic sequence of build commands is as follows:

Set up environment

Initialize the environment with the envsetup.sh script.

$ source build/envsetup.sh

or

$ . build/envsetup.sh

Choose a Target

Choose which target to build:

$ lunch

Then you will see your target device's code name, for example, 'aosp_hammerhead-userdebug'. Then you can select it.

Note : If you cannot see your target, make sure you installed proprietary binaries appropriately.

Or you can configure passing the code name as an argument.

$ lunch hammerhead

If you want to build a image for Android Virtual Device (AVD), you have to choose 'aosp_arm-eng'. Or you can configure passing the code name as an argument.

$ lunch aosp_arm-eng

Build the code

Build everything with make.

Building whole Android source tree should take several hours. GNU make can handle parallel tasks with a -jN argument, and it's common to use a number of tasks N that's between 1 and 2 times the number of hardware threads on the computer being used for the build. For example, on a dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), the fastest builds are made with commands between make -j16 and make -j32.

$ make -j4

Once you build whole source tree, you can use mm and make snod for building only an individual program or module. For more information, visit http://elinux.org/Android_Build_System#Speeding_up_the_build.

After successful build, you will see image files such as 'system.img', 'boot.img' and 'userdata.img' in WORKING_DIRECTORY/out/tartget/product/TARGET_CODE_NAME/

Reference : http://source.android.com/source/building.html, http://source.android.com/source/running.html

6. Flashing NANS Images to the Device

Booting into fastboot mode

The device should be in fastboot mode which is a mode in the bootloader that can be used to flash the device.

To flash a device, you will need to use fastboot and adb, which should be included in your path after a successful build. If you don't already have fastboot and adb, you can build them with the regular build system. Use the instructions in Building the System and replace the main make command with:

$ make fastboot adb

Place the device in fastboot mode either manually by holding the appropriate key combination at boot, or from the shell with the device connected to PC:

$ adb reboot bootloader

If it is successful, it shows like below,

Fastboot Mode

Unlocking the bootloader

It's possible to flash a custom system only if the bootloader allows it, and the bootloader is locked by default. You can unlock the bootloader, but be aware that doing so deletes the user data for privacy reasons (the unlock operation needs to run only once).

With the device in fastboot mode, unlock the bootloader using:

$ fastboot oem unlock

Flashing System Images on the Device

Once the device is in fastboot mode, run:

$ fastboot flashall

Or you can flash individual images:

$ fastboot flash system system.img
$ fastboot flash boot boot.img
$ fastboot flash userdata userdata.img
$ fastboot flash recovery recovery.img

7. Using NANS platform

Turning on NANS Option

As you flash the images, there will be NANS option in Settings. Enable NANS and Multi-Touch options.

Connect with External Displays

You can use external displays by connecting with SlimPort(HDMI) and/or Miracast.

  • For connecting via SlimPort, you can do simply by connecting the cable.
  • For Miracast connection, you need to turn on the Wi-Fi, go Settings > Display & lights > Cast screen and then select the wireless display.

Controlling NANS

NANSControls