— If you would rather use a ready-to-go Virtual Machine based on these instructions, check out this post!—
Copied with permission from nathanpfry.com
With a new version of Ubuntu comes an update to my world-famous guide for setting up a build environment to compile Android ROMs. The aim of this is to simplify the configuration process for you.
Follow the directions step-by-step. All you have to do is copy and paste the code in order and it will be up and running in no time!
This guide applies to all variations of Ubuntu 15.04 Vivid Vervet 64 bit. Do not use the 32 Bit version.
Also, PAY CLOSE ATTENTION when to use “sudo” and when to not. It can make things funky if you do something as root that you shouldn’t.
Much thanks goes out to Google, ProTekk, Canonical, and everyone else that I read a random paragraph here and snippet there.
Ready to begin? Ok.
1) Unless it’s a completely fresh Ubuntu installation, many of you have the wrong version of Java installed. Let’s fix that first.
The command below makes sure you’re starting with a clean slate. Copy and paste it into a terminal (command prompt) window:
Code:
sudo apt-get remove openjdk-* icedtea-* icedtea6-*
If necessary, follow the on-screen instructions to remove any stray Java versions. Otherwise, move on to the next step.
2) Install the main build tools with this command:
Code:
sudo apt-get install openjdk-7-jdk 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
That’s it on the package side of things.
3) A program called “repo” lets you communicate with git servers and download all that precious source code. The next command will install it:
Code:
mkdir ~/bin && curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo && chmod a+x ~/bin/repo
4) Use your favorite text editor to open ~/.bashrc – I like nano:
Code:
sudo nano ~/.bashrc
5) At the very bottom (use the Page Down key) paste this code to a new line:
Code:
export PATH=~/bin:$PATH
export USE_CCACHE=1
6) Save it. In nano that would be Ctrl-O and then Enter. Then Ctrl-X to exit back to a prompt. Restart bash:
Code:
source ~/.bashrc
7) In the terminal, navigate to where you would like to download the Android source code. The commands below will make it in your home folder, but if you have limited space you may want to create it somewhere else. Faster is better, i.e. SSD would be best, USB external (even 3.0) will be comparatively slow. Here we go:
Code:
mkdir ~/android
cd ~/android
8) Now you’re going to initialize the repo. This is where you decide the flavor of Android you want to build, i.e. AOKP, CyanogenMod, AOSP etc.
For the purposes of the tutorial, here’s the command for SimpleAOSP Lollipop:
Code:
repo init -u https://github.com/SimpleAOSP-Lollipop/platform_manifest.git -b L
9) Last step. Time to get the source. Prepare yourself, many gigabytes of downloading await.
Don’t worry, it’s automated.
Hey everyone, it’s the final terminal command!
Code:
repo sync
Check back periodically every hour or so. It all depends on how fast your connection is.
That should be everything. Now you’re ready to build Android. Good luck!
If this guide helped you out, feel free to click the thanks button!
For those of you that want to build Gingerbread thru KitKat, here's the easiest way to update your system:
First add the PPA for older Java 1.6 builds.
Code:
sudo add-apt-repository ppa:webupd8team/java
Then install:
Code:
sudo apt-get update && sudo apt-get install oracle-java6-installer
Once that completes, you simply need to tell Linux to use the older version of Java and Java Compiler to render content.
Run the following two commands separately, making the correct selection for Oracle JDK 1.6 both times when prompted. Again in the terminal:
Code:
sudo update-alternatives --config java
sudo update-alternatives --config javac
That should do the trick!
Going to replace 14.04 with this, keep having javac crashes and whatever it is is not isolated to this version.
Update:
mingw32, lib32bz2-1.0, lib32bz2-dev not found.
Code:
============================================
Checking build tools versions...
************************************************************
You are attempting to build with the incorrect version
of java.
Your version is: Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar java version "1.7.0_79" OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu1) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode).
The required version is: "1.7.x/1.8.x"
Please follow the machine setup instructions at
https://source.android.com/source/initializing.html
************************************************************
build/core/main.mk:174: *** stop. Stop.
#### make failed to build some targets (2 seconds) ####
Still getting this error
aapav01 said:
Code:
============================================
Checking build tools versions...
************************************************************
You are attempting to build with the incorrect version
of java.
Your version is: Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar java version "1.7.0_79" OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu1) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode).
The required version is: "1.7.x/1.8.x"
Please follow the machine setup instructions at
https://source.android.com/source/initializing.html
************************************************************
build/core/main.mk:174: *** stop. Stop.
#### make failed to build some targets (2 seconds) ####
Still getting this error
Click to expand...
Click to collapse
same error here. still trying to figure it out. you can remove the lines of code that check for java on main.mk to build, nonetheless.
---------- Post added at 08:32 ---------- Previous post was at 08:30 ----------
and BTW, you only need these packages to build on 14.04 and upwards:
Code:
sudo apt-get install bison g++-multilib git gperf libxml2-utils make zlib1g-dev:i386 zip
in:
https://source.android.com/source/initializing.html
infected_ said:
same error here. still trying to figure it out. you can remove the lines of code that check for java on main.mk to build, nonetheless.
---------- Post added at 08:32 ---------- Previous post was at 08:30 ----------
and BTW, you only need these packages to build on 14.04 and upwards:
Code:
sudo apt-get install bison g++-multilib git gperf libxml2-utils make zlib1g-dev:i386 zip
in:
https://source.android.com/source/initializing.html
Click to expand...
Click to collapse
did u find the way to solve it..
fix no.. kind of a hack.
edit "main.mk" and remove the lines that check for java version.
infected_ said:
fix no.. kind of a hack.
edit "main.mk" and remove the lines that check for java version.
Click to expand...
Click to collapse
bro but it will not stop that repo sync thingie
infected_ said:
fix no.. kind of a hack.
edit "main.mk" and remove the lines that check for java version.
Click to expand...
Click to collapse
BRO i found the fix just need to do this
Copy and paste the following into the terminal:
Code:
sudo apt-get install openjdk-7-jre openjdk-7-jdk
IF i help plz don't forget to press the thanks
---------- Post added at 11:26 PM ---------- Previous post was at 11:23 PM ----------
sylentprofet said:
If necessary, follow the on-screen instructions to remove any stray Java versions. Otherwise, move on to the next step.
2) Copy and paste the following into the terminal:
Code:
sudo apt-get install openjdk-7-jdk
[/B]
Click to expand...
Click to collapse
i think u change the 2nd to this
Code:
sudo apt-get install openjdk-7-jre openjdk-7-jdk
infected_ said:
same error here. still trying to figure it out. you can remove the lines of code that check for java on main.mk to build, nonetheless.
Click to expand...
Click to collapse
For those of you that want to build Gingerbread thru KitKat (which requires Oracle JDK 1.6) but already have your system configured for Lollipop (JDK 1.7), here's the easiest way to update your system:
First add the PPA for updated Java builds.
Code:
sudo add-apt-repository ppa:webupd8team/java
Then install:
Code:
sudo apt-get update && sudo apt-get install oracle-java6-installer
Once that completes, you simply need to tell Linux to use the older version of Java and Java Compiler to render content.
Run the following two commands separately, making the correct selection for Oracle JDK 1.6 both times when prompted. Again in the terminal:
Code:
sudo update-alternatives --config java
sudo update-alternatives --config javac
That should do the trick! I'll add this to the main thread.
infected_ said:
and BTW, you only need these packages to build on 14.04 and upwards:
Click to expand...
Click to collapse
That may be true for vanilla Google Android, but if you attempt to build for another flavor (ie Cyanogenmod), additional packages are required (image optimizers etc)
This guide is designed to help new users prepare their systems as comprehensively as possible. If you don't know what you're talking about, please don't confuse people with misinformation or poorly crafted "hacks". I've been publishing this guide for 3 years now, ask a question and be patient, try reading Google results for a couple of hours - I'll do everything I can to help out.
garwynn said:
Going to replace 14.04 with this, keep having javac crashes and whatever it is is not isolated to this version.
Update:
mingw32, lib32bz2-1.0, lib32bz2-dev not found.
Click to expand...
Click to collapse
Thanks for the heads up. Don't know how those snuck in there, I think I accidentally copied the string from one of my older guides.
OP updated.
sylentprofet said:
That may be true for vanilla Google Android, but if you attempt to build for another flavor (ie Cyanogenmod), additional packages are required (image optimizers etc)
This guide is designed to help new users prepare their systems as comprehensively as possible. If you don't know what you're talking about, please don't confuse people with misinformation or poorly crafted "hacks". I've been publishing this guide for 3 years now, ask a question and be patient, try reading Google results for a couple of hours - I'll do everything I can to help out.
Click to expand...
Click to collapse
you are a bit full of yourself, no? i was trying to help. and i really dont care you've been doing this for 3y... anyone can google for tutorials and make one. you made even worse, just adapted one from 14.10 or 14.04, which gave you those 3 not found packages. you made the tutorial and forget to test it?
got it to build CM in 15.04 with the packages i mentioned, only lzop was missing.
and if you see another way to build, without the jayatana error, when checking for java version, without hacking main.mk to remove java version check, please be my guest and do so.
meanwhile heres a commit i pushed to temporarily build, until a proper fix gets merged on CM repos.
https://github.com/infected-lp/android_build/commit/eb88ff447df814f8c7a57e807e4b0bb4ede7c7dd
regards!
infected_ said:
you are a bit full of yourself, no? i was trying to help. and i really dont care you've been doing this for 3y... anyone can google for tutorials and make one. you made even worse, just adapted one from 14.10 or 14.04, which gave you those 3 not found packages. you made the tutorial and forget to test it?
Click to expand...
Click to collapse
Not really full of myself, no, I just know what I'm talking about.
Yeah I was a bit lazy and published without testing first, oh well. It's updated now. And I thanked the person that pointed it out.
The point is you weren't helping. Your "hack" will run into an error anytime you attempt to repo sync.
Either way I'm not here to argue about it. Have fun working on your projects!
sylentprofet said:
The point is you weren't helping. Your "hack" will run into an error anytime you attempt to repo sync.
Click to expand...
Click to collapse
lol.. explain that to me like i am a 6y old and been doing this since yesterday...
in which way will a cherry-pick commit on the build repo interfere with syncing? you dont build much, do you?
ill leave it here before you embarass yourself even more
regards.
infected_ said:
lol.. explain that to me like i am a 6y old and been doing this since yesterday...
in which way will a cherry-pick commit on the build repo interfere with syncing? you dont build much, do you?
ill leave it here before you embarass yourself even more
regards.
Click to expand...
Click to collapse
Most people starting to learn Android have no idea how to use git at that level. They would likely edit the file locally on their computer and then start running into problems. But hey what do I know?
*shrug* I'm over it already.
hi i am sorry
java err
cm12.1 buid...
install openjdk7 ..
============================================
Checking build tools versions...
************************************************************
You are attempting to build with the incorrect version
of java.
Your version is: Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar java version "1.7.0_79" OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu1) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode).
The required version is: "1.7.x"
Please follow the machine setup instructions at
https://source.android.com/source/initializing.html
************************************************************
java -version ok
[email protected]:~$ java -version
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
[email protected]:~$
java -err
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
??
windows8k said:
java err
Click to expand...
Click to collapse
Hi, can you please try the following two commands separately and reply with copy-paste output?
Code:
sudo update-alternatives --config java
Code:
sudo update-alternatives --config javac
If it prompts you to make a selection, make sure to choose OpenJDK 1.7 both times.
Thanks!
windows8k said:
hi i am sorry
java err
cm12.1 buid...
install openjdk7 ..
============================================
Checking build tools versions...
************************************************************
You are attempting to build with the incorrect version
of java.
Your version is: Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar java version "1.7.0_79" OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu1) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode).
The required version is: "1.7.x"
Please follow the machine setup instructions at
https://source.android.com/source/initializing.html
************************************************************
java -version ok
[email protected]:~$ java -version
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
[email protected]:~$
java -err
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
??
Click to expand...
Click to collapse
Hi,
the problem is due to JAVA_TOOL_OPTIONS line, appearing also launching
java -version
in order to avoid it you can uninstall jayatana and reboot the system:
sudo apt-get remove jayatana
[Restart the PC]
sylentprofet said:
Hi, can you please try the following two commands separately and reply with copy-paste output?
Code:
sudo update-alternatives --config java
Code:
sudo update-alternatives --config javac
If it prompts you to make a selection, make sure to choose OpenJDK 1.7 both times.
Thanks!
Click to expand...
Click to collapse
Thanks openjdk7 change sudo apt-get remove jayatana.
---------- Post added at 12:42 PM ---------- Previous post was at 12:42 PM ----------
aapav01 said:
Hi,
the problem is due to JAVA_TOOL_OPTIONS line, appearing also launching
java -version
in order to avoid it you can uninstall jayatana and reboot the system:
sudo apt-get remove jayatana
[Restart the PC]
Click to expand...
Click to collapse
Thanks openjdk7 change sudo apt-get remove jayatana. Reboot
windows8k said:
hi i am sorry
java err
cm12.1 buid...
install openjdk7 ..
============================================
Checking build tools versions...
************************************************************
You are attempting to build with the incorrect version
of java.
Your version is: Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar java version "1.7.0_79" OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu1) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode).
The required version is: "1.7.x"
Please follow the machine setup instructions at
https://source.android.com/source/initializing.html
************************************************************
java -version ok
[email protected]:~$ java -version
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
[email protected]:~$
java -err
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
??
Click to expand...
Click to collapse
simply enter the dir /build inside your android build environment and copy & paste this and press enter:
git fetch https://github.com/infected-lp/android_build infected && git cherry-pick eb88ff447df814f8c7a57e807e4b0bb4ede7c7dd
then get back to the root of the build environment, like "cd .." or "croot" in case you've done ". build/envsetup.sh" already.
sylentprofet said:
Hi, can you please try the following two commands separately and reply with copy-paste output?
Code:
sudo update-alternatives --config java
Code:
sudo update-alternatives --config javac
If it prompts you to make a selection, make sure to choose OpenJDK 1.7 both times.
Thanks!
Click to expand...
Click to collapse
wont work, ive tried that.
aapav01 said:
Hi,
the problem is due to JAVA_TOOL_OPTIONS line, appearing also launching
java -version
in order to avoid it you can uninstall jayatana and reboot the system:
sudo apt-get remove jayatana
[Restart the PC]
Click to expand...
Click to collapse
removing jayatana also wont work ... it will still give error on the useragent, and update-alternatives wont help....
solution for now is what i say:
simply enter the dir /build inside your android build environment and copy & paste this and press enter:
git fetch https://github.com/infected-lp/android_build infected && git cherry-pick eb88ff447df814f8c7a57e807e4b0bb4ede7c7dd
then get back to the root of the build environment, like "cd .." or "croot" in case you've done ". build/envsetup.sh" already.
Click to expand...
Click to collapse
regards....
infected_ said:
simply enter the dir /build inside your android build environment and copy & paste this
git fetch https://github.com/infected-lp/android_build infected && git cherry-pick eb88ff447df814f8c7a57e807e4b0bb4ede7c7dd
Click to expand...
Click to collapse
Thank you for the solution! Build started, I hope it will be successful
Code:
Your version is: openjdk version "1.7.0_75" OpenJDK Runtime Environment (build 1.7.0_75-b13) OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode).
The required version is: "1.7.x"
Using CyanogenMod 12.1 as a base (need to build for a older phone).
openjdk is installed and currently active. Restarted, checked env, reinstalled - nothing.
1.7.x should natch 1.7.0_75. Is this some weird code glitch where it doesnät like the _75?
Seems like main.mk grep was a bit too hardcoded - it was looking for a very specific format for java -version.
as in java.
Code:
java_version := $(shell echo '$(java_version_str)' | grep '^java .*[ "]1\.7[\. "$$]')
While version returned:
Code:
openjdk version "1.7.0_75"
how to fix this then i got this same error
plzz reply
raxxeo said:
plzz reply
Click to expand...
Click to collapse
see error or similar build/core/main.mk:160?: *** stop.
comment # on lines
Code:
#ifeq ($(strip $(java_version)),)
#$(info ************************************************************)
#$(info You are attempting to build with the incorrect version)
#$(info of java.)
#$(info $(space))
#$(info Your version is: $(java_version_str).)
#$(info The required version is: $(required_version))
#$(info $(space))
#$(info Please follow the machine setup instructions at)
#$(info $(space)$(space)$(space)$(space)https://source.android.com/source/initializing.html)
#$(info ************************************************************)
#$(error stop)
#endif