Preparing build environment and download android aosp source code on ubuntu 14.04, 15.10, 16.04, 17.10

Modify below script to update AOSP_SOURCE_DIRECTORY, USER_NAME, USER_EMAIL, AOSP_BRANCH as per your requirement.

 $ vim host_prepare_for_aosp.sh 
#!/bin/sh

#########################################################
#
# reference README http://source.android.com/source/downloading.html
# http://source.android.com/source/initializing.html
#
#########################################################

AOSP_SOURCE_DIRECTORY=$PWD/android_aosp #replace with proper directory
USER_NAME="Your Name"
USER_EMAIL="you@example.com"
AOSP_BRANCH=master

INSTALL_ANDROID_VERSION=Oreo #Lollipop Marshmallow, Nougat
REPO_DOWNLOAD_URL=https://storage.googleapis.com/git-repo-downloads/repo

#sudo apt-get install repo

echo "Installing repo binary"
mkdir -p ~/bin
curl $REPO_DOWNLOAD_URL > ~/bin/repo
chmod a+x ~/bin/repo
echo "repo installed at ~/bin/repo"
REPO_CMD=~/bin/repo

export PATH=$PATH:~/bin/repo

UBUNTU_VERSION=`lsb_release -r | awk '{print $2}'`
echo "ubuntu version is $UBUNTU_VERSION"

if [ "$UBUNTU_VERSION" = "14.04" ]; then
	echo "Ubuntu version is 14.04"

	echo "Installing Host Packages required for compiling android "
	sudo apt-get install git gnupg flex bison gperf build-essential \
		zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
		libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
		libgl1-mesa-dev g++-multilib mingw32 tofrodos \
		python-markdown libxml2-utils xsltproc zlib1g-dev:i386

	sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

	if [ "$INSTALL_ANDROID_VERSION" = "Lollipop" || "$INSTALL_ANDROID_VERSION" = "Marshmallow" ]; then
		echo "Installing sun-java6-jdk"
		sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy main multiverse"
		sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy-updates main multiverse"
		sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
		sudo apt-get update
		sudo apt-get install sun-java6-jdk
	else
		if [ "$INSTALL_ANDROID_VERSION" = "Nougat" || "$INSTALL_ANDROID_VERSION" = "Oreo" ]; then
			sudo apt-get update
			sudo apt-get install openjdk-8-jdk
		fi
	fi
fi

if [ "$UBUNTU_VERSION" = "16.04" ]; then
	sudo apt-get install openjdk-8-jdk
	echo "Ubuntu version is 16.04"

fi

mkdir -p $AOSP_SOURCE_DIRECTORY
cd $AOSP_SOURCE_DIRECTORY
git config --global user.name $USER_NAME
git config --global user.email $USER_EMAIL

$REPO_CMD init -u https://android.googlesource.com/platform/manifest -b $AOSP_BRANCH
$REPO_CMD sync

echo "If something didn't worked, refer to https://source.android.com/setup/build/requirements "
 $ bash host_prepare_for_aosp.sh 

Above command will download aosp master into android_aosp directory inside your current working directory i.e. from where you are running this script.

Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply