dimanche 9 août 2015

[GUIDE][COMPLETE] All in one Android Development [NOOB FRIENDLY]



Hi All,

I and @akhilnarang decided to post this guide to help anyone wanting to learn building of Roms and kernels. We will be using Ubuntu 14.04 Trusty Tahr here.
You can find instructions to install it elsewhere, just remember rom building needs 64bit OS, minimum 4GB RAM, and 100GB space on HDD. Kernel can be built on less hardware, but will take long
Make sure you have fast net, as you have to download at least 16GB of ROM sources, or more kernel, only 1GB of sources max.
Be prepared to spend a lot of time downloading, learning, and fixing bugs :D

More RAM, or faster CPU, or SSD will speed up the process.
From our personal experiences we have found that this is the best, stable, up-to-date version of Ubuntu yet. This has come from my trial and errors, searching all over the web, and bits I picked up from here and there.

We will move Rom building part when we completed this step properly. Step by step we will learn compiling kernel, using Github, Gerrit, Cherry-picking.
At the end of the post I have linked a script by @akhilnarang which if run will automatically install all these programs for lazy people like us haha :P
If you not interested to do all procedure from below just use the script. Simply it will automatically configure the build environment.

NOTE-------- some of these packages may already be on your machine. Obviously, if you complete a step and you have one of these installed, the machine simply will not do anything. So...it will not hurt anything. Some of the packages are different from Ubuntu 12.04 and 13.04 (use these packages for Ubuntu 14.04 as many of the old ones have obsoleted - these are new replacements).

So if you set up your pc with Ubuntu we are good to go.
All code will be in code boxes like this:
[code]
$ <example command>
[/codes]
means you have to run that command in the terminal (don't type the $).
All commands with sudo, gksudo, or gksu means it requires root permission.
It will ask for password.
Once you type, then in that terminal session it will not ask you for a few minutes again.
Any time you make changes to .bashrc or .profile file, make sure to run

Code:


$ source ~/.bashrc
$ source ~/.profile


Or exit and open new terminal else the changes will not take place

Setting up build environment:

Installing Java JDK

Note: You need JDK 7 or higher when you willing to compile Lollipop. If you wanna compile KitKat or lower you need JDK 6.
Open terminal (CTRL + ALT + T)
Then execute the following commands in terminal one by one:

Download & install java


Code:


$ sudo apt-get update && sudo apt-get install openjdk-7-jdk openjdk-7-jre

CHECK if java properly installed or not

Code:


$ java -version

If you get output like

Code:


java version "1.7.0_79"

on the first line then all is good :D

Now JDK is configured!

Note: Only for Ubuntu 14.04 or higher

Installing Required Packages

Open Terminal
Now execute this command:
Note: This will take some time, has to download about 500MB or so of packages

Code:


$ sudo apt-get update && sudo apt-get install git-core python gnupg flex bison gperf libsdl1.2-dev libesd0-dev libwxgtk2.8-dev squashfs-tools build-essential zip curl libncurses5-dev zlib1g-dev  openjdk-7-jdk pngcrush schedtool \
 libxml2 libxml2-utils xsltproc lzop libc6-dev schedtool g++-multilib lib32z1-dev lib32ncurses5-dev lib32readline-gplv2-dev gcc-multilib liblz4-* android-tools-adb android-tools-fastboot ccache


Installing Android SDK

Download the SDK from here!
Accept Terms & download 64 bit.
Extract in your home directory & rename extracted folder "android-sdk".
Now, execute these commands in terminal:

Code:


$ cd ~/android-sdk/tools/
$ ./android sdk


At this point the SDK should come up and you will need to download at least all the tools and all the extras files (at least to 4.0, so select them and install them.When it finishes downloading & installing everything you have to run this command in ANOTHER TERMINAL:

Code:


$ sudo apt-get install gksudo
$ gksu gedit .bashrc


And you need to add at the end of it your SDK paths these three lines (copy and paste them):


Code:


export PATH=~/android-sdk/tools:$PATH
export PATH=~/android-sdk/platform-tools:$PATH
export PATH=~/bin:$PATH


Save and close the file, then close terminal, or

Code:


source ~/.bashrc

Find your .profile file and add this at the bottom of the file

Code:


PATH="$HOME/android-sdk/tools:$HOME/android-sdk/plartform-tools:$PATH"

SDK is configured.

Configuring USB Access

Now we need to set permissions so that our USB ports can detect our android devices :P
Type in the following commands, it will download a file with the permissions, give it permission to execute, and restart the service.

Code:


$ sudo curl --create-dirs -L -o /etc/udev/rules.d/51-android.rules -O -L https://raw.githubusercontent.com/snowdream/51-android/master/51-android.rules
$ sudo chmod 644  /etc/udev/rules.d/51-android.rules
$ sudo chown root. /etc/udev/rules.d/51-android.rules
$ sudo service udev restart
$ sudo killall adb


ADB & Fastboot are configured

Installing Repo Package

Open terminal and type:

Code:


$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo


Configure Git

Open terminal and type:

Code:


$ git config --global user.email "<your email address here>"
$ git config --global user.name "<your name here>"


Git is configured.

Configure ccache

Open terminal and type:

Code:


$ gksu gedit ~/.bashrc

Enter these lines

Code:


export USE_CCACHE=1
export CCACHE_DIR=~/.ccache


Save & close

Open terminal & execute:

Code:


$ source .bashrc
$ ccache -M 50G


I usually use 50 gigs. You can use more if you have more space, or build for many devices

Make a GitHub account using the same email address you used for configuring git
Then follow these

So if you not interested in doing above all steps then simply use this script by my friend @akhilnarang
Open terminal and type:

Code:


$ sudo apt-get install git-core

       
Code:

       
then do

$ git clone https://github.com/akhilnarang/scripts.git
$ cd scripts
$ . build-environment-setup.sh


This script will install all required packages automatically :D

Congrats :D
[B]YOUR BUILD ENVIROMENT IS NOW SETUP :D[/B

If our build environment setted up successfully now we will concentrete on rom building :)
Now we have Initialize Repo. We will try to build CyanogenMod.

Initialize the repo:

Code:

Code:


$ mkdir cm
$ cd cm
$ repo init -u git://github.com/CyanogenMod/android.git -b cm-12.1
$ repo sync -f --no-clone-bundle


For people who have already done a repo init:

Code:


$ cd cm
$ repo sync -f --no-clone-bundle


When prompted, enter your real name and email address.

Continue onto adding a device

~How To Add A Device To The List~

Find the github for your device you wish to add. (We will give Android One Devices(sprout4&sprout8) as an example

Navigate back to your home directory for building:

Code:


$ cd ~/cm
$ source build/envsetup.sh
Or
$ . build/envsetup.sh


That sets up your environment for building

Get your list of devices:


Code:


$ brunch

Choose your device from the list, till will fetch tree and dependencies if needed, sometimes vendor tree will need to be added manually (In case of CyanogenMod, rest all ROMs keep in dependencies)
Build will start,enjoy!

For users who like understanding>





Code:


. build/envsetup.sh

runs a shell script, which adds various environment variables,etc, and some commands.
Calling "brunch" actually runs the command

Code:


breakfast $@ && mka bacon

(for CM)
$@ in shell script means all the parameters that have been passed, so if you passed brunch sprout, it would pass sprout
breakfast calls lunch, which selects the device, prepares the environment for building for it, fetches dependencies with the help of roomservice python script
"mka bacon"
This calls GNU make, and passes bacon as a parameters, to be "made"
mka is used instead of make, as it automatically uses all available threads of your CPU
If you have a quad core Intel, or octa core AMD, you could run make -j8 bacon
This is just the gist of it, reading through the envsetup.sh would make it clearer




If successful, you will get a zip in out/target/product/device
If not, check post #
Most likely, you will find a solution there.
If not, please ask us in the thread, we would be happy to assist you :)

To be continued



Aucun commentaire:

Enregistrer un commentaire