Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,741,924 Members 45,184 Now Online
XDA Developers Android and Mobile Development Forum

COMPILE From Source For Any Phone On Linux Distros [BUILD ENVIRONMENT TO COMPILE]

Tip us?
 
mithun46
Old
(Last edited by mithun46; 13th December 2013 at 11:22 AM.)
#1  
mithun46's Avatar
Recognized Contributor - OP
Thanks Meter 1652
Posts: 1,231
Join Date: Oct 2012
Location: ▒▅|▆|█|▆|▅▒

 
DONATE TO ME
Prompt COMPILE From Source For Any Phone On Linux Distros [BUILD ENVIRONMENT TO COMPILE]


This is a guide to Compile From any CyanogenMod and CyanogenMod Source-Based source for Any Phone. This guide is for linux , Ubuntu etc.


What you’ll need
  • A Phone Which runs Android :P
  • A relatively recent computer (Linux, OS X, or Windows) w/a reasonable amount of RAM and storage. The less RAM you have, the longer the build will take. Using SSDs results in faster builds than traditional hard drives.
  • A micro USB cable
  • A decent Internet connection & reliable electricity
  • Some familiarity with basic Android operation and terminology. It would help if you’ve installed custom roms on other devices and are familiar with what a recovery image such as ClockworkMod is, for example. It may also be useful to know some basic command line concepts such as cd for “change directory”, the concept of directory hierarchies, that in Linux they are separated by /, etc.

Quote:
Note:
You want to use a 64-bit version of Linux. According to Google, 32-bit Linux environment will only work if you are building older versions prior to Gingerbread (2.3.x)/CyanogenMod 7.

Using a VM allows Linux to run as a guest inside your host computer-- a computer in a computer, if you will. If you hate Linux for whatever reason, you can always just uninstall and delete the whole thing. (There are plenty of places to find instructions for setting up Virtualbox with Ubuntu, so I’ll leave it to you to do that.)
So let’s begin!

Build ROM and ClockworkMod Recovery





Prepare the Build Environment


Quote:
Note:
You only need to do these steps the first time you build. If you previously prepared your build environment and have downloaded the CyanogenMod source code for another device, skip to Next Post.
Install the SDK
If you have not previously installed adb and fastboot, install the Android SDK. "SDK" stands for Software Developer Kit, and it includes useful tools that you will can use to flash software, look at the system logs in real time, grab screenshots, and more-- all from your computer.

Quote:
Helpful Tip!
While the SDK contains lots of different things-- the two tools you are most interested in for building Android are adb and fastboot, located in the /platform-tools directory.
Install the Build Packages
Several "build packages" are needed to build From Source. You can install these using the package manager of your choice.
Quote:
Helpful Tip!
A package manager in Linux is a system used to install or remove software (usually originating from the Internet) on your computer. With Ubuntu, you can use the Ubuntu Software Center. Even better, you may also use the apt-get install command directly in the Terminal. (Learn more about the apt packaging tool system from Wikipedia.)
For 32-bit & 64-bit systems, you'll need:
Code:
Select Code
git-core gnupg flex bison gperf libsdl1.2-dev libesd0-dev libwxgtk2.8-dev squashfs-tools build-essential zip curl 
libncurses5-dev zlib1g-dev openjdk-6-jre openjdk-6-jdk pngcrush schedtool
For 64-bit only systems, get these:
Code:
Select Code
g++-multilib lib32z1-dev lib32ncurses5-dev lib32readline-gplv2-dev gcc-4.7-multilib g++-4.5-multilib
For Linux Mint, you'll need:
Code:
Select Code
libc6-dev x11proto-core-dev libx11-dev libgl1-mesa-dev mingw32 tofrodos python-markdown libxml2-utils
Create the directories
Code:
Select Code
mkdir -p ~/bin
Install the repo command
Enter the following to download the "repo" binary and make it executable (runnable):
Code:
Select Code
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
Put the ~/bin directory in your path of execution
Make sure that the ~/bin directory you just created is in your path of execution so that you can easily run the repo command even when you're not in ~/bin. Assuming you are using the BASH shell, the default in recent versions of Ubuntu, you can set it like this:
Code:
Select Code
export PATH=${PATH}:~/bin
Quote:
Helpful Tip!
You can make this change to the path permanent for all future Terminal sessions:
Code:
Select Code
gedit ~/.bashrc
This will launch a graphical text editor. Enter
Code:
Select Code
export PATH=${PATH}:~/bin
on its own line, then save the file.
Initialize the source repository


Make a Folder to Download the Sources and cd to it. For That:
Code:
Select Code
mkdir -p ~/Source
Code:
Select Code
cd Source
Enter the following to initialize the repository:

Quote:
REPOSITORY'S OF FAMOUS ROMS (Select One)

PAC-Man :
Code:
Select Code
repo init -u git://github.com/PAC-man/android.git -b cm-10.2
CM 11.0 :
Code:
Select Code
repo init -u git://github.com/CyanogenMod/android.git -b cm-11.0
CM 10.1 :
Code:
Select Code
repo init -u git://github.com/CyanogenMod/android.git -b cm-10.2
CM10 :
Code:
Select Code
repo init -u git://github.com/CyanogenMod/android.git -b jellybean
Download the source code
Code:
Select Code
repo sync
Quote:
Helpful Tip!
The repo sync command is used to update the latest source code from CyanogenMod and Google. Remember it, as you can do it every few days to keep your code base fresh and up-to-date.

Get prebuilt apps
Code:
Select Code
cd ~/Source/vendor/cm
Code:
Select Code
./get-prebuilts
How To Compile is there on next post
The Following 185 Users Say Thank You to mithun46 For This Useful Post: [ Click to Expand ]
 
mithun46
Old
(Last edited by mithun46; 17th May 2013 at 01:33 PM.)
#2  
mithun46's Avatar
Recognized Contributor - OP
Thanks Meter 1652
Posts: 1,231
Join Date: Oct 2012
Location: ▒▅|▆|█|▆|▅▒

 
DONATE TO ME
Prepare the device-specific code

After the source downloads, type:
Code:
Select Code
. build/envsetup.sh
Then Do This

Code:
Select Code
breakfast ******
Where ***** is the codename for your device

Quote:
MAKE SURE YOUR PHONE IS ON OFFICIAL LATEST CYANOGENMOD ROM



Quote:
Helpful Tip!
If you get a command not found error for lunch, be sure you’ve done the “. build/envsetup.sh” command from ~/Source. Notice there is a period and space (“. ”) in that command.
Extract proprietary blobs

Now ensure that your Phone is connected to your computer via the USB cable and that you are in the ~/Source/device/***/***** directory (you can cd ~/Source/device/***/****** if necessary). Run as Root if on Debian using sudo. Then run the this script:
Code:
Select Code
./proprietary-files.sh
or
Code:
Select Code
./extract-files.sh
Quote:
Here ***** is Device codename and *** is the Phone Company like Samsung or HTC
For Example if my phone is note 2 then this will be the device path : ~/Source/device/Samsung/n7100
You should see the proprietary files (aka “blobs”) get pulled from the device and moved to the right place in the vendor directory. If you see errors about adb being unable to pull the files, adb may not be in the path of execution

Quote:
Note:
It’s important that these proprietary files are properly extracted and moved to the vendor directory. Without them, CyanogenMod will build without error, but you’ll be missing important functionality, such as the ability to see anything!
Turn on caching to speed up build

Code:
Select Code
export USE_CCACHE=1
Start the build

Code:
Select Code
cd ~/Source
brunch *****
Here ***** is the Phone Codename

Quote:
Helpful Tip!
If the build doesn't start, try lunch and choose your device from the menu. If that doesn't work, try breakfast and choose from the menu. The command make ***** should then work.
If the build breaks...
If you experience this not-enough-memory-related error...
Code:
Select Code
ERROR: signapk.jar failed: return code 1make: *** [out/target/product/n7100/cm_n7100-ota-eng.root.zip] Error 1
...you may want to make the following change to This File : system/build/tools/releasetools/common.py
Change: java -Xmx2048m to java -Xmx1024m or java -Xmx512m
Then start the build again (with brunch).
If you see a message about things suddenly being “killed” for no reason, your (virtual) machine may have run out of memory or storage space. Assign it more resources and try again.

Install the build
Assuming the build completed without error (it will be obvious when it finishes), type:
Code:
Select Code
# cd $OUT
in the same terminal window that you did the build. Here you’ll find all the files that were created. The stuff that will go in /system is in a folder called system. The stuff that will become your ramdisk is in a folder called root. And your kernel is called... kernel.
But that’s all just background info. The two files we are interested in are (1) recovery.img, which contains ClockworkMod recovery, and (2) cm-[something].zip, which contains ROM.

Install ROM
Back to the $OUT directory on your computer-- you should see a file that looks something like:
Code:
Select Code
cm-10-20120718-UNOFFICIAL-***.zip
Here *** is the phone codename

Now you can flash the ...zip file above as usual via recovery mode. (Be sure you have backed up any previous installation before trying your new build.)


Feedbacks to this guide

 
Quote:
Originally Posted by tommyjt24 View Post
I got my build working!
Great tutorial by the way!
Tom
Quote:
Originally Posted by sevenup30 View Post
Well i finally sucessfully build.
thank you for your help
Quote:
Originally Posted by AndyFox2011 View Post
Works like a charm, used it a while ago too set up on 12.10
Quote:
Originally Posted by sswb27 View Post
Compiling cm10.1 worked great for my sgs3 d2tmo.Thank's for the tutorial it's been fun setting this up.
Quote:
Originally Posted by matt95 View Post
really really good guide, very detailed and precise.
Quote:
Originally Posted by Koetermann View Post
Hi there,
I was finally able to compile Cyanogenmod from source.
So, thanks for your guide an your support.Thanks a lot.
Regards Koetermann
Quote:
Originally Posted by AndyFox2011 View Post
Used your guide again to setup my PC for building! Worked like a charm on 11.04
Quote:
Originally Posted by Melch1zedeK View Post
thanks for post this, great and simple guide for n00bs (like me)
Quote:
Originally Posted by VipSaran View Post
This tutorial ROCKS! . Successfully built i9300 starting from fresh ubuntu 12.10 installation w/o even a hickup




Read the Below Command Before Asking question regarding Device tree : Credit @speed_bot
 
HTML Code:
#include
#include /ps my own header/
main()
{
int device tree,rom;
for((device==1) || (device tree =1))
printf("you can build a rom");
else 
printf("you cant :P");
}
If you consider my efforts worthwhile then Donate or Thank me
The Following 94 Users Say Thank You to mithun46 For This Useful Post: [ Click to Expand ]
 
pongnamu
Old
#3  
pongnamu's Avatar
Recognized Contributor
Thanks Meter 1698
Posts: 1,168
Join Date: Feb 2012
Location: Jeonju
Great guide!

I want to build cm10.1 for x10 mini and I have to modify
<?xml version="1.0" encoding="UTF-8"?>

<manifest>

<project name="teamhacksung/buildscripts" path="buildscripts" remote="github" revision="jellybean">

<copyfile dest="build.sh" src="build.sh" />

</project>

<project name="TheMuppets/proprietary_vendor_samsung" path="vendor/samsung" remote="github" revision="jellybean" />

<project name="CyanogenMod/android_packages_apps_SamsungServiceMode" path="packages/apps/SamsungServiceMode" remote="github" revision="jellybean" />

<project name="CyanogenMod/android_device_samsung_n7000" path="device/samsung/n7000" remote="github" revision="jellybean" />

<project name="CyanogenMod/android_device_samsung_galaxys2-common" path="device/samsung/galaxys2-common" remote="github" revision="jellybean" />

<project name="CyanogenMod/android_kernel_samsung_smdk4210" path="kernel/samsung/smdk4210" remote="github" revision="jellybean" />

<project name="CyanogenMod/android_hardware_samsung" path="hardware/samsung" remote="github" revision="jellybean" />

</manifest>

right? So, how can I do that? What should I change it into? Thanks


CURRENT DEVICES: XPERIA X10 MINI & IPHONE 5S
PAST DEVICES: XPERIA Z1

MY WORKS

JOIN ME ON GOOGLE+ COMMUNITY AND ADD ME ON GOOGLE+
The Following 2 Users Say Thank You to pongnamu For This Useful Post: [ Click to Expand ]
 
mithun46
Old
#4  
mithun46's Avatar
Recognized Contributor - OP
Thanks Meter 1652
Posts: 1,231
Join Date: Oct 2012
Location: ▒▅|▆|█|▆|▅▒

 
DONATE TO ME
Quote:
Originally Posted by pongnamu View Post
Great guide!

I want to build cm10.1 for x10 mini and I have to modify
<?xml version="1.0" encoding="UTF-8"?>

<manifest>

<project name="teamhacksung/buildscripts" path="buildscripts" remote="github" revision="jellybean">

<copyfile dest="build.sh" src="build.sh" />

</project>

<project name="TheMuppets/proprietary_vendor_samsung" path="vendor/samsung" remote="github" revision="jellybean" />

<project name="CyanogenMod/android_packages_apps_SamsungServiceMode" path="packages/apps/SamsungServiceMode" remote="github" revision="jellybean" />

<project name="CyanogenMod/android_device_samsung_n7000" path="device/samsung/n7000" remote="github" revision="jellybean" />

<project name="CyanogenMod/android_device_samsung_galaxys2-common" path="device/samsung/galaxys2-common" remote="github" revision="jellybean" />

<project name="CyanogenMod/android_kernel_samsung_smdk4210" path="kernel/samsung/smdk4210" remote="github" revision="jellybean" />

<project name="CyanogenMod/android_hardware_samsung" path="hardware/samsung" remote="github" revision="jellybean" />

</manifest>

right? So, how can I do that? What should I change it into? Thanks
You can Pm Freexperia for that.
i dont know every android phone's code
i know about freeexperia because i own a xperia mini myself
If you consider my efforts worthwhile then Donate or Thank me
The Following User Says Thank You to mithun46 For This Useful Post: [ Click to Expand ]
 
dewanshu93
Old
#5  
dewanshu93's Avatar
Recognized Contributor
Thanks Meter 854
Posts: 538
Join Date: Sep 2011
Location: Chandigarh
Quote:
Originally Posted by mithun46 View Post
[B][U][CENTER][SIZE="7"]

Code:
Select Code
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.6-dev python
M getting error

Quote:
jolly@ubuntu:~$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.6-dev python
[sudo] password for jolly:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package lib32bz2-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package lib32ncurses5-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package lib32readline-gplv2-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package lib32readline5 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package lib32readline6 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package ia32-libs is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'lib32ncurses5-dev' has no installation candidate
E: Package 'ia32-libs' has no installation candidate
E: Unable to locate package lib32z-dev
E: Package 'lib32readline-gplv2-dev' has no installation candidate
E: Package 'lib32readline5' has no installation candidate
E: Package 'lib32readline6' has no installation candidate
E: Package 'lib32bz2-dev' has no installation candidate
E: Unable to locate package libwxgtk2.6-dev
E: Couldn't find any package by regex 'libwxgtk2.6-dev
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

LT22i Stock JB 4.1.2 [6.2.A.1.100][ROOTED][CWM 6][Locked BL]



HIT THANKS IF I HELPED YOU
The Following User Says Thank You to dewanshu93 For This Useful Post: [ Click to Expand ]
 
mithun46
Old
#6  
mithun46's Avatar
Recognized Contributor - OP
Thanks Meter 1652
Posts: 1,231
Join Date: Oct 2012
Location: ▒▅|▆|█|▆|▅▒

 
DONATE TO ME
Quote:
Originally Posted by dewanshu93 View Post
M getting error
sorry for my mistake
u should enter it in package manager and install them all
If you consider my efforts worthwhile then Donate or Thank me
The Following User Says Thank You to mithun46 For This Useful Post: [ Click to Expand ]
 
chasmodo
Old
#7  
chasmodo's Avatar
Senior Member
Thanks Meter 39263
Posts: 11,845
Join Date: Dec 2011
Location: Novi Sad

 
DONATE TO ME
Your local_manifest.xml is incorrect for compiling CM10.1.
 
mithun46
Old
#8  
mithun46's Avatar
Recognized Contributor - OP
Thanks Meter 1652
Posts: 1,231
Join Date: Oct 2012
Location: ▒▅|▆|█|▆|▅▒

 
DONATE TO ME
Quote:
Originally Posted by chasmodo View Post
Your local_manifest.xml is incorrect for compiling CM10.1.
The Below Manifest is for Compiling CM10. Not CM10.1
If you consider my efforts worthwhile then Donate or Thank me
The Following User Says Thank You to mithun46 For This Useful Post: [ Click to Expand ]
 
shoey63
Old
#9  
shoey63's Avatar
Recognized Contributor
Thanks Meter 1300
Posts: 2,155
Join Date: Jun 2012
Location: Somewhere in Oz...
Good effort though

Sent from my GT-N7000 using xda app-developers app
 
pulser_g2
Old
#10  
pulser_g2's Avatar
Developer Admin / Senior Recognized Developer
Thanks Meter 10691
Posts: 19,244
Join Date: Nov 2009
The issue with guides like these is they are specific to one version of Ubuntu. I successfully build Android on gentoo, which has about as little in common with Ubuntu as possible. Hence we prefer to go for guides which, where possible, teach the reasoning, rather than the method.

For building CM, this might be worthwhile merging into the "how to build android from source" one?

Unfortunately this guide isn't usable for most people, as it relies on the hacksung build scripts, so you can only build for certain devices...

What might be better is a guide on using roomservice via lunch, to build for any device?


Having trouble getting an answer? | What is XDA about? | How to ask for help?

if [ $PM.incoming.type = $type.question.ROM.how_to_use ] || [ $PM.incoming.type = $type.question.ROM.silly_question ]; then mv $PM.incoming /.trash; PM.response($responsetype.ignore); $PM.sender.ignore_in_future=true; init.sequence($boy_who_cried_wolf); fi;

BTC: 1K2fpDsRHkirWmk3PKiqtzhVHKUJCWPWnN
PGP: 0x260F4FDEF258E3C4

The Following 18 Users Say Thank You to pulser_g2 For This Useful Post: [ Click to Expand ]
Tags
*abhi boomed here*, compile android from source, easy, ubuntu 12.10
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes