Compiling & Installing PBD OS - Guanjie-Liu/Pay-By-Data-Android GitHub Wiki

##Project Specifications

Android version: android-5.0.2_r1
Build Environment: Ubuntu 12.04
Device: Nexus 7 2013-Mobile
Sync_gateway: couchbase-sync-gateway-enterprise_1.2.1-4_x86_64
Couchbase Server: couchbase-server-enterprise_4.5.0-ubuntu12.04_amd64

##Setup Instructions The official guides for setting up the build environment for AOSP is here. This document is written based on my own experience. It should only be used to help you replicate the exact build environment I worked under, and reproduce my work. Otherwise consider it as a supplement to the official guides only.

###1. Setting up a Linux build environment Install Ubuntu 12.04 in partition. Allocate about 200 GB for that partition to allow at least 2 builds.
Follow the instructions here to:
Install required packages
Configure USB access
Setup ccache (This will speed up the repeated builds)

You will have to lower down the make version by first download the make 3.81 package, then:
sudo dpkg -i <Downloaded package>.deb (to intall the package)
make -version (to check the actual make version in use)

Install OpenJDK7 by following this link.

###2. Downloading the Source Code Follow this link to download the AOSP. The source code is about 50-60 GB in size, so this will take a while .

###3. Preparing to Build Follow this link. It's important that you download the proprietary binaries from google and extract them to the AOSP. Otherwise the built system will be stuck on the google sign during booting (That's what happened to me before).

Download my PBD source code (all the files that have been added in or modified from AOSP), merge my code with the AOSP, replace the original files when they have the same names.
Note: The directory hierarchy of the PBD source code needs to be preserved after the merge.

###4.Starting to Build Initialise the build environment:
. build/envsetup.sh
choose a build target:
lunch aosp_deb_userdebug
Notify API updates: make update-api
Start the make: make or make -j6 (the number specifies the number of thread used to make)

Depending on your machine, the compilation will take a long time if it's the first time you make, so be patient. In my case, it took me 8 hours for the first make.

###5.Installing system to the device Note: Make sure your device is backed-up to avoid any permanent data lost.

Enable USB debugging mode on you device: Turn on your Nexus 7, go to Settings, click on About tablet, then click Build number about 7 times until developer options is enable.

Go back to Settings, enable USB debugging. Then turn off you device.

Enter fastboot mode by pressing the power button and the volume-down button at the same time for 3-5 seconds. Then you should see an android robot appearing on the screen.

Connect the Nexus 7 to you machine via USB, then execute the following: fastboot -w flashall (-w will erase all the user data)
or
fastboot flashall (to preserve the user data)

Now your device should reboot, and your PBD version of Android is installed!

##Building Apps and Platform_Libraries For adding libraries, Android Open Source Project(AOSP) provides an example library named PlatformLibrary under the path device/sample/frameworks/PlatformLibrary which was used as a skeleton for the PBD library. The advantage to developers of being apple to add custom libraries to the device/sample folder is that their own classes and methods will be available to apps without having to alter or deal with the Android core framework.

If you want to build apps and libraries within AOSP to test the new system:
go to the AOSP root dir.
make com.example.android.pbd
got to the app folder
mm
go to ask folder out/target/product/deb/system/app and set up adb to run it as root user:
adb root
adb remount
push the app to the device
adb push Hello.apk /system/app
// using similar methods // push the jar file from out/target/product/deb/system/framework to /system/framework // push the xml file to /system/etc/permissions