Compiling Lineage OS for Raspberry Pi

Rutherford, North Bergen, Bergen County, NJ, NYC, New Jersey, New York, New York City, NY ,	Walden,	Walden System, Waldensys, Ames , Ames Computer, geeks,  geek,  corner, geeks corner, hardware, how to,  MySQL, Raspberry Pi, Pi, rpi, database,  install, packages, dpkg, apt-get, repository, cross compile, Android, gcc, compile, Lineage, Lineage OS
https://www.raspberrypi.org/

The majority of smartphones and tablets out today run the Android OS. Even though the Raspberry Pi is not officially supported by Android OS, there is an open source version of android called LineageOS that we can install on the Raspberry Pi to run Android on the Raspberry Pi. In order to do this, we will cross compile Lineage OS on a Linux machine for the Raspberry Pi. We will need to install some packages on the Linux compile machine, download the source code, then compile.

Downloading necessary packages

In order to compile Lineage OS, we will need to install some software on the compile machine. We will need to add OpenJDK, which is a open source version of Java, Android ADB tools, a cross compiler to compile for the ARM processor, and other supporting files. In order to install OpenJDK, we will add the repository that contains the OpenJDK package using the following commands :

    $  sudo add-apt-repository ppa:openjdk-r/ppa
    $  sudo apt-get update


Next, we will install all the needed packages. We can install them one at a time but for convenience, we will be installing them all at once. When installing packages, we must know the exact name of the package and is case sensitive. We will be installing compilers, cross compilers, libraries needed and other tools.

    $  sudo apt-get install gnupg flex gperf build-essential zip curl 
       zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 
       lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev 
       ccache libgl1-mesa-dev libxml2-utils xsltproc unzip 
       openjdk-8-jdk git phablet-tools python-mako android-tools-adb

    $  sudo apt-get install gcc-arm-linux-gnueabihf

Get source code

Next, we need to get the source code. In order to do so, we need to create a new user for our local git. Once that is done, we will initialize our local git, download the manifest file, and download the source code. The manifest file is an xml file that contains the folder structure and the names of all the files in the repository. We will use this file to download all the source code.

Create User

    $  git config -global user.email "YOUR EMAIL"
    $  git config -global user.name "YOUR NAME"



Initialize local git
    $ repo init -u https://android.googlesource.com/platform/manifest 
       -b android-pi



Download the manifest file
    $  git clone https://github.com/peyo-hd/local_manifests 
       .repo/local_manifests -b ppv



Download the source code
    $  repo sync --force-broken --force-sync

Build from source

Once the files are downloaded, we need to cross compile the kernel source code for the arm processor. After we cross compile the we need patch the framework and build the Android source. Here are the terminal commands to do it. Once everything is done, we will have the compiles binaries for Android OS for the arm processor on the Raspberry Pi. We can copy the files to a sd card and be able to run Android on the Raspberry Pi.

Build kernel

  $ cd kernel/rpi
  $ ARCH=arm scripts/kconfig/merge_config.sh arch/arm/configs/ 
    bcm2709_defconfig kernel/configs/android-base.config 
    kernel/configs/android-recommended.config
  $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make zImage
  $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make dtbs



Patch framework source
    $ nano frameworks/base/core/java/android/view/GestureDetector.java 
    $ nano frameworks/base/opengl/java/android/opengl/GLSurfaceView.java 
    $ nano frameworks/base/core/java/android/os/StrictMode.java 
    $ nano frameworks/av/media/libstagefright/colorconversion/ 
      SoftwareRenderer.cpp



Build Android source
    $ source build/envsetup.sh 
    $ lunch rpi3-eng 
    $ export 
    $ make -j4