[ Tutorial / Reference ] Learning to Build for Galaxy Note - Galaxy Note GT-N7000 General

--
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
INTRODUCTION
There are several guides and tutorials that teach you how to build your own custom firmware from source.
To the trained eye, the steps to be followed are essentially the same.
But to users with relatively lesser experience in programming or software development/scripting of any kind, it often seems to be a daunting task.
One of the many reasons for this is that users usually have atleast 2 similar guides open side-by-side on their screens.
And when one or two lines of code/instruction do not match, all hell breaks loose.
This might not be the case with you, but it sure was with me.
This guide is based solely on my experience in starting from scratch, trying to build a ROM from CyanogenMod and AOKP sources​​
Before we proceed any further, I would like to clarify that this is NOT a definitive tutorial,
nor is it the best way to get started in ROM development.
There may be ‘kanging’ involved, zipping-unzipping as well.
Purists may take exception to some steps – but then they are purists for a reason.
My purpose is NOT to oppose what the better-skilled developers opine,
nor is it to encourage the said procedures.
However, in the event that I do mention using them –
be aware that the attempt is solely to provide a small impetus to enthusiastic learners, so that it may help them have some know-how on how to finally get started. ​
I intend to proceed slowly, rather than publishing the entire thing all at once
and then having confused users discussing Step 2 and Step 2002 at the same time.
In order to avoid this, the posts that follow will be updated in parts i.e
we shall together proceed ahead once a sizable majority of participants have successfully completed a chunk of required steps.
This, I feel, will ensure that the ensuing discussions are enjoyed and benefitted from by several more users at any given time.
REQUIREMENTS
We would be using the CM10 and AOKP sources as reference to learn building for our device.
For the purpose of this tutorial, we shall work together on the following environment –
◘ Ubuntu 12.04 64-bit
◘ A minimal requirement of a Quad-Core processor with >= 4 GB RAM
◘ A high-speed connection >= 2 mBps
◘ Solid State Drives are highly recommended.
◘ Google Toolbar
◘ Patience
◘ Patience
◘ And more Patience
​
Assuming that you would be syncing either one of the source trees, you would require
about 70-80GB of free space to sync repositories and compile a ROM from start to finish.
Users on Windows have an option of dual-booting.
If they are hesitant to do so, they can also run Ubuntu using a Desktop Virtualization Software.
However, in this case you would then require atleast 6GB of RAM, if not more,
to run both operating systems concurrently.
Users building on a remote server, I presume, would be spoilt for choices different Linux distributions available.
Be sure to have an SCP client in handy.
It is my humble request that we all follow good etiquettes and rules all the more strictly to ensure an enriching learning environment.
◘ Please do not troll here.
◘ The thread is not to be used for smug remarks or aspersions (as most of us are accustomed to)
◘ Code Snippets that will be posted on this thread using the code tag, as part of this thread, are supposed to be entered into the Linux terminal.
◘ You are requested to use Pastebin to post logs and build errors
◘ Please do not use any fancy fonts or bold typefaces.
◘ Please do not create Thank You posts if a particular solution solves your problem.
​
Each and every solution will be verified, and the author in turn will be requested to mark his post in Bold-Green.
Hence the last point above..
It is a given that this shall forever be a Work in Progress.
Things will be added, things will be removed as time flies by.
The only thing that should remain constant is the willingness to learn.
And the willingness to use Google Search.
BIBLIOGRAPHY
◘ [Tutorial] Compile JB on Ubuntu
◘ [TUTORIAL] So You Want To Build AOKP JB? [Ubuntu 12.04+]
◘ CyanogenMod WiKi
◘ Android Open Source Project
◘ Frequent IRC chats with Pier and bajee11
◘ Google chats with other kind developers, users and friends
--

Part 1: Setting-up Build Environment
--
A Build Environment is the state of the machine being used for development, including the directory structure and environment variables for your particular project. ​
Additionally, the command-line build environment for the platform and projects is your build release directory.
And so it follows that though we have our Ubuntu installations done, we are still required
to install additional packages to set-up a build environment suited for our purpose.
OpenJDK is an open-source implementation of the Java Platform, Standard Edition, and related projects.
We shall use OpenJDK-6. Type the following in your terminal -
Code:
$ sudo apt-get install openjdk-6-jdk
At the end of this step you might get a message in terminal related to the need
to update certain elements to complete installation of required packages.
For this, simply run
Code:
$ apt-get update
Python is a general-purpose, interpreted high-level programming language,
whose design philosophy emphasizes code readability.
It may already be installed on your system. But no harm in checking -
Code:
$ [B]sudo apt-get install python[/B]
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Code:
$ [B]sudo apt-get install git-core[/B]
The Android software development kit (SDK) includes a comprehensive set of development tools.
These include a debugger, libraries, a handset emulator based on QEMU, documentation, sample code, and tutorials.
There are 2 ways to install this.
If your Ubuntu setup is on your Home PC and you have GUI access,
you can download the package from here
http://dl.google.com/android/android-sdk_r20.0.3-linux.tgz
To do the same via command line, type this in your terminal -
Code:
$ [B]wget http://dl.google.com/android/android-sdk_r20.0.3-linux.tgz[/B]
This will download the very same package for you to the current working directory.
Now, you have to extract the folder inside the archive, and place it in your home directory.
To do this, enter the following command in your terminal -
Code:
$ [B]tar -xvzf[/B] <filename>.<extension>
For example, if your archive is named android-sdk_linux.tar.gz
where
android-sdk_linux = filename
tar.gz = extension
you will type -
Code:
$ [B]tar -xvzf android-sdk_linux.tar.gz[/B]
Once your folder is extracted, move it to your home directory. Search Google on how to do it.
Next step is to define the path.
For this, go to your home folder and look for a file named .bashrc
For users having the comfort of a GUI, press Ctrl + H incase the file is not visible.
Remote users can use their SCP Client to find the file easily.
Open the file to edit it, and at the bottom paste the following lines -
Code:
# Android tools
export PATH=${PATH}:~/<folder_name>/tools
export PATH=${PATH}:~/<folder_name>/platform-tools
export PATH=${PATH}:~/bin
In the same manner and place, look for the file named .profile and add the following lines at the end -
Code:
PATH="$HOME/<folder_name>/tools:$HOME/<folder_name>/platform-tools:$PATH"
Once, done you now have the Android SDK successfully installed. :good:
In the end, you have to install the remaining packages and libraries and dependencies and what not.
This varies as per the version of the Ubuntu installation.
Since we are (hopefully) on Ubuntu 12.04 (64-bit) , we need to enter the following command in our terminal -
Code:
$ $ s[B]udo apt-get install git-core 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 openjdk-6-jdk tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386[/B]
and then
Code:
$ [B]sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so[/B]
In the even that you get errors relating to unavailability of g++ and gcc
run the following in terminal -
Code:
$ [B]apt-get install gcc[/B]
Code:
$ [B]apt-get install g++[/B]
and then repeat the previous steps.
I would also advise that you install the following as well (more on it later) -
Code:
$ [B]apt-get install lzma[/B]
Code:
$ [B]apt-get install screen[/B]
With the above done, all that is left to do is to initialize the repository that you require and then sync it to your machine or remote server. This we do in the next part.
--

Part 2: Fetching sources
--
Repo is a repository management tool that was built on top of Git
.
Repo unifies the many Git repositories when necessary, does the uploads to the revision control system, and automates parts of the Android development workflow.
Repo is not meant to replace Git, only to make it easier to work with Git in the context of Android.​
More information on the subject can be found here.
In our context, we need to download repositories of the correct Android branch (ICS, JB etc) for which we want to build.
But whose branch?
That is completely upto you to decide.
The first step is to 'download and install the repo binaries'. Issue the following commands in terminal -
Code:
$ [B]mkdir ~/bin[/B]
$[B] PATH=~/bin:$PATH[/B]
$ [B]curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo[/B]
$ [B]chmod a+x ~/bin/repo[/B]
With this done, we now make a new folder in our home directory where we would be downloading our rom sources by initializing the relevant repo
Code:
$ [B]mkdir myrom[/B]
$ [B]cd myrom[/B]
For CM10
Code:
$ [B]repo init -u git://github.com/CyanogenMod/android.git -b jellybean[/B]
For AOKP
Code:
$ [B]repo init -u git://github.com/AOKP/platform_manifest.git -b jb[/B]
You will most likely be prompted for certain details like name, email etc. Fill those in and proceed to the next step.
Once you have the above completed ( repo has been initialized in /....) it is time to sync! :good:
Simply issue the command -
Code:
$ [B]repo sync[/B]
You might have come across variations like
Code:
$ repo sync [B]-j4[/B]
or
Code:
$ repo sync [B]-j16[/B]
Essentially, all are performing the same function. Only difference is that by adding that little -j
we are specifying how many jobs we want to run concurrently, which is in a way directly related
to the number of cores powering your machine.
I have a quad-core, he has a dual-core, what should we use?
Go ahead and see for yourself.
Your first sync (rather a download) would likely take around 45 minutes to 1 hour, if you have a decent internet connection.​
The first time I decided to do this, I wasn't aware of how big the repositories could be, or what sort of an internet connection one would require.
As long as it was an unlimited data plan (yes we have limited data plans in our country), it would be fine I thought.
I had the screen active for around 6 hours without any signs of stopping, until I was finally put out of my misery by good friend antiochasylum -
me: Wow
It takes us a day to download movies
20kbps. Its party time if I can get anything
above 100kbps
Matt: Holy ****. Lol. Mrs Antis galaxy s2 lte gets 5500 down.
Blows the **** outta my note
me: :sniff:
Click to expand...
Click to collapse
Sit back and enjoy.
Do not get all tensed if the text on your screen suddenly stops moving OR is stuck at some place.
Unless and until you are back to the bash shell with a definite error message explaining why repo sync was interrupted - you are all good. :laugh:
--

rvd

reserved

one more

last

And this one is for me..... Thanks a lot dude... will keep watching this space..

Thank you so much, this is great for us newbies :highfive:

Wow, wanted to learn since longthanks

Great idea toxic, you might've just encouraged me to start compiling and building again
Sent from my GT-N7000 using XDA Premium HD app

thanks

Grrr888888. thank you very much :good:

Thank you, with my computer it gonna take forever compiling , it's is only dual core 2,1 ghz :silly:.
But since i've got patient, i'm gonna try.
PS: I have plans to install gentoo on the same team at some point in the future so this will be easy in comparison.

Please share this with other users who might be interested so that all can benefit.
Thanks
Sent from my GT-N7000 using xda premium

While setting up Ubuntu via VM for windows i am able to run though entire installation procedure but getting an critical error after i restart when the installation is complete..
sorry, this may not be exactly related with the topic directly but i thought i might find my answer here..
Sent from my GT-N7100 using Tapatalk 2

What would the error message be? I mean what exactly does it say?
Sent from my GT-N7000 using xda premium

http://pastebin.com/VLtJzaqd
Ubuntu log for your ready reference.

sunny2303 said:
http://pastebin.com/VLtJzaqd
Ubuntu log for your ready reference.
Click to expand...
Click to collapse
It seems he SATA controller in your VM has only one port configured and is unavailable to make hotplugging work.​
Make sure you are not trying to run your installation from a Guest/Limited account.
Also, in case you're trying to run Ubuntu from a CD instead of copying files to the the hard disk, you may face some problems.
Sent from my GT-N7000 using xda premium

Thanks this solution worked You were right the isse was with SATA controller.. I had not assigned it. After assigning it under settings, it worked.
Now I have moved slightly ahead... at the path setting stage
export PATH=${PATH}:~/<folder_name>/tools
export PATH=${PATH}:~/<folder_name>/platform-tools
export PATH=${PATH}:~/bin
while we are writing this in .bashrc are we supposed to replace <folder_name>/ with actual folder name? like say extracted folder name is android-sdk-linux which is placed under home.. so should we write <android-sdk-linux> ?

Related

[GUIDE][ICS] Compile Cyanogenmod 9 on Mac OS X Lion

There are a lot of toturials for building CM9 on ubuntu or CM7 on Mac but I couldn't find a decent toturial for building CM9 on Mac (specially Lion). Development in AOSP/CM land is rapid and guides frequently need updating. I had to spend a little time to figure everything out and I decided to share it here.
This tutorial is for building CM9 (ICS) for Galaxy Nexus GSM (maguro) on Mac OS X Lion 10.7.3 using Xcode 4.3 and homebrew . You can easily make the instructions work for most other cm9 devices, but I wouldn't know anything about that.
DISCLAIMER: I'm not responsible if you blow yourself up, blah blah blah
However, I've tried to make this as noob friendly as possible because, well I'm a noob myself
Instrunctions:
UPADTE (MAY 29TH) : The Xcode 4.3 default compiler (llvm-gcc) used to be incompatible with CM9. Thanks to jocelyn and topprospect, the LLVM compatibility patches from mainline AOSP are now merged into CM9. Therefore, you can now use Xcode 4.3 and its command line tools without installing another compiler. However, since GCC is still the only officially supported compiler, incompatibilites with llvm-gcc could still be introduced with future updates. Therefore, if your build fails, it might be worth it to try installing and compiling with GCC 4.2. See the Troubleshooting section for more info.
Now that we have Xcode 4.3 and Xcode command line tools (CLT) installed, let's continue.
Open Terminal and run
Code:
java
if you don't have Java, you will get a prompt asking you to download and install Java. Go ahead and install it.
If you don't have adb and fastboot working, download the android-sdk from google (version r18 as of now) and put it in /usr/local/ and rename the folder to "android-sdk".
Install the homebrew package manager
Code:
/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
To make sure that homebrew and android-sdk executables are in $PATH:
Code:
touch ~/.bash_profile && echo "PATH=/usr/local/bin:/usr/local/sbin:$PATH:/usr/local/android-sdk/tools:/usr/local/android-sdk/platform-tools" >> ~/.bash_profile
Relaunch Terminal for the change to take effect.
At this point you can run
Code:
brew doctor
to detect any problems there might be (Homebrew may instruct you to use the xcode-select utility to select the xcode installation path). Hopefully, your system is raring to brew
Now we have to install a bunch of packages:
Code:
brew install git coreutils findutils gnu-sed gnupg pngcrush repo
We now need to create a couple of symlinks so that the gnu versions of 'sed' and 'find' are used rather than the osx provided versions :
Code:
ln -s /usr/local/bin/gfind /usr/local/bin/find && ln -s /usr/local/bin/gsed /usr/local/bin/sed && ln -s /usr/local/bin/gstat /usr/local/bin/stat
It's time to create a case sensitive image which will hold our working directory:
Code:
hdiutil create -type SPARSE -fs "Case-sensitive Journaled HFS+" -size 40g -volname "android" -attach ~/Desktop/Android
Now we have a disk image in ~/Desktop/Android. Mount it if it's not mounted already. (Don't be picky about the size, the image will only take as much as space as its contents).
Now we need to create a working directory inside the mounted volume:
Code:
cd /Volumes/android && mkdir cm9 && cd cm9
We can initialize and download the source now:
Code:
repo init -u git://github.com/CyanogenMod/android.git -b ics && repo sync && say 'finished'
Now we need to get the required proprietry files for our device. We can get these from the device itself. Connect your phone (make sure USB Debugging is enabled) and run the following (for maguro):
Code:
cd /Volumes/android/cm9/device/samsung/maguro/ && ./extract-files.sh
[If you see errors in the output from extract-files.sh, see the Troubleshooting section below]
For Google devices,we can also get them directly from google. For maguro, download the 3 files and extract them to /Volumes/android/cm9. Then,
Code:
cd /Volumes/android/cm9
/Volumes/android/cm9/extract-broadcom-maguro.sh
/Volumes/android/cm9/extract-imgtec-maguro.sh
/Volumes/android/cm9/extract-samsung-maguro.sh
We also need the prebuilts (like ROM manager and Term.apk):
Code:
/Volumes/android/cm9/vendor/cm/get-prebuilts
You can optionally tell the build to use the ccache tool. CCache acts as a compiler cache that can be used to speed-up rebuilds :
Code:
export USE_CCACHE=1 && /Volumes/android/cm9/prebuilt/darwin-x86/ccache/ccache -M 20G
Default is 1GB. Anything between 20GB-50GB should be fine.
Before starting the build, we need to workaround an issue with Lion and compiling the QEMU emulator.
[This step doesn't seem to be needed anymore. QEMU is automatically ignored on OS X/Darwin]
If you build now, you're probably gonna get kernel build errors regarding the missing elf.h header (this error might be device specific). Fortunately, we already have this file downloaded, so we only need to copy it to /usr/local/include:
Code:
cp /Volumes/android/cm9/external/elfutils/libelf/elf.h /usr/local/include
FINALLY, we are ready to build:
Code:
cd /Volumes/android/cm9 && source build/envsetup.sh && brunch
Pick your device from the list and enter the number. For maguro, you could use "brunch maguro" instead and skip the menu. Depending on your system, this will take 30min-4hours.
You should now see a beautiful zip file waiting to be flashed:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
​Troubleshooting:
The extract script for maguro seems to be a little outdated, as it doesn't pull the gps proprietary blob. You can either use the google provided scripts, or add koush's git repository for your device to your local_manifest.xml.
As explained above, the CM9 source is currently compatible with llvm-gcc. In the future, if llvm-gcc fails to build correctly, you should try installing and compiling using GCC4.2 (the Xcode 3 compiler). You can install apple-gcc4.2 from homebrew:
Code:
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb
This version of gcc can happily coexist with Xcode 4.x .
So now you have GCC 4.2 installed, but it won't be used unless we update the corresposing environment variables:
Code:
export CC=/usr/local/bin/gcc-4.2 && export CXX=/usr/local/bin/g++-4.2
Notice that using the export command is temporary. If you relaunch Terminal, you will need to set these again. However, this is a good thing, because changing these values permanently (by putting them in ~/.bash_profile) can interfere with other builds.
If you use this method, the build might fail while compiling "external/zlib/x86/adler32.c". It appears that a recent change in zlib has introduced an incompatibility with gcc 4.2. you have to revert the following 2 commits:
Code:
cd external/zlib
git revert dd6786cae3f4493faa6661d5f74db587932f15d7
git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
Alternatively, you can add topprospect's zlib on github (which has those commits reverted) to your local_manifast.xml. Simply run:
Code:
nano /Volumes/android/cm9/.repo/local_manifest.xml
and add the following line
Code:
<project name="dferg/android_external_zlib" path="external/zlib" remote="github" />
If you get a build error, and your error is not covered here, copy the last 20-30 lines of the build output AND the output from the following command into pastebin and post the link. Hopefully me or someone else will help you.
Code:
echo -e "\nENV:\n$(env)\n\nWHICH GCC\n:$(which gcc)\n\nWHICH G++:\n$(which g++)\n\nWHICH CC:\n$(which cc)\n\nWHICH C++:\n$(which c++)\n\nBREW DOCTOR:\n$(brew doctor)\n\nBREW LIST:\n$(brew list)\n\n/USR/BIN:\n$(ls -l /usr/bin | grep gcc)\n\n/USR/LOCAL/BIN:\n$(ls -l /usr/local/bin | grep gcc)\n\n"
​Notes/Extras:
To quickly setup your environment, add an alias like the following to ~/.bash_profile:
Code:
alias cm9env="hdiutil attach PATH-TO-DISK-IMAGE -mountpoint /Volumes/android && cd /Volumes/android/cm9 && source ./build/envsetup.sh && export USE_CCACHE=1"
alias cm9build="cm9env && make clobber && reposync && brunch maguro"
Now you can save time by using "cm9env" to get your environment setup or "cm9build" to compile a clean updated build.
To clear your output directory for a new build, run "make clobber". You probably don't need this if you've only changed a few lines of code.
To cherry pick yet-to-be-merged changes from the gerrit instance:
1. Pick an open commit from CM Gerrit
2. Under list of Patch Sets pick the latest and open cherry-pick tab
3. Check what Git repository the url is pointing e.g. http://review.cyanog...frameworks_base
4. In your CM9 working tree go to the corresponding directory, which in this case is something like ~/your-working-directory/frameworks/base/
5. Now simply paste the whole line seen in CM Gerrit cherry-pick tab e.g. "git fetch http://review.cyanog....rameworks_base refs/changes/00/13100/4 && git cherry-pick FETCH_HEAD"
It should be now included in your next compiled build. When doing repo sync again, cherry picks will be lost.[CREDIT Fihlvein from xda]
Click to expand...
Click to collapse
Enjoy your custom built CM9!
I updated OP with some updated info about Xcode 4.3.
Nice work man. Very helpful.
conantroutman said:
Nice work man. Very helpful.
Click to expand...
Click to collapse
thanks! I'll try to keep this topic updated as issues with mac are introduced/resolved.
Nice write up. Thanks.
Before I start again from scratch I have a question. Does this guide apply to previous versions of mac os x (mine is 10.6.8)? I used the official android initializing build environment page & cm7 wiki page for the instructions to setup my build environment.
Also, any tips to switch from macports to homebrew?
In the past I've had to cherry pick to get my OS X build environment set up for CM9. The compile from source fails because I started with macports instead of homebrew (bad idea). I tried to switch to homebrew without success. Any tips to switch from macports to homebrew?
For the sake of keeping this page on topic a pm response is ok if that is what you prefer.
Hi thanks for this !! Helpful one question what do i change so i can do AOSP instead of cm9??
grad061980 said:
Nice write up. Thanks.
Before I start again from scratch I have a question. Does this guide apply to previous versions of mac os x (mine is 10.6.8)? I used the official android initializing build environment page & cm7 wiki page for the instructions to setup my build environment.
Also, any tips to switch from macports to homebrew?
In the past I've had to cherry pick to get my OS X build environment set up for CM9. The compile from source fails because I started with macports instead of homebrew (bad idea). I tried to switch to homebrew without success. Any tips to switch from macports to homebrew?
For the sake of keeping this page on topic a pm response is ok if that is what you prefer.
Click to expand...
Click to collapse
Yes, this guide should work fine on Snow Leopard. It mostly depends on your Xcode version. If you have Xcode 3, you can skip step 1 entirely, since you already have gcc4.2 as part of Xcode.
If you have access to Xcode 4.2 and above, you will need to install gcc4.2 separately, as explained in the guide.
Now regarding Macports, I strongly suggest that you completely uninstall Macports before installing homebrew. Instructions are here: http://guide.macports.org/chunked/installing.macports.uninstalling.html
WonkyYew said:
Hi thanks for this !! Helpful one question what do i change so i can do AOSP instead of cm9??
Click to expand...
Click to collapse
Full instructions are available on android.com : http://source.android.com/source/initializing.html
If you are using this guide, you need to change the repo initialization command to :
Code:
repo init -u https://android.googlesource.com/platform/manifest
and then do repo sync. You can setup ccache as usual. I don't think AOSP has the "brunch command", so you have to use launch and then make.
Run "lunch" and select an option from the menu. You can find more info about the options here: http://source.android.com/source/building.html. For maguro, you should use "full_maguro-userdebug".
To start the build, use
Code:
make -j$(sysctl -n hw.ncpu)
@ArmanUV. Sounds good & thanks for the input. I'll give the link to macports uninstall a go.
Im a real noob, whats the advantage of compiling from source?
Thanks for the help man !
Hi, thanks for your guide, setting up the repo was no problem at all!
But: I'm getting the following error when building.
Code:
external/zlib/x86/adler32.c: In function ‘adler32_MMX’:
external/zlib/x86/adler32.c:747: error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
external/zlib/x86/adler32.c:747: error: ‘asm’ operand has impossible constraints
make: *** [out/host/darwin-x86/obj/STATIC_LIBRARIES/libz_intermediates/adler32.o] Error 1
make: *** Waiting for unfinished jobs....
Seems to be a problem with the compiler, but I'm on xcode 4.3 and I've installed gcc-4.2 and set the env vars. Any help?
ArmanUV,
Thanks so much for posting this guide. Very helpful!
Are you having any trouble with errors like this?
Code:
external/zlib/x86/adler32.c: In function ‘adler32_MMX’:
external/zlib/x86/adler32.c:747: error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
external/zlib/x86/adler32.c:747: error: ‘asm’ operand has impossible constraints
Googling for this error implies that the fix is to use a version of GCC > 4.2. But there does not seem to be a GCC 4.4 in Homebrew.
Thanks again for the guide!
EDIT: Sorry for the double post with empyyy. Seems like there is someone else having my same issue!
topprospect said:
ArmanUV,
Thanks so much for posting this guide. Very helpful!
Are you having any trouble with errors like this?
Code:
external/zlib/x86/adler32.c: In function ‘adler32_MMX’:
external/zlib/x86/adler32.c:747: error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
external/zlib/x86/adler32.c:747: error: ‘asm’ operand has impossible constraints
Googling for this error implies that the fix is to use a version of GCC > 4.2. But there does not seem to be a GCC 4.4 in Homebrew.
Thanks again for the guide!
EDIT: Sorry for the double post with empyyy. Seems like there is someone else having my same issue!
Click to expand...
Click to collapse
empyyy said:
Hi, thanks for your guide, setting up the repo was no problem at all!
But: I'm getting the following error when building.
Code:
external/zlib/x86/adler32.c: In function ‘adler32_MMX’:
external/zlib/x86/adler32.c:747: error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
external/zlib/x86/adler32.c:747: error: ‘asm’ operand has impossible constraints
make: *** [out/host/darwin-x86/obj/STATIC_LIBRARIES/libz_intermediates/adler32.o] Error 1
make: *** Waiting for unfinished jobs....
Seems to be a problem with the compiler, but I'm on xcode 4.3 and I've installed gcc-4.2 and set the env vars. Any help?
Click to expand...
Click to collapse
You guys seem to have the same issue. What sort of Xcode configuration are you using? Can you post the output from "which gcc","which g++", "gcc -v", "g++ -v" and "cc -v"?
ArmanUV said:
You guys seem to have the same issue. What sort of Xcode configuration are you using? Can you post the output from "which gcc","which g++", "gcc -v", "g++ -v" and "cc -v"?
Click to expand...
Click to collapse
I am on Lion 10.7.4 with Xcode 4.3.2. Here is the output that you asked for:
Code:
# echo -n "which gcc: "; which gcc; echo -n "which g++: "; which g++; echo ""; echo "gcc -v:"; gcc -v; echo ""; echo "g++ -v:"; g++ -v; echo ""; echo "cc -v:"; cc -v
which gcc: /usr/bin/gcc
which g++: /usr/bin/g++
gcc -v:
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
g++ -v:
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
cc -v:
Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
They are pointing to LLVM, but my CC and CXX variables point to:
Code:
env|grep 4.2
CXX=/usr/local/bin/g++-4.2
CC=/usr/local/bin/gcc-4.2
Do I need to add something to PATH? I'm sure I just missed something obvious in your instructions.. Thanks for helping!
topprospect said:
I am on Lion 10.7.4 with Xcode 4.3.2. Here is the output that you asked for:
Do I need to add something to PATH? I'm sure I just missed something obvious in your instructions.. Thanks for helping!
Click to expand...
Click to collapse
Everything checks out. I'm away from my main machine so I can't run a test build, but I suspect that a recent change is causing problems.
Now, regarding the compiler, Setting CC/CXX *should* take care of everything, but I am currently not 100% sure that somewhere in a makefile, these environment variables aren't being ignored. Since I wrote the guide, I noticed a lot of clang warnings in the build, which means that CC/CXX is not honored and /usr/bin/cc and /usr/bin/c++ is being used.
A more robust method of making sure gcc-4.2 is being used is creating symlinks to gcc-4.2 and g++-4.2 :
Code:
ln -s /usr/local/bin/gcc-4.2 /usr/local/bin/gcc
ln -s /usr/local/bin/gcc-4.2 /usr/local/bin/cc
ln -s /usr/local/bin/g++-4.2 /usr/local/bin/c++
ln -s /usr/local/bin/g++-4.2 /usr/local/bin/g++
Obviousely, a systemic method like this has its downsides but it may be the only choice without having to change CM code (especially since I lack the knowledge to do so )
[I recently found out that master aosp is no longer using CC/CXX to find the compiler (see ./build/core/combo/). Instead, it uses "gcc" and "g++" directly, which means that llvm-gcc will be used no matter what env variable you have. Fortunately, unlike cm9, master aosp is supposed to build fine with llvm-gcc (except for qemu, which doesn't matter for device images). ]
ArmanUV said:
Everything checks out. I'm away from my main machine so I can't run a test build, but I suspect that a recent change is causing problems.
Now, regarding the compiler, Setting CC/CXX *should* take care of everything, but I am currently not 100% sure that somewhere in a makefile, these environment variables aren't being ignored. Since I wrote the guide, I noticed a lot of clang warnings in the build, which means that CC/CXX is not honored and /usr/bin/cc and /usr/bin/c++ is being used.
A more robust method of making sure gcc-4.2 is being used is creating symlinks to gcc-4.2 and g++-4.2 :
Code:
ln -s /usr/local/bin/gcc-4.2 /usr/local/bin/gcc
ln -s /usr/local/bin/gcc-4.2 /usr/local/bin/cc
ln -s /usr/local/bin/g++-4.2 /usr/local/bin/c++
ln -s /usr/local/bin/g++-4.2 /usr/local/bin/g++
Click to expand...
Click to collapse
Okay, just tried this. I created a new dir (/Volumes/Android/bin) that simply houses those softlinks you recommended. Then I put /Volumes/Android/bin at the beginning of my PATH. That should fix it without breaking the rest of the system, e.g. homebrew.
The GENERAL_REGS problem still exists though. Pretty sure b/c gcc 4.2.1 doesn't understand this construct properly (need a newer version of gcc).
So I backed out the change that introduced this adler32.c.
https://github.com/CyanogenMod/android_external_zlib/commit/13bf40af68236c961542bdee1d4b7c0176bf15a0
The compile is getting farther now. I have to run to work so I'll post later if it succeeds.
The weird thing is: This change was made back in December. Why would it have worked for you?
topprospect said:
The compile is getting farther now. I have to run to work so I'll post later if it succeeds.
Click to expand...
Click to collapse
Build works (and boots!) with the following:
Code:
cd external/zlib
git revert dd6786cae3f4493faa6661d5f74db587932f15d7
git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
Note the 1st revert is just to avoid massive conflicts seen when reverting the 2nd one by itself. The 2nd revert is the one that really matters here.
So this isn't really a solution.. Seems like we need to move to a newer version of gcc or figure out a patch to adler32.c that makes it gcc 4.2 compatible.
topprospect said:
Build works (and boots!) with the following:
Code:
cd external/zlib
git revert dd6786cae3f4493faa6661d5f74db587932f15d7
git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
Click to expand...
Click to collapse
The first revert works fine, however the second one gives me the following error:
Code:
$ git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
error: could not revert 13bf40a... Implement vectorized adler32 and optimized slhash
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
error: Could not parse conflict hunks in zlib.h
empyyy said:
The first revert works fine, however the second one gives me the following error:
Code:
$ git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
error: could not revert 13bf40a... Implement vectorized adler32 and optimized slhash
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
error: Could not parse conflict hunks in zlib.h
Click to expand...
Click to collapse
Well, run git status. You'll see that the only conflict is in the comments in zlib.h. So, you can just ignore it.
topprospect said:
Okay, just tried this. I created a new dir (/Volumes/Android/bin) that simply houses those softlinks you recommended. Then I put /Volumes/Android/bin at the beginning of my PATH. That should fix it without breaking the rest of the system, e.g. homebrew.
The GENERAL_REGS problem still exists though. Pretty sure b/c gcc 4.2.1 doesn't understand this construct properly (need a newer version of gcc).
So I backed out the change that introduced this adler32.c.
https://github.com/CyanogenMod/android_external_zlib/commit/13bf40af68236c961542bdee1d4b7c0176bf15a0
The compile is getting farther now. I have to run to work so I'll post later if it succeeds.
The weird thing is: This change was made back in December. Why would it have worked for you?
Click to expand...
Click to collapse
topprospect said:
Build works (and boots!) with the following:
Code:
cd external/zlib
git revert dd6786cae3f4493faa6661d5f74db587932f15d7
git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
Note the 1st revert is just to avoid massive conflicts seen when reverting the 2nd one by itself. The 2nd revert is the one that really matters here.
So this isn't really a solution.. Seems like we need to move to a newer version of gcc or figure out a patch to adler32.c that makes it gcc 4.2 compatible.
Click to expand...
Click to collapse
Nice find. I tried to compile this morning and I ran into the same issue. This is what I don't understand: I did a couple of builds about a week ago without running into this issue. But, the latest commits on zlib are from 2 months ago.
Amazingly, the Xcode 4.3 toolchain (clang and llvm-gcc) builds this external/zlib/adler32.c just fine.
An alternative to this problem is to install an up to date gcc 4.7 :
Code:
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gcc.rb
and then create symlinks to gcc-4.7/g++-4.7. I have not tested this yet.

[ULTIMATE GUIDE][Noob Friendly]Compile your own android kernel from source

Hey, Guys
Today I'm going to show you a nice tutorial on how to compile your own android kernel from source, this tutorial will be a little bit focused on Sony devices as i had an experience with 'em, but that is not going to prevent that this way can be good for other manufacturers as all of them are Android based (Same programing language)
I have included screenshots and examples of codes to accompany each step of the way. :good:
On XDA Portal:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Chapters:
1.Installing Ubuntu (Alongside with Windows OS)
2.Downloading the source code
3.Installing libraries
4.Preparing the toolchain
5.Adding Features to the Kernel
6.Compiling
7.Trying out your kernel
8.Additional Tips
Click to expand...
Click to collapse
Requirments:
Ubuntu 12.04 LTS or Newer
Manufacturer sources (Links located down for most of the manufacturers)
Linaro Toolchain
Simple background about executing Linux terminals
Click to expand...
Click to collapse
1.Installing Ubuntu
As we all know, Ubuntu is free open source OS that allows you to use it alongside your already installed OS without any problems, you will be promoted at every startup to choose whether your Default OS or Ubuntu OS
So, don't get freaked guys no partitions are going to be formatted or no data loss is going to happen at all.
1)Get the Ubuntu ISO
Go to Ubuntu site (Downloads section)
Choose whether you are on 32-bit or 64-bit (We'll be assuming that we are on 32-bit)
Download the ISO then burn the ISO to DVD then boot it (or you can write install your ubuntu via usb by using this tutorial
Choose "install Ubuntu alongside your windows OS version"
Manage the partitions yourself
You got your Ubuntu ready. Time for some business
2.Downloading the Source Code
Motorola: opensource.motorola.com/
LG: http://opensource.lge.com/osList/list?m=Mc001&s=Sc002
Huawei: http://emui.huawei.com/en/plugin.php?id=hwdownload
Sony: http://developer.sonymobile.com/downloads/xperia-open-source-archives/
HTC: http://www.htcdev.com/
Samsung: http://opensource.samsung.com/
Download the TAR Source file that suits your firmware version for e.g (11.2.A.0.31)
To find your firmware version go to settings then about phone. You will see your firmware version there
Reserved
3.Installing Libraries and Preparing the Environment
As you know guys there are several libraries needed for any software to terminate properly so, if you want to succeed in compiling you have to get these libraries that we're gonna write through the Linux terminal
1)Open the Linux Terminal
2)Write these commands
Code:
sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2
Code:
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0
Code:
mkdir android
3)Copy the source code archive into the folder android (that has been created throughout the “mkdir android” command
4)Run these commands
Code:
cd android
Code:
tar -xjvf [COLOR="DarkSlateBlue"]Source Name[/COLOR]
Replace Source Name with the Archive name
4.Preparing the toolchain
(You should download the whole toolchain of DoomLord, But to save our time I decided not to download the whole toolchain since that we're going to use only one folder of it)
The folder will be: arm-eabi-4.33 (Took from Linaro 4.6) (So you can consider your kernel is compiled using Linaro 4.6
Download arm-eabi-4.4.3
and extract it in the root of your home
And if you want to download the whole source run these commands
Code:
cd android
Code:
cd kernel
Code:
git clone git://github.com/DooMLoRD/android_prebuilt_toolchains.git toolchains
Reserved
5.Adding Features to the Kernel
A)Automatic Way (Using the toolchain menu)
Code:
cd android
Code:
cd kernel
Code:
ARCH=arm CROSS_COMPILE=~/arm-eabi-4.4.3/bin/arm-eabi- make Device Name
Code:
make ARCH=arm CROSS_COMPILE=~/arm-eabi-4.4.3/bin/arm-eabi- menuconfig
Replace Device Name with the configuration file found at:
Source/arch/arm/configs
It's written in this way something_DeviceCodename_user_defconfig
A menu like this will appear
Choose the features you want.
B)Manual Way
1)Adding Governors
The CPU is just 1 C file (Can be found at sources of any of kernel developers)
Get the Governor file
1.1 If you cant get it through github just view it and use other stock governor file like this
my kernel has already got performance governor, you are going to take it from Kernel Source/drivers/cpufreq/cpufreq_performance.c
Copy cpufreq_performance.c from kernel source to desktop then open it with text editor
delete all the lines in it then copy the lines from the viewed governor on github and rename the whole file name
1.2
Copy the governor C file to KernelSource/drivers/cpufreq and paste it
Open Kconfig
Then Add these lines with proper replacment
Code:
config CPU_FREQ_GOV_GOVNAMEHERE
tristate "'gov_name_lowercase' cpufreq governor"
depends on CPU_FREQ
help
governor' - a custom governor!
For BadAss (For Example)
Code:
config CPU_FREQ_DEFAULT_GOV_BADASS
bool "badass"
select CPU_FREQ_GOV_BADASS
help
Use the CPUFreq governor 'BADASS' as default
Find endchoice
Add these lines below it
Code:
config CPU_FREQ_GOV_BADASS
tristate "'badass' cpufreq governor"
depends on CPU_FREQ
help
'badass' - This driver adds a dynamic cpufreq policy governor.
The governor does a periodic polling and
changes frequency based on the CPU utilization.
The support for this governor depends on CPU capability to
do fast frequency switching (i.e, very low latency frequency
transitions).
If in doubt, say N.
1.3
Open Makefile
Add the line according to the Governor
HTML:
obj-$(CONFIG_CPU_FREQ_GOV_BADASS) += cpufreq_badass.o
1.4
Open Kernel Source/include/linux.* now open cpufreq.h
Add these lines (With Proper Replacments)
Code:
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_badass)
extern struct cpufreq_governor cpufreq_gov_badass;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_badass)
2)Adding I/O Schedulers
Get the I/O .c file as the same way you got the Governor File
Paste it to Kernel Source/block
2.1
Now Open Kconfig.iosched
Let's Assume that we now see SIO
HTML:
config IOSCHED_SIO
tristate "Simple I/O scheduler"
default y
---help---
The Simple I/O scheduler is an extremely simple scheduler,
based on noop and deadline, that relies on deadlines to
ensure fairness. The algorithm does not do any sorting but
basic merging, trying to keep a minimum overhead. It is aimed
mainly for aleatory access devices (eg: flash devices).
And we will add the I/O Scheduler VR Below it like:
We will put VR below it
HTML:
config IOSCHED_VR
tristate "V(R) I/O scheduler"
default y
---help---
Requests are chosen according to SSTF with a penalty of rev_penalty
for switching head direction.
Let's assume that we saw SIO (But in different way)
config DEFAULT_SIO
Code:
bool "sio" if IOSCHED_SIO=y
We will put VR below it
Code:
config DEFAULT_VR
bool "V(R)" if IOSCHED_VR=y
Let's assume that we saw SIO (But in another different way)
Code:
default "sio" if DEFAULT_SIO
We will put VR below it
Code:
default "vr" if DEFAULT_VR
2.2
Open the Makefile at the same folder
Lets Assume that we saw SIO And we will put VR below it
Code:
obj-$(CONFIG_IOSCHED_SIO) += sio-iosched.o
Add VR Now
Code:
[obj-$(CONFIG_IOSCHED_VR) += vr-iosched.o
Done We have added the VR I/O Scheduler !
3)Overclocking
Unfortunately, overclocking can't be told the way i said the Governors and I/O Schedulers way because every device has its specific CPU frequencies
But, here is a little help
Go to KernelSource/arch/arm/mach-msm/acpuclock-XxXX.c
You will find files like these
acpuclock-7x30.c
acpuclock-8x50.c
You will see each one of them has only .c file
except one which will have .c and .o file
the one with both .c and .o files will be edited
Explanation will be added as soon as possible
Last
6.Compiling
Part.A
Code:
cd android
Code:
cd kernel
Code:
export ARCH=arm
Code:
export CROSS_COMPILE=~/android/kernel/arm-eabi-4.4.3/bin/arm-eabi-
Part.B (Wanna do some modifications ?)
Code:
make <your_config_name>_defconfig
Replace <your_config_name> with the one found at Source/arch/arm/configs
Code:
make menuconfig
Code:
make -j<cpucore>
Replace <cpucore> with the number of cpu cores that the device has if you are on single core write 1 and if you are on dual core write 2[
Quad core=4
Octa core=8
Part.C
Code:
make clean
Code:
make oldconfig
Code:
make -j<cpucore>
Same as before.
7.Trying out your kernel
Once you have got an output which will be kernel.elf
You have now to try it
Flash it using fastboot
Whether CMD or Androxyde Flashtool
You will have to install your fastboot drivers in both ways
CMD way
Code:
fastboot -i 0x0fce flash boot kernel.elf
Using Androxyde Flashtool (XPERIA Only)
Download it from here
Install the drivers found at (C:/Flashtool/drivers/Flashtool-drivers.exe)
Press on the thunder button above
Then Choose Fastboot mode
Connect your device in fastboot
After that choose the kernel output (.ELF)
Wanna my help fast ?
Mention me or PM me
8.Additional Tips
*To find the number of cores of your CPU, just open terminal and type the following:
Code:
cd android
cd kernel
cat /proc/cpuinfo
You will find the number of cores of CPU in a tag called "cpu cores" (Great Thanks to @#buzz)
*Some other useful packages from apt-get, especially on newer Qualcomm devices. (Might help you if you want to compile whole AOSP ROMs from source)
Code:
sudo apt-get install liblz4-dev liblz4-tool lzop device-tree-compiler
(Thanks bro @savoca)
Android & GPL
Once you have done your kernel and of course you used some parts from past kernel developers, you will also have to give your sources to other people "This which is called GPL Licence"
So, the best way for this process is "GIthub"
The Rules as they apply on XDA
As XDA has no legal power to uphold the GPL (and frankly we want to stay as far away from doing so as possible), we can’t force any of our users to abide by the GPL. However it is in XDA’s interests as well as the interests of our developer-base to ensure all GPL-derived materials hosted or linked on XDA comply fully with the GPL.
GPL-derived materials that do not come with the complete sources used to compile the GPL components are considered warez, and will be treated as such under forum rule 6 and 9.
If you use GPL components, but do not make any modifications to them whatsoever, you should provide a link to the original source of your GPL code.
Sources accompanying a release should be complete, and contain all the necessary source code for any modules, scripts or definition files. Complete sources will be defined as those which compile correctly and completely against the platform for which the software is distributed, and which contain any and all modifications made to the released General Public Licenced code. The source code supplied should be the exact version for which the source code is being requested, complete with all modifications.
EXAMPLE: Here’s a bit of code that could be used as a template to post your releases
<Kernel Or Author Name> <Kernel Nr>:
<Source>|<ReadMe>|<Credits>|<Other>
The Very Quick Summary of General Public License (GPL)
The text of the GPL Licence itself will be used to reach any final conclusion regarding any disputes over GPL Licenced materials. The above is a summary of what XDA expects of members using GPL code, and the complete text can be read at the GNU website.
The GPL states that anyone who modifies GPL licenced code is required to make available the sources used to compile it. This is to further improve and encourage collaborative work, as well as to ensure that the best code possible is produced, and to encourage peer-review of all work. This benefits both developers and end users in numerous ways, including:
Allowing anyone to verify the code they are trusting with their data, and its authenticity
Encouraging community collaboration to produce faster fixes and updates, and better code
Helping bring new developments from other devices and fields to your own, letting you benefit from new code that wouldn’t have been available without this sharing.
The GPL imparts great freedom for GPL end users. It ensures innovation is never stifled and no project is dependent upon any single developer.
It is in everyone’s interest for the GPL to be adhered to, as it gives us all better ROMs, better transparency, and a better atmosphere for developers to work together to make great code.
Click to expand...
Click to collapse
Credits @TheWizardOfROMs @thewadegeek @DooMLoRD @SatrioDwiPrabowo @Haze028 @abcdjdj
XDA Universty
Good tutorial ! :good::good::good:
DanielFlorin said:
Good tutorial ! :good::good::good:
Click to expand...
Click to collapse
@DanielFlorin
Thanks Bro.
Step 7 just for Sony Xperia Tamsui device like Miro , J , E , Tipo this is different with an other Xperia device so please justify and one more don't re-upload / mirror my files please use original link on my github thanks ....
Truly amazing and descriptive guide. Was thinking about making my own kernel from source just the other day and now this is up!
Nice guide well done:good:
Hi,
Great tutorial. I'm going to try it for my device!
Kernel has more than just I/O, schedulers and governers.
Are you going to expand the tutorial gradually i.e. explain other features? (Would be great if Yes)
Very good . subscribed
Nikhil said:
Hi,
Great tutorial. I'm going to try it for my device!
Kernel has more than just I/O, schedulers and governers.
Are you going to expand the tutorial gradually i.e. explain other features? (Would be great if Yes)
Click to expand...
Click to collapse
Of course bro, but the problem that for now i'm studying but if you need any thing go ahead and message me.
Dilesh Perera said:
Very good . subscribed
Click to expand...
Click to collapse
Thanks very much..... :laugh:
Thanks very much my bro......
Your comment made me really happy ^^
:thumbup:
Sent from my ST26i using XDA Free mobile app
What a coincidence!!
Eliminator79 said:
XDA Universty
Click to expand...
Click to collapse
I don't know whether it a coincidence or not but I have exactly the same wallpaper applied on to my Ubuntu 14.04 x64 bit operating system also with dual boot of Windows 7 Ultimate along side Ubuntu.
Also the second coincidence is, I made the same tutorial on building kernel except for the fact that it is for building linux kernel rather than an android kernel.
Anyway, Good Job! :good:
---------- Post added at 07:13 AM ---------- Previous post was at 07:03 AM ----------
Eliminator79 said:
Code:
make -j<cpucore>"
Replace <cpucore> with the number of cpu cores that the device has if you are on single core write 1 and if you are on dual core write 2
Click to expand...
Click to collapse
To find the number of cores of your CPU, just open terminal and type the following:
Code:
cat /proc/cpuinfo
You will find the number of cores of CPU in a tag called "cpu cores"
Hope that helps.
@Eliminator79 You can add this to your guide.
Eliminator79 said:
3.Installing Libraries and Preparing the Environment
As you know guys there are several libraries needed for any software to be successful so if you want to succeed in compilng you have to get the libraries that i'm going to write through the Linux Terminal
1)Open the Linux Terminal
2)Write these commands
Code:
sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2
Click to expand...
Click to collapse
Some other useful packages from apt-get, especially on newer qcom devices.
Code:
sudo apt-get install liblz4-dev liblz4-tool lzop device-tree-compiler
#buzz said:
To find the number of cores of your CPU, just open terminal and type the following:
Code:
cat /proc/cpuinfo
You will find the number of cores of CPU in a tag called "cpu cores"
Hope that helps.
@Eliminator79 You can add this to your guide.
Click to expand...
Click to collapse
Code:
make -j$(grep -c ^processor /proc/cpuinfo)
^ Works as well, and it's universal.
Wow, I was always curious how people do it. Thanks a lot man.
Nikhil said:
Hi,
Great tutorial. I'm going to try it for my device!
Kernel has more than just I/O, schedulers and governers.
Are you going to expand the tutorial gradually i.e. explain other features? (Would be great if Yes)
Click to expand...
Click to collapse
+1
Thanks a lot!
You got me what I wanted! :victory:
savoca said:
Some other useful packages from apt-get, especially on newer qcom devices.
Code:
sudo apt-get install liblz4-dev liblz4-tool lzop device-tree-compiler
Code:
make -j$(grep -c ^processor /proc/cpuinfo)
^ Works as well, and it's universal.
Click to expand...
Click to collapse
@savoca Thanks so much dude.
Do you give me permisssions to add these tips to the post ?
You motivated me alot bro...Thanks
DarkFalcon said:
Thanks a lot!
You got me what I wanted! :victory:
Click to expand...
Click to collapse
Anytime bro
#buzz said:
I don't know whether it a coincidence or not but I have exactly the same wallpaper applied on to my Ubuntu 14.04 x64 bit operating system also with dual boot of Windows 7 Ultimate along side Ubuntu.
Also the second coincidence is, I made the same tutorial on building kernel except for the fact that it is for building linux kernel rather than an android kernel.
Anyway, Good Job! :good:
---------- Post added at 07:13 AM ---------- Previous post was at 07:03 AM ----------
To find the number of cores of your CPU, just open terminal and type the following:
Code:
cat /proc/cpuinfo
You will find the number of cores of CPU in a tag called "cpu cores"
Hope that helps.
@Eliminator79 You can add this to your guide.
Click to expand...
Click to collapse

[Guide][9/3/2015] Building CM12 for the Nexus 6 Shamu

Building CM12 from source for the Nexus 6 Shamu!
Thanks goes to @scrosler and @GROGG88 and @sykopompos for their amazing guide
[Guide][1/19/2015] Buulding AOSP for the Nexus 6!​
This guide will walk you through, how to build CM12 for the Nexus 6 from source. To complete this, you will need a PC with either virtual box setup and Ubuntu or duel boot Windows and Ubuntu. I recommend duel booting as it gets better results.​
Ideally your PC will need a minimum of an I5 processor and 8GB of ram. I won't go into too much detail on how to setup Ubuntu on your PC. For this guide, you do need to know the basic commands and how to use Ubuntu.
This guide is very similar in process to @scrosler and @GROGG88 and @sykopompos amazing guide here: [Guide][1/19/2015] Building AOSP for the Nexus 6! Through the use of their guide and asking a lot of questions on their thread, I was able to learn how to build AOSP from source. My guide is to complement their guide and show you how to build CM12, I found switching from AOSP to CM12 fairly easy, but there were a few changes in the process.
For my guide I will be using CM12 build guide as reference for the commands. How To Build CyanogenMod Android for Google Nexus 6 ("shamu") Even their guide is not 100% up to date, so I had to make a few changes.
Disclaimer:
I am not responsible for any damage done to your device, thermal nuclear war etc. Please use at your own risk. Your warranty may be affected if you install a custom rom. I am also not responsible if you go over your payment plan when downloading the source code. It is large over 16gb so be careful!
Click to expand...
Click to collapse
So assuming you have Ubuntu 14.* set up, you will need to now set up your build environment:
First on their guide it talks about installing the SDK tools. You do not need these to build the ROM. You only really need ADB commands. I installed fastboot as well.
Install ADB command
Code:
sudo apt-get install android-tools-adb
Install Fastboot command
Code:
sudo apt-get install android-tools-fastboot
Install Java
Code:
sudo apt-get install openjdk-7-jdk
Setting up the build enviroment
Code:
bison build-essential curl flex git gnupg gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop openjdk-6-jdk openjdk-6-jre pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev
If you have a 64bit PC install the following:
Code:
g++-multilib gcc-multilib lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev
Setting your build directory - This can be any folder you want. for my example I will use android as my root folder. Remember that Ubuntu is case sensitive when switching folders.
Code:
mkdir -p ~/bin
mkdir -p ~/android
Install Repo
Code:
curl [URL]https://storage.googleapis.com/git-repo-downloads/repo[/URL] > ~/bin/repo
chmod a+x ~/bin/repo
Put the ~/bin directory in your path of execution - In recent versions of Ubuntu, ~/bin should already be in your PATH. You can check this by opening ~/.profile with a text editor and verifying the following code exists (add it if it is missing):
Code:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
Now for the good bit! We are about to download the source for cm12. Warning: The download is large and will take a long time to download. I have a 38mb fiber connection and unlimited data plan, so it is ok for me to download. I believe the download is 16gb+ in size, so you will have to take this into consideration. Note: I will not be held responsible if you go over your payment plan with your service provider. This is were I have had to start changing the guide a bit as CM's document is for building CM11. It has not been updated to CM12 yet.
Identify Yourself to the Repo
Code:
git config --global user.email "[email protected]"
git config --global user.name "yourpreferredusername"
Initialize the CyanogenMod source repository
Code:
cd ~/android [B]- this is your root folder[/B]
repo init -u [URL]https://github.com/CyanogenMod/android.git[/URL] -b cm-12.0
Download the source code - Note this will take a while, as mentioned it is over 16gb in size. Even with my connection it takes about an hour and a half to download, so time for coffee!
Code:
repo sync
If repo sync errors and stops during download, don't worry you can simply run the command again and it will pick up were it left off. If you get a lot of errors during download, I recommend using
Code:
repo sync -j1
This seems to download the source better. When you have completed the download run it again, to make sure it completes with out any errors. This way you know you have downloaded the full source code.
Backup your home directory
Also at this point, what I do is make a backup using the inbuilt backup software in ubuntu. This backs up my entire home directory to a secondary hard drive I have set up in my PC. This way if I have any issues and need to start from scratch, I can simply delete my android directory, then restore from backup. I then have a fresh working copy and don't have to spend time downloading source from CM12 again. I would also recommend this as part of scrosler's guide as well, when you have finished downloading AOSP source.
Vendor and device specific files
Now this is were the cm12 guide starts to differ a bit from AOSP. AOSP you have to download the vendor files and extract them and then add in missing ones as well. CM12 differs here. At this point I would recommend having CM12 on your Nexus 6. It uses ADB to pull files from your phone and set up the device specific files and the vendor files. I found having CM12 on the phone made life easier at this point. You can use my ROM as an example here: [ROM][5.0.2][CM12 - Android L][LRX22G] Version 1.0.0 - [8/03/2015] - Native LED's
Code:
cd ~/android
source build/envsetup.sh
breakfast shamu
Extract proprietary blobs
Now ensure that your Nexus 6 is connected to your computer via the USB cable and that you are in the ~/android/device/moto/shamu directory, then run the extract-files.sh script
Code:
cd ~/android/device/moto/shamu
./extract-files.sh
Turn on caching to speed up build
You can speed up subsequent builds by adding: the following command to your to your .bashrc file To do this close your terminal window and then reopen and type ./.bashrc - A text editor will open. Add this line to the bottom of the page.
Code:
export USE_CCACHE=1
Close the text editor and save the file
Then in the command window type the following. CM12 recommend 50GB, but you can change to what ever you want.
Code:
prebuilts/misc/linux-x86/ccache/ccache -M 50G
Building CM12!!!!
Now you are all set to start building CM12. You have everything you need. So run the following commands:
Code:
cd ~\android
source build/envsetup.sh
brunch shamu
Thats it! CM12 is now building. This will take some time to build. I do recommend a duel boot PC as it works better than in Virtual Box. Even in my PC it takes about an hour and a half to do a fresh build and about 15 minutes to do a dirty build.
So once the build finishes you now have a flash-able version of CM12 from their latest source that you can flash on your Nexus 6 - Congratulations - you are now among the elite who can build their own ROM from source
The zip file is stored in the following directory:
Code:
cd ~/android/out/target/product/shamu/cm-12-20150308-UNOFFICIAL-shamu.zip
The file name will depend on the day you build the ROM, so it may be slightly different.
Here is an example output of a successful build of CM12!
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
​ Note of caution here:
Now that you have built CM12 as in AOSP I would not recommend flashing at this stage, it will make the following changes to your phone:
Install stock recovery
Encrypt your phone
To get around these we will need to make the following changes. See post 2 on how to make the changes.
As mentioned in post 1, after building CM12 you dont really want to flash it yet. It will:
Install stock recovery
Encrypt your phone - This is optional you can leave it to encrypt, but it is best to give the user the choice to do so or not.
In this post, I will also show you how to make other changes, eg: changing default wallpaper etc. I have a GitHub setup for this and all you need to do, is cherry-pick the commands into your folder, then compile the rom. My main source for all my changes are located here: https://github.com/StephenRJ - you are free to use these changes, but please give credit if you do.
Disable recovery.
Code:
cd ~/android/system/core/rootdir
git init
git fetch https://github.com/StephenRJ/cm12_system_core_rootdir.git
git cherry-pick f413ac907961c07f07f767ceb568deb4881e9f57
This next cherry-pick command will all the user the option of setting encryption on the phone, rather than it being automaticly encrypted.
Disable encryption
Code:
cd ~/android/device/moto/shamu
git init
git fetch https://github.com/StephenRJ/cm12_device_moto_shamu.git
git cherry-pick 7459b0d54102fbee27f363e7612b83f614a0f8c4
Now you have both of these disabled, you will need to do a fresh build again. To do this, I simply delete the out folder. Open file manager and go to android - then delete the folder out. This will let you make a full build again.
Close your terminal window and reopen.
Start a fresh build
Code:
cd ~/android
source build/envsetup.sh
brunch shamu
Now you can flash CM12 on your Nexus 6 Shamu Congratulations!!!!!
I will continue to add more fixes here has I find them.
Here are a couple of video tutorials I have found on setting up a basic Ubuntu enviroment.
Virtual Box: https://www.virtualbox.org/wiki/Downloads
Ubuntu ISO: http://www.ubuntu.com/download/desktop
Tutorial on setting up Virtual box on Windows 7 / 8
Duel boot Windows 8 and Ubuntu - Prefered method
Disclaimer
I am not responsable for anything that happens to your PC during the install of Ubuntu. I recommend taking a full backup first before installing a second operating system. Do this at your own risk. If your are not sure about installing different oprating systems, use the first method as it is safer
Click to expand...
Click to collapse
Change Log
Version 1.0.0
- Initial release
Please feel free to share here and help each other. I hope this guide is as useful to users as scrosler's has been. With out his help and guide, I would have never have been able to learn how to build AOSP for this amazing phone. I hope this guide gives more users the chance to build CM12 as well.
Using this guide, I have built and released a ROM. Please have a look here: [ROM][5.0.2][CM12 - Android L][LRX22G] Version 1.0.0 - [8/03/2015] - Native LED's
Please feel free to try it and report back!
I would suggest using a local manifest and getting your vendor files from TheMuppets repo. That way you stay up to date on any changes that are made.
Thanks for the tip. Could you explain a bit more on how to do that? I had installed an existing stock CM12 rom on the phone and then used the commands to remotely pull the files from it.
Stephen said:
Thanks for the tip. Could you explain a bit more on how to do that? I had installed an existing stock CM12 rom on the phone and then used the commands to remotely pull the files from it.
Click to expand...
Click to collapse
CM's wiki has a pretty good guide.
http://wiki.cyanogenmod.org/w/Doc:_Using_manifests#The_local_manifest
Also, not sure the recovery thing mentioned is an issue. I've been building CM for this device for nearly 2 months and have had no issues with TWRP being replaced.
Excellent guide! Now I just need a Nexus 6... :silly:
I love seeing useful tutorials being posted. That's why I got involved in @scrosler's thread. Nice job!!
akellar said:
Also, not sure the recovery thing mentioned is an issue. I've been building CM for this device for nearly 2 months and have had no issues with TWRP being replaced.
Click to expand...
Click to collapse
Agreed. I was just about to post that too. Most custom ROMs remove the stock recovery so custom recoveries don't get overwritten.
Very cool ill try this tomorrow! Can you maybe add a section on how to find and add nice cherrypicks?
Regarding the recovery I added that in on the safe side. I know if you download the full stock cm12 from their website it does change the recovery and encrypt the device.
I will be adding a few more cherry picks at some stage, I am working on something rather cool at the minute.
Thanks for doing this. I've followed a few guides but every one wasn't quite correct. I can't wait to test this out soon.
- Aaron
Very well done Stephen! I read as many of these as I can and always learn something new. This is very well written and I hope all of us can add and help each other as we progress with the N6!:good:
Hey,
I have built AOSP for Nexus devices for a long time, but have yet to run into this issue.
When I run "brunch shamu", it fails, referancing generic "goldfish"? is that just a generic device name?
Here is the build process:
[email protected]:~/android$ source build/envsetup.sh
including device/moto/shamu/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-mips/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including vendor/cm/vendorsetup.sh
including sdk/bash_completion/adb.bash
including vendor/cm/bash_completion/git.bash
including vendor/cm/bash_completion/repo.bash
[email protected]:~/android$ brunch shamu
including vendor/cm/vendorsetup.sh
Looking for dependencies
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.0.2
CM_VERSION=12-20150315-UNOFFICIAL-shamu
TARGET_PRODUCT=cm_shamu
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=krait
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.16.0-31-generic-x86_64-with-Ubuntu-14.10-utopic
HOST_BUILD_TYPE=release
BUILD_ID=LRX22G
OUT_DIR=/home/npjohnson/android/out
============================================
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.0.2
CM_VERSION=12-20150315-UNOFFICIAL-shamu
TARGET_PRODUCT=cm_shamu
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=krait
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.16.0-31-generic-x86_64-with-Ubuntu-14.10-utopic
HOST_BUILD_TYPE=release
BUILD_ID=LRX22G
OUT_DIR=/home/npjohnson/android/out
============================================
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
"ebtables is disabled on this build"
find: `dummy': No such file or directory
build/core/base_rules.mk:154: *** system/device/generic/goldfish/audio: MODULE.TARGET.SHARED_LIBRARIES.audio.primary.goldfish already defined by device/generic/goldfish/audio. Stop.
Not sure, haven't seen that error before. Have you added any extra mods into the rom? One of those could be causing the issue. It could also be an issue with CM12 its self. Some times they do add code in and it can cause errors.
I would try downloading source again and see if there is any difference.
Stephen said:
Not sure, haven't seen that error before. Have you added any extra mods into the rom? One of those could be causing the issue. It could also be an issue with CM12 its self. Some times they do add code in and it can cause errors.
I would try downloading source again and see if there is any difference.
Click to expand...
Click to collapse
Will do. I am building on Ubuntu 14.10. That should be OK to use correct? Fresh install, then followed steps in the OP.
npjohnson said:
Will do. I am building on Ubuntu 14.10. That should be OK to use correct? Fresh install, then followed steps in the OP.
Click to expand...
Click to collapse
Yes. Oh what setup are you using. Virtual Box or duel boot. I did have problems with Virtual box and switched to duel boot. Found it to be more stable.
Stephen said:
Yes. Oh what setup are you using. Virtual Box or duel boot. I did have problems with Virtual box and switched to duel boot. Found it to be more stable.
Click to expand...
Click to collapse
Dual boot.
Any idea why my builds come in at around 387MB but the official nightlies are ~443MB?

Guide - Introduction to Rom building/development

Hello everyone.
I’ve decided to build this tutorial in order to assist all developers and builders into the ROM and kernel development. I’ve felt motivating into writing this small post because I feel that the current information available is confusing and also do not provide the set of skills and information to help someone in the first steps.
This tutorial will be divided on:
The Machine Configuration
The tools of development
The Source
Hardware
Software
What to do to be able to Innovate
The Machine Configuration
In order to have a good machine configuration you should select your distro based on the packages which are provided to developers. In my opinion the best distros are Fedora and Ubuntu. It is important to learn a bit how Linux works in order to fully understand what we are editing as Android is nothing more than equivalent Linux system where you run java on a virtual machine. In other words, you’ll understand with time that many parts which are used on Linux Operating system it is also used on Android Operating System (example: bionic, kernel libs).
After you installed your Linux system you’ll need to prepare your machine for building. For that you’ll need to install the following packages:
Code:
sudo apt-get install git ccache automake lzop bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 g++-multilib python-networkx libxml2-utils bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev squashfs-tools pngcrush schedtool dpkg-dev liblz4-tool make optipng maven
sudo apt-get install openjdk-7-jdk
Code:
sudo apt-get install android androidsdk-uiautomatorviewer android-copyright android-src-vendor android-emulator android-tools-adb android-headers android-tools-adbd androidsdk-ddms android-tools-fastboot androidsdk-hierarchyviewer android-tools-fsutils androidsdk-traceview
After you have the basic packages installed we are going to add the repo instructions to you git in your machine. Basically this will interpret the source information when you are syncing new code from google repos and we’ll add to the folder /bin/repo.
To do that we’ll run.
Code:
[B]mkdir -p ~/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo[/B]
And run the /.profile. Basically this command will reload information of the new settings for your profile, where it’ll read the folder ~/bin/repo information for all situations. In the future only makes sense to load again in case you have added a new repo instruction.
Code:
[B]. ~/.profile[/B]
Now we are going to sync the source code. I’ll use here as an example CyanogenMod as I believe to be the easiest for anyone which is starting. Lets imagine we are going to put all the source on a folder named cm, you’ll have to just run the following commands.
Code:
[B]mkdir ~/cm
cd ~/cm
repo init -u git://github.com/CyanogenMod/android.git -b cm-13.0[/B]
So in order to explain what we’ve done here by steps. The repo init –u basically is a command instructing to go to the GitHub on that specific location and extract what is available on the cm-13.0 branch regarding to manifests. So basically it’ll automatically push the file which has all CyanogenMod source to .repo/ folder with the name manifest.xml
After you have loaded this command you’ll run the repo sync , basically this command consists on downloading all the code into your building folder (in this case cm folder).
After the repo sync is complete you’ll have interest on having a local_manifests. Basically on this local_manifests.xml , where some developers prefer to name it as roomservice.xml it is where you’ll add the changes to the manifest.xml or even sources which you wish to add to your building folder. This is a solution to you never edit the manifest.xml.
Usually it is added on the local_manifests the folders related to your device tree. I’ll give in this example how to build for the OnePlus One (bacon).
A device tree consists on configurations where you set information related to your device. Example if is qualcom, usually is android_device_qcom_common (where is the general settings) together with android_device_oneplus_bacon (where are the specific settings). When I say settings, for you to understand is like compile with the folder hardware/qcom/display for the display. You should take some time to explore to understand what is in it.
So you’ll add your local_manifests.xml this way.
Code:
[B]
mkdir .repo/local_manifests
nano .repo/local_manifests/local_manifests.xm[/B]l
You now add:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<project name="CyanogenMod/android_device_oneplus_bacon" path="device/oneplus/bacon" remote="github" revision="cm-13.0" />
<project name="CyanogenMod/android_device_oppo_common" revision="cm-13.0" remote="github" path="device/oppo/common"/>
<project name="CyanogenMod/android_device_qcom_common" path="device/qcom/common" remote="github" revision="cm-13.0" />
<project name="CyanogenMod/android_kernel_oneplus_msm8974" path="kernel/oneplus/msm8974" remote="github" revision="cm-13.0" />
<project name="TheMuppets/proprietary_vendor_oneplus" path="vendor/oneplus" remote="github" revision="cm-13.0" />
</manifest>
Now you need to run the repo sync command again.
This has to do separately the first time or it won’t sync all the files you need. In case the repo sync fails with an error saying you need to do –force-sync just run repo sync –force-sync (this happens only when you change common git sources with your manifest.
After the sync is done you are ready to build!
To start building you’ll need to run the .envsetup.sh , which will load all the source code into memory. After that breakfast bacon userdebug (in case it is for the OnePlus One device), then later make bacon (the word bacon it is to be used on all devices , here it is just a coincidence with OnePlus One)
Code:
[B]. build/envsetup.sh
breakfast bacon
make bacon[/B]
After it compiled your rom will be located at /cm/out/target/product/bacon/
Easy until here? I hope so.
Possible errors :
Q: Receive error: fatal: duplicate path xxx/xxx in ~/cm/.repo/manifest.xml
A: edit .repo/local_manifests/local_manifests.xml to remove the item which matches the item located in bold.
Q: How big is the repo?
A: 50GB just source code and around 10GB when built per device. Therefore you should aim to have about 60GB free on your system.
The tools of development
Git
Probably many of you question about what it is git, read about it on the github manuals etc and still cannot figure out how to work (I took two weeks to understand that it is really simple). So imagine that you have a diary, but instead of being separated by dates it is separated by titles, which we call commits. And what is a commit? Basically it is a portion of code. So when you make a change and want to record that change, you create a commit and in the end it’ll be a portion of code. This portion of code, known as commit, can be easily ported between different sources.
Here is an example:
https://github.com/jgcaaprom/androi...mmit/9f16b3cd79ad7bb8c821a518ca73725f19c38478
The commit number is: 9f16b3cd79ad7bb8c821a518ca73725f19c38478
This commit has recorded a change of IZAT_DEBUG_LEVEL = 2 .
Now how to bring other commits from different sources into our source.
The process comes in 3 phases:
First we’ll have to add the source where the commits that interests us are with git add source_name link
Second we’ll download that source by using git fetch source command
Thirdly we’ll cherry-pick (bring the portion of code recorded in the commit) into our source in order to make the changes automatically.
So lets see a real scenario. Imagin you are interested on cherry-picking this source:
https://github.com/CyanogenMod/android_device_oneplus_bacon
What you’ll have to do is.
Step one: git add cm https://github.com/CyanogenMod/android_device_oneplus_bacon.git
Step two: git fetch cm
Step three: (imagine this is the commit you want:
https://github.com/CyanogenMod/andr...mmit/58027fcbea4dd9fbb5aaeb8ae5f6e32bdf613573 )
The commit number is: 58027fcbea4dd9fbb5aaeb8ae5f6e32bdf613573
So you’ll git cherry-pick 58027fcbea4dd9fbb5aaeb8ae5f6e32bdf613573
And voila! You’ve done your cherry-pick . Now it is important to have in mind how the cherry-pick process works which I’ll explain on the next step.
Cherry-picking
Cherry-picking is a process of importing code from one source to another. So the process that git does basically is, compares your present files in the source with the files that was on the source you are cherry-picking and if everything is a match it’ll change the code automatically for you.
Now lets pick up the example above and imagine that the changes you are doing instead of being exactly the same as described here:
https://github.com/CyanogenMod/andr...mmit/58027fcbea4dd9fbb5aaeb8ae5f6e32bdf613573
Your source has a difference which doesn’t have this line:
32 private static String CONTROL_PATH = "/proc/touchpanel/keypad_enable";
You’ll notice that it’ll give a conflict. The reason for that is because the git when comparing understood that there was no match between the sources. When that happens means basically that there might be changes you should do in order for the code to be compatible, so you’ll have to review that code.
Now the review process is very simple. For you to see which files are in conflict you’ll have to run git status ( basically this command informs you of the situation of the commits which are being cherry-picked and the changes which you’ve done. )
You’ll notice that the files which need to be edited/review are in red. In case it appears files in green, means that there was a perfect match and doesn’t need a review.
Pretty useful right?
After you finish editing all the code you’ll do git add . and for this exercise do git status again just for you to see what happened . Everything is green. To finish the cherry-pick you’ll now do git commit and done!
How to record my own changes and create a commit with it.
Basically this process is exatly the same as the previous one, the only difference is that after you made the changes, you can make git status, then git add filename in case you want to commit only one file or git add . in case you wish to commit all the files and to record the commit you write git commit, or git commit –m “commit message”.
Congratulations! You’ve just recorded your commit!
Git push/pull
There will be moments where we just wish that we could be lazy and cherry-pick everything all at once. Well there are some scenarios where you can actually do that, but remember it is not perfect. Lets imagine we are using the source above, and CyanogenMod uploaded like 20 different commits, your source is not exactly like CM source but you wish to keep your changes and also have all changes from CM what to do?
1) You can cherry-pick one on one. And waste a lot of time…
2) You can make a new source based on cm and include your changes there
3) You can git pull
Git pull basically will update your source with CM source by merging all the commits. You do that with:
git pull cm cm-13.0 (in case your rom is Marshmallow)
The git pull should only be used when the sources are very similar and you are using as a base. Basically it’ll warn you that’ll merge the code and voila done! 20 commits added to the source.
Now when on the situation that the sources are slight different or very different it’ll create a conflict. Again the git will do comparisons between the entire sources, check which commits are missing, compare the files just like with cherry-picking. And when you do git status, it’ll appear on red all files where you need to review your code.
After you finish, same as before
Code:
[B]git add .
git commit[/B]
Done.
I hope you are understanding everything until here.
git reset HEAD~n
This command is rarely used but is super usefull. Basically you are saying to git that you with to remove n commits you've reated/cherry-picked. For you guys to understand how it works, basically imagin you have just written/cherry-picked 10 commits, and you do git reset HEAD~3 , he'll basically remove from records 3 commits. But... That doesn't mean he reverted the code! In case you wish reset the code you need to do git reset --hard.
Also it is very usefull to help rewrite the history. Lets think the example I given before. When you do a git reset HEAD~3 , basically on a history of A B C D E F G H I J commits, the git will remove only the recorded commits H I J. If you do after a git status, you'll understand that the code is still there, which means the changes you done on H I J will still be there. So you can create a new commit with H I J all together . Simple!
Another way to create a unique commit with H I J is by using git rebase -i HEAD~3 , where you basically are instructing the git that you wish to rebase the source with an interactive selection. You'll see that it'll appear a commit list where you can remove other commits from history. But since you wish to create a unique commit you'll wish to change the instruction from pick with the letter s (without capslock term for squash) . Example:
Code:
[B]pick d0c49f4 UsbDeviceManager: Remove charging from persisted function composition
s 2c755a6 SystemUI: fix NFC tile sometimes hiding
s e39d1d7 Revert "base: start nfc service prior to systemui"
pick 9164274 DocumentsUI : Hide advanced menu option when in forced mode
pick 5f8d3f8 Themes: Expose Power Dialogs
pick 9153396 SysUI: Don't let rogue themes ruin notifications
pick 226797c Revert "Only show keyguard panel if on lockscreen + no activity on top"
pick e843aaf Fix NPE in DocumentsUI when rotate UI before format as internal
pick 26079d3 SystemUI: detect rotation and resize mKeyguardBlur accordingly
pick 80b060d Automatic translation import
pick 4282864 Automatic translation import
pick d442df6 wifi: Enable WiFi IpReachabilityMonitor by default
pick 9cf937f SystemUI: Add margin in qs_tile_top between instruction text and add button[/B]
Cool right?
And I believe I've covered with some examples the git. As you can see, once you get used to git you'll be able to use it easily.
Toolchains
There has been a big debate from many developers on which toolchains to use. Many prefer sabermod, others prefer uber, others google toolchain, etc. It is in fact debatable. If you ask me which one to use, I would say google or uber (very similer to google) and the gcc used by stock on the source. The reason is simple, the code is optimized for a certain gcc version, if you start using a gcc version which is not prepared to be used on the code, it won't translate correctly your instruction.
The source
When you start building roms, you should at least know a little about how the source of android is organized, what language it is used, etc. On android it is used C, C++, Java, Assembly. Withing the following folders inside the source it is used:
Java
Frameworks
Packages
external (some packages)
C++
ART
bionic
hardware
C
kernel
hardware
Assembly
bionic
some of the kernel libs
This is important for you to navigate easily within it. Some of you ask yourselfs what is one thing or another. I'll represent that to the following image which is published on the google developers page.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Now I believe you wish to know which parts should be used in order to put a rom working for a certain device. Those parts are:
Hardware
Kernel
device tree
Vendor blobs
These parts are the "base" of your build to put a certain device in a working, since on these parts is where lies the instructions for the device to understand what to do.
The build folder is where you specify instructions of the building process. For example : Certain optimization, which GCC to use, where will the compiler find the apps to compile.
frameworks, system, packages and some of the folders within the external folder are the packages of what you will have inside the rom which is general and can be present on any rom.
external folder has present different things, compilers such as proguard, jemalloc. external software used by the rom such as sqlite.
prebuilts folder has present everything related to stuff which is already compiled, in this case clang, gcc toolchains.
I've done a very summarize version of the source in order for you to understand how that google built things, so I hope it is simple to understand these basics.
(to continue)
reserve1
reserve2
reserve3
Another great contribution bro. Thanks for your work and for your help. Starting read right now
Edit: Amazing guide
Just one request, please bold when you write a command. I think it becomes more eligible.
@jgcaap I think this is useful
For those already have JDK8 installed, they can use it by adding this code to $HOME/.bashrc
Code:
EXPERIMENTAL_USE_JAVA8=true
You just have to source ~/.bashrc before make bacon
There's nothing better than learning something from a professional who you know has done such a great work. Thanks a million!! @jgcaap
Very useful.. Thanks for sharing =D>
Sent from my A0001 using XDA-Developers mobile app
FSadino said:
@jgcaap I think this is useful
For those already have JDK8 installed, they can use it by adding this code to $HOME/.bashrc
Code:
EXPERIMENTAL_USE_JAVA8=true
You just have to source ~/.bashrc before make bacon
Click to expand...
Click to collapse
I'll speak about different custom GCC and also other compilers, but it'll be on another section. I'll continue writing this on wednesday (exam tomorow). I believe that my guide will help understand all the basics.
If I speak about that mode, I believe it'll give the idea that it is a feature of linux and it isn't. It is something you can change inside the source in many different ways.
jgcaap said:
I'll speak about different custom GCC and also other compilers, but it'll be on another section. I'll continue writing this on wednesday (exam tomorow). I believe that my guide will help understand all the basics.
If I speak about that mode, I believe it'll give the idea that it is a feature of linux and it isn't. It is something you can change inside the source in many different ways.
Click to expand...
Click to collapse
This might sound a little stupid but which JDK version is recommended? 7 or 8? Seems like 7 cause you have to enable "Experimental Use" for 8.
Great guide! Can you, if you have time, also post a guide only focusing on kernel building?
abhibnl said:
Great guide! Can you, if you have time, also post a guide only focusing on kernel building?
Click to expand...
Click to collapse
The guide is incomplete, will write more on wednesday. I'll cover everything in a very simple waywith praticle solutions.
thank you , that what was looking to develop on my tablet , I can use basic as this tutorial for other devices.
continue with tutorial , as many want to learn, but has no simple guide to base
you must wrote revision="cm-13.0" /> instead of revision=”cm-13.0” /> 'cause it give you an error that you can't be able to repo sync
fafa77140 said:
you must wrote revision="cm-13.0" /> instead of revision=”cm-13.0” /> 'cause it give you an error that you can't be able to repo sync
Click to expand...
Click to collapse
i literally stared at this for like 1h and didn't find any difference could you please elaborate more...
baconxda said:
i literally stared at this for like 1h and didn't find any difference could you please elaborate more...
Click to expand...
Click to collapse
The quotation marks surrounding cm-13.0 in first post are not the right ones. So you need to replace those quotation marks if you copied and pasted the code in your manifest. Just delete the quotation marks and type them again.
joshuous said:
The quotation marks surrounding cm-13.0 in first post are not the right ones. So you need to replace those quotation marks if you copied and pasted the code in your manifest. Just delete the quotation marks and type them again.
Click to expand...
Click to collapse
ohhhkayyy.........:good:
fafa77140 said:
you must wrote revision="cm-13.0" /> instead of revision=”cm-13.0” /> 'cause it give you an error that you can't be able to repo sync
Click to expand...
Click to collapse
good catch. I never thought the keyboard would be writting differently when not on the terminal. Thanks
jgcaap said:
good catch. I never thought the keyboard would be writting differently when not on the terminal. Thanks
Click to expand...
Click to collapse
No problems
fafa77140 said:
No problems
Click to expand...
Click to collapse
updated more stuff today.

[GUIDE][2018]All you need to know to build Android from scratch!

Introduction​So, I will start off by telling a little bit about myself. I got interested in Android building in November 2017. I found most of the guides "inadequate" for pure newbies like me.
This is my second guide and the first one for No-Knowledge newbies so please do correct me . I will also add some humor so you don't get bored
The guide will be divided into a few parts-
Using linux and enjoying it(No offense to GNU/Linux enthusiasts. please don't start a debate, its just my personal opinion)
Basic git for complete newbies
Compiling your first ROM(Lineage)
Compiling your first non-Lineage ROM
Choosing a Programming lanugage
Basics to resolving conflicts
Compiling AOSP-based roms for CAF devices(For which I couldn't find a guide)
It will probably take a while for you to read this but its must to read everything carefully. Lets start off right away
Using Linux and Enjoying it!
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
There are more than adequate guides for using Linux. I will just help you choose the distro and recommend some guides
Personally, I used Linux wayyyy before I started building android(~2013) I didn't do much at first so I got most of my Linux experience in 2016-2018
Some distros I recommend-
Ubuntu 16.04 or 18.04 (Probably the best for newbies imo) - https://www.ubuntu.com/download/desktop
Arch Linux(Could be problematic to install for newbies so I recommend you install Antergos first - https://Antergos.com/try-it/ )
Linux Mint - https://linuxmint.com/download.php (Newbie friendly)
Debian GNU/Linux (Easier than Arch imo, slightly(very slightly) harder than Ubuntu) - https://www.debian.org/
You absolutely MUST live boot them and feel them. I highly recommend you to install them on a small partition(~40GB) to get the best experience. Please don't use linux on a server at first!
I personally started with Ubuntu 12.04 for a month or so, 14.04 as well for a few months. I became a daily user when 16.04 came out.
Currently, I am using Antergos. However, for building I liked Arch as it had everything "bleeding edge"(Search it if you don't know what this means xD)
Here are some absolutely noob friendly guides-
https://www.youtube.com/watch?v=opBKvGi77cU
For Ubuntu (Long guide but indepth!)
https://www.youtube.com/watch?v=G0AFuhVSvEk
For Linux Mint (Again, Long but indepth!)
Use them for atleast a week or two before you even jump into android building! A month of daily usage is recommended so you know how to tackle basic problems. Youtube will always be your friend and so will be google. You can't hate Linux once you know how to use it! The only reason why I use Windows is because of gaming and applications such as Photoshop and Illustrator(I know there are alternatives, again just my personal opinion!)
See you after a week! No? Seriously use linux for atleast a week!
Using Linux will also hone your google skills(Not even kidding)
Basic git for complete newbies
Personally, I myself don't do advanced stuff with git myself and here are the subcommands you will be using the most with git -
clone
cherry-pick
revert
merge
commit
push
I will give a brief explanation of each and link some guides! Why brief? Because I expect you to have a thinking like a linux user now . Also, you can switch to a server now!
Here is a playlist by github -
https://www.youtube.com/watch?v=noZnOSpcjYY&list=PLg7s6cbtAD15G8lNyoaYDuKZSKyJrgwB-
If you are not satisfied(I wasn't) you can search youtube for a specifc command as well! (i.e cherry-pick)
clone -
Simply clones the repository including its commit history!
Usage-
Code:
git clone <repo> -b <branch> <directory>
If you don't specify a branch, it will clone from the default branch.
If you don't specify a directory, it will make a folder with the name of the repo
Example -
Code:
git clone https://github.com/ChimeraKernelProject/chimera_land-current -b lineage-16.0 chimera
(Shameless self advertising xD)
cherry-pick-
Generates a diff from a commit and applies it to the local repo
Usage-
Code:
git cherry-pick sha
You do need to fetch the repository from which you are picking a commit
Using-
Code:
git fetch <repo> <branch>
If the branch isn't specified, it fetches the default branch instead
Cherry-picking multiple commits-
Code:
git cherry-pick sha1^..sha2
This picks all the commits from sha1 to sha2(i.e the commits between sha1 and sha2, including sha1 and sha2)
You may or may not get a conflict for which I will have a seperate section.
Example-
Code:
git fetch https://github.com/ChimeraKernelProject/chimera_land-current lineage-16.0
git cherry-pick 9e8a821ba64f5b498843b025d1804e3818dda480^..8e80e52915492328e80378f7ecff0cb44fdc1344
(Try figuring out what I did )
What is SHA you ask? You don't have to know what it actually is so just consider it to be an identifier for a commit.
revert
Generates a diff of the commit and reverses it(pretty much the opposite of cherry-pick)
The usage is same as cherry-pick.
merge
Kind of like cherry-picking multiple commits but it compares the history of the local and the remote and then generates a common diff for the commits that are not in local
Also, you do need to fetch before merging.
Usage-
Code:
git merge <remote>
Example-
Code:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git v3.18.125
git merge FETCH_HEAD
(The example here is of upstreaming the kernel )
commit and push
Generates a commit for staged files
Usage-
Code:
git commit -m "some message" -m "sub-message"
some optional parameters-
--signoff
--author="name <author email>
If you forgot to add a file to the commit, you can -
Code:
git commit --ammend
Again, you can use the optional parameter.
how to stage files you ask?
you simply use-
Code:
git add <filepath>
If you did your linux lessons correctly, you might know that, you can use "." and ".." in filepath(redo them if you don't know xD)
finally, to "push" your changes to a remote repo-
Code:
git push -u <repolink>
It will ask for authentication. You use your github(or whatever you prefer) account for that.
After using -u once, you won't have to pass the parameter again.
Lets end this with an example-
Code:
git add .
git commit -m "add 69 hour battery life" -m "best" --signoff --author="someone <[email protected]>"
git push -u https://github.com/ChimeraKernelProject/chimera_land-current
(Also please don't use a stupid commit message like the one I showed xD. This one was just for the lulz)
This one was big. oof. Took me a while to write and probably will take a while for you to read too .
You might ask why did I tell you to search xyz in this one so much! Simple reason- I want you to get used to searching your problems!
Mastering git takes alot of time! I am not any good myself and I search alot of stuff on google myself! (Sometimes even problems related to merging and checking out!)
Compiling your first ROM(LineageOS)
I bet you have been getting restless by now! The previous guides were to build the excitement to build your first ROM!
Why Lineage? Simple. Its one of the easiest ROM to build. Pretty well documented and most importantly, alot of video guides to check if you are confused at any point!
It is highly recommended to use a server at this point as you will be pulling alot of data and you will require alot of processing power.
You can build locally if you have good internet.
Here are the minimum requirements(imo)-
i3 6100 or equivalent
8 GB RAM
300GB HDD(500 GB+ is highly recommended)
Lets start off by the dependencies. I am assuming you are on Ubuntu or Linux Mint. These are the dependencies you need to install -
Code:
openjdk-8-jdk
git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc unzip
You know how to install them don't you now
Lets install Repo now-
Code:
mkdir ~/bin
edit your .bashrc in the home directory with your preffered file editor(I use nano) and add this line to the bottom (Hint - hold pgdwn to jump to the bottom quickly)-
Code:
PATH=~/bin:$PATH
Then execute these commands-
Code:
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
Code:
chmod a+x ~/bin/repo
Lets sync Lineage now shall we
First add your github account to the git config using-
Code:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Here, you should use your github email! (See https://help.github.com/articles/about-commit-email-addresses/ if you don't want to use personal email)
Make a dir in which you will do the rom stuff and cd to it
Before we initialize and sync LineageOS, you have to decide which branch you are choosing as well
You can check your device forum and see what Android versions does the device have. PS- You might wanna check the LineageOS thread. The developer must have provided a link to their kernel source(If they didn't, report the thread to mods kek). Click and navigate through their github. you will find a repo named- android_device_(vendor)_(devicecodename) . you probably know the vendor and the codename from the forum don't you?For example its- android_device_xiaomi_land for my device(Yea right I have an old as hecc device pls no laugh ). Check the branch of the ROM. It will probably something like lineage-16.0 or 15.1 etc. Also if you have an official device, you can check its branch at- https://github.com/LineageOS .
Welp now you know the branch, lets start!
Code:
repo init -u git://github.com/LineageOS/android.git -b <branch>
repo sync
To sync a little bit faster, here's a better command I got from StatiXOS git -
Code:
repo sync -c -f --force-sync --no-tag --no-clone-bundle -j$(nproc --all) --optimized-fetch --prune
Also, if your sync stopped midway because of your ISP(BSNL :'( ), you can just start the sync again.
If you are on another distro such as arch, you might have to do some extra steps- https://wiki.archlinux.org/index.php/android#Building
Now that you have synced, You may choose one of the 2 paths-
If you have official LineageOS, choose me!
Setup the environmental Variables with-
Code:
source bu*/e*
Clone your vendor blobs from TheMuppets repo - http://github.com/TheMuppets
or, from your preferred developer.
The usual repo name is proprietary_vendor_(vendorname). For example, in my case its proprietary_vendor_xiaomi . It should have a folder with your device codename
If not, try changing the branch!
You should be cloning them to vendor/(vendorname)
start bulding right away with-
Code:
brunch lineage_<codename>-<buildtype>
here, codename is your device codename and buildtype is one of these-
user, userdebug, eng .
I recommend userdebug at first. user builds are pretty much as limited as your stock rom. eng builds are actually the one you should use for debugging the rom. These are not secure for daily usage.
This will start the build and you probably won't get an error as its official. If you do, you can just search it up on google. Once the build is done, you will get filepath in the command output. Generally, the build is in
<workingdir>/out/target/product/<codename>/xyz-UNOFFICIAL.zip .
If you have unofficial Lineage, choose me!
I am assuming you are in the working directory
Welp, lets start off by searching for the required trees.
Here's what you need-
Device Tree
Kernel Source
Vendor Blobs
Usually I find them by checking the post of the unofficial Lineage thread and click the kernel source link(Again, if they didn't post it, you should report the thread ). Go to the dev's profile and check his repositories. Here are the usual naming schemes for each one of them-
Device tree - android_device_(vendorname)_(devicecodename)
Kernel Source - android_kernel_(vendorname)_(devicecodename) or! android_kernel_(vendorname)_(soccodename)
Vendor Blobs - proprietary_vendor_(vendorname) or, proprietary_vendor_(vendorname)_(devicecodename)
Device tree should be obvious. It should be cloned to - device/(vendorname)/(devicecodename)
As for kernel tree, soccodename menas the codename of the SoC you have in the device. The thread should have it already as the kernel is licensed in GPL v2(GNU Public License V2, for more info check - https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html ). To know where you need to clone the kernel tree, check the "BoardConfig.mk" of your Device tree and check the "TARGET_KERNEL_SOURCE" line. It tells where you need to clone the kernel
vendor name should be obvious as well now. If your vendor name doesn't have the codename, it should be cloned to vendor/<vendorname>
if it has the devicecodename, it may or may not be the device tree and still be like this-
If it doesn't look like this, it should be cloned to vendor/<vendorname>/<devicecodename>
Here's the repo list of an ideal dev-
Setup environmental variables-
Code:
source bu*/e*
Start the build! -
Code:
brunch lineage_<codename>-<buildtype>
here, codename is your device codename and buildtype is one of these-
user, userdebug, eng .
I recommend userdebug at first. user builds are pretty much as limited as your stock rom. eng builds are actually the one you should use for debugging the rom. These are not secure for daily usage.
Now since you are using an unofficial tree, it is likely that you might hit an error. One of the most common error is when brunch is unable to find your target device. a simple fix for that is to navigate to your device tree and make a file called "vendorsetup.sh"
It should have this line in it-
Code:
add_lunch_combo lineage_<codename>-userdebug
where(you guessed it), codename is your device codename. Run the environmental variable setup again and you should be ready to build.
You might hit errors. Google is always your friend. If you are absolutely sure that you can't find it on google, check the help group section in the thread!
Once the ROM is ready, you will find the filepath in the command ouput. Generally its in out/target/product/<codename>/xyz-UNOFFICIAL.zip
Uploading files to google drive
There's a really nice guide availabe here- http://olivermarshall.net/how-to-upload-a-file-to-google-drive-from-the-command-line
Congratulations! You just made your first rom. If you find this hard, this is just the beginning! There's a very rough road ahead.
Compiling your first Non-Lineage ROM
PS. - The ROM has to be "Lineage-based".
thee aren't eft f'r aosp bas'd roms!
I will be using XenonHD as an example as it is pretty easy to build and it was pretty much one of the first roms i ever built.
Building a Lineage-based rom is as easy as building Lineage!
You go to the rom's git(I usually google search or check it in one of the rom's thread for any device) and check the repo manifest. The usual naming scheme for a repo is-
android_manifest
platform_manifest
manifest
android
etc.
In xenonHD's case, its platform_manifest(and all other repo names will start with platform prefix)
A proper ROM source should have the syncing instructions and building instructions. Lets check the XenonHD's example
make a working dir for the rom in which you will do your rom stuff.
Initialize and sync it. The initializing and syncing part is always the same across the ROMs. (You know which branch to use now. Don't you?)
Again, clone all the required trees!
Now now now, don't get excited yet! Before you start brunching, there is some stuff you need to change.
Usually you can refer to one of the official trees in the ROM organization. For example, https://github.com/TeamHorizon/android_device_xiaomi_kenzo has proper commits. You should be looking at the "Initial XenonHD" commit. You can obviously ignore commits like https://github.com/TeamHorizon/andr...mmit/c076f8c7199d0cddbe6a1e0d05bf3ffc63080d1d as they are device specific. The basics are always the same-
Rename lineage.mk to (romname).mk . refer to the device tree if you are unsure about the romname
edit the (romname).mk and change all the lineage instances to (romname). refer to the commit if unsure.
rename lineage.dependencies to (romname).dependencies .
Renaming the kernel defconfig isn't really necessary so you can ignore that.
Setup the environmental variables(Same across all the roms)-
Code:
source bu*/e*
start the build using the supported command given by the ROM devs.
Code:
brunch codename-<buildtype>
in XenonHD's case. However its different across most of the roms so never forget to read manifests!
You are more likely to hit errors with these spinoffs. Google is your friend(I can't remember how many times I have repeated this) and so is LineageOS repo! You have alot of references if the error is not device specific. Learn to fix derps! Check the help groups sections and ask if its absolutely necessary! Again, the command output will have the filepath of the final ROM zip!
You aren't ready yet. You need to gain alot more experience in compiling ROMs and here are some ROMs that you should be able to build at this point- Resurrection Remix, DotOS etc. Most of the lineage based roms support brunch. (Be careful tho, as a few AOSP based roms support it too. You might have a hard time compiling those!)
Choosing a programming language
At this point, it is highly suggested to learn a programming language if you want to escape the Buildbot stage. I am not forcing you, but you will have alot of trouble in doing advanced stuff.
There are several beginner friendly languages-
bash (the easiest)
Python (Recommended)
Kotlin (Android App development, quite easy)
Harder, recomended to learn after the easy langages-
Java (Gotta learn java if you want to make your own custom ROM at some point :3 )
C/C++ (Other than System UI, most of the other stuff for Android is written in C or C++)
Anything else you like! Once you get the basics, its not hard to learn another language .
The reason why I recommend Python is because it was the first language I learnt! Its pretty easy(Though, the OOP, Object Oriented Programming part is slightly advanced). It has wide applications and THE preferred language for Machine Learning and AI stuff, Period(OMG BUZZWORDS).
Kotlin is also fairely easy. I haven't programmed much in kotlin though I know basic syntaxes. If you learn it first, you won't have much trouble with learning Java. Probably. You can learn Java at first as well but you might have trouble! C is a must learn if you want to modify the Kernel and C++ is a must if you want to modify other code like HALs!
Python takes a day or two to learn! Not even kidding. I recommend this nice playlist by CSDojo - https://www.youtube.com/watch?v=Z1Yd7upQsXY&list=PLBZBJbE_rGRWeh5mIBhD-hhDwSEDxogDg
If you are interested in programming Machine learning, I recommend this playlist- https://www.youtube.com/playlist?list=PLOU2XLYxmsIIuiBfYad6rFYQU_jL2ryal
I learnt Kotlin basics from this Video - https://www.youtube.com/watch?v=H_oGi8uuDpA but there are more advanced videos as well.
I can't link Java tutorials as I haven't learnt it and nor do I plan to anytime soon. You can of course check youtube .
I learnt C from books and The C programming language by Dennis Ritchie and Brian W Keringhan is a must read! I quite liked "Programming in ANSI C" by E. Balagurusamy as well. You can of course, learn it on youtube.
Getting into programming takes a while and you might not like it at first but if you do, you will always enjoy it!
Basics To Conflict Resolution
It is assumed that you have a mind of a programmer and thus the guide will have alot less spoon feeding!
Lets get back to git and discuss about Conflict resolution. From time to time, you might want to cherry-pick something or perform a merge and you might get a "conflict".
Here's a basic idea!
The code between <<< HEAD and ===== is your previous code and the code between ====== and >>>> (commit SHA) is the new code from the commit. You get this if a part of the file in the commit is not the same as your local file.
There are 3 possibilities -
The code between <<<< HEAD and ===== is not required, thus you can delete that (Mostly)
The code between ===== and >>>>> is not required, thus the new change is not required (Rarely)
Both the old code and the new code is required (Pretty common!)
How do you decide between the three? You actually check the commit you are picking. In case of a merge, you can just view the history of a file and check the changes on github. Mostly, that should be enough for a decision. In case of a conflict while upstreaming my kernel, I usually refer to android-linux-stable project - http://github.com/android-linux-stable . Other times, I actually use my brain and figure out the option myself!
Compiling AOSP-based roms for CAF devices
Welp, I took alot of your time! You surely learnt plenty. Its the final part of this guide Took me a while to write all this ;_; .
I am assuming that you are fairly experienced now and you have atleast basic programming knowledge and plenty experience with git.
For starters, I recommend you to try AOSIP! It is highly compatible with Lineage trees and it shouldn't be much trouble to modify your device tree for it.
No spoon feeding at this point . Lets revise the basic idea! -
Find the rom source
Find the appropriate branch
Check the manifest for syncing and building instructions
Refer to another device tree(Possibly a tree of a similar device) and modify your device tree! (The hard part as its different from lineage based roms)
Environment setup
Start the build
Most of the AOSP-based roms use these commands-
Code:
lunch <codename>-<buildtype>
Code:
mka bacon
The lunch part is always there in Maximum AOSP based ROMs and the building command maybe different(i.e
Code:
time mka kronic
in AOSIP)
Another part I want to mention is about "HALs" . Usually most of the ROMs (even AOSP-based) ship with CAF HALs and support project pathmaps. However, some ROMs don't. Probably because they are not intended for CAF devices or the sources aren't properly complete yet! To build these ROM succesfully, I clone the CAF HALs from the lineage repo. These are- display-caf, media-caf, audio-caf, bt-caf and wlan-caf.
The first 3 HALs are usually platform specific so do check the branch on LineageOS! (for example, its lineage-16.0-caf-8996 branch for 821 series family SoCs for pie). The next step is to remove project pathmpas from both the device tree and the HALs. You can refer to the changes done by PedroKalil -
https://github.com/KAOSP/platform_hardware_qcom_display-caf/commits/aosp-8.1-8996
https://github.com/KAOSP/platform_hardware_qcom_media-caf/commits/aosp-8.1-8996
https://github.com/KAOSP/platform_hardware_qcom_audio-caf/commits/aosp-8.1-8937
Don't be lazy. Don't clone these HALs as these are outdated! Refer to them and do the appropriate changes on the latest Lineage HALs. the libbfqio changes may not be required as alot of AOSP-based roms have started to ship with it.
As for the Changes required in Device tree, you can refer to -
https://github.com/rupansh/pie_device_xiaomi_land/commit/c118701ba20a70fd59e32833417adeb7b08ab1d0 (The custom Audio policy is probably already enabled so no need to do that)
and https://github.com/rupansh/pie_device_xiaomi_land/commit/23215a2d8d5f1976657190f2a8f19f3fd111c250 (Depends on the path you cloned your HAL to)
You should now be able to compile any AOSP-based ROM! Experience is the key. Some other AOSP-based roms I recommend - NitrogenOS, AEX, AOSCP, Pixel Experience(Fairly easy), Pixel Dust(One of the hard), AOSPA( teach me when you fix the cneserver error lulz) .
Thats all you need to know to build AOSP-based ROMs for CAF devices .
If you wish to get into Android and Linux Kernel Development, Learning C is a must! I recommend this guide by nathanchance if you are ready! - https://forum.xda-developers.com/an...erence-how-to-compile-android-kernel-t3627297
Groups for help
https://t.me/AndroidBuildersHelp
https://t.me/LinuxKernelNewbies (Linux Kernel only)
Your device groups
Let me know if you want your group here
Credits
@tanish2k09 and @Swapnil Soni ( For guiding me even though I had 0 knowledge, co-operating with my idiotic requests)
ABH (Helping me realise that you can fix most of the errors by just searching properly)
@nathanchance (for his awesome kernel guides)
@KalilDev (For helping me with building AOSP based roms)
@ZeroInfinity (For machine learning tutorials kek)
@riteshsaxena (Bess sources for reference xD, Helping me with pie bringup which caused rapid progress for me)
You, the reader
I hope you learnt plenty of stuff from the guide. It took me a while to type this you see :3 .
​
awesome sir
rupanshji said:
@KalilDev (For helping me with building AOSP based roms)
Click to expand...
Click to collapse
This is one of the best or the most helpful guide I've ever read! I'll Recommend this for anyone who wants to join the ROM building club.
10/10 tutorial, thanx dev.
Thank you for this, OP
any guide like this for mtk devices?

Categories

Resources