Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[TUT] Configuring Arch Linux to build Android

OP GermainZ

1st May 2013, 09:45 PM   |  #1  
GermainZ's Avatar
OP Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,333
 
5,910 posts
Join Date:Joined: Aug 2012
More
Arch Linux is a rolling release distribution, but Android requires you to have jdk6 (or openjdk6) and python2 to build it. It took me some time to setup everything, and I hope this guide will be useful to anyone who's trying to do the same.

The ArchWiki is a bit outdated. Among other things, it suggests changing the "python" symlink to point to python2, which I didn't want to do as it could cause problems ("python" is supposed to point to python3). Also, Arch Linux uses openjdk7, so you'd have to downgrade to openjdk6 (or Oracle's jdk6) - which isn't mentioned in the Wiki, and is something I'd rather avoid as I want to keep using the latest version.

Basically, I'd like to share this here for now to get some input, and later update the ArchWiki.

0- Quick note about this guide
I think it's pretty safe to assume you're familiar with the terminal.
Also note that this guide will not really talk about how to actually build Android, it's focused on setting up your Arch distro to do so in an easy way.

1- Prerequisites
The ArchWiki covers installing the Android SDK and ADB pretty well.

You'll need these packages for building Android:
Code:
git gnupg flex bison gperf sdl wxgtk squashfs-tools curl ncurses zlib schedtool perl-switch zip unzip
And for 64 bit systems (make sure multilib is enabled):
Code:
lib32-zlib lib32-ncurses lib32-readline gcc-libs-multilib gcc-multilib lib32-gcc-libs
You also need the "repo" utility, which is available in the AUR.

2- Setting up Java
The AUR has packages that should install alongside openjdk7, but that didn't work for me and I found it easier to simply install jdk6 independently of pacman's packages.
To do so, download the latest Linux .bin file (jdk-6u45-linux-x64.bin), and place it in /opt (run a root shell, "sudo bash"):
Code:
cp ~/Downloads/jdk-6u45-linux-x64.bin
Make it executable and run it as root:
Code:
cd /opt
chmod +x jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
We'll be updating our path before building to use this version.

3- Setting up Python
We're going to create a python symlink to python2, and place it in /opt/android-build. We'll use this later by updating our path when necessary.
Code:
mkdir /opt/android-build
cd /opt/android-build
ln -s $(which python2) python
4- (Temporarily) Setting up our PATH to test if everything's fine
We just installed jdk6 and made a symlink to python2, but we still need to update our path. In this step, we'll do that in order to test that everything's fine:
Code:
export PATH="/opt/android-build:/opt/jdk1.6.0_45/bin:$PATH"
Make sure jdk6 and python2 are being used:
Code:
echo -n $(python -V)
echo -n $(java -version)
The output should be similar to:
Code:
Python 2.x.x
java version "1.6.xx"
Java(TM) SE Runtime Environment (build 1.6.xx)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
5- Make a build script (or just build).
I'd highly suggest making a build script and placing it in ~/bin. You can then easily run it, and it will take care of everything.
Otherwise, you can run this in the terminal every time before building:
Code:
export PATH="/opt/android-build:/opt/jdk1.6.0_45/bin:$PATH"
And then proceed normally, for example:
Code:
. build/envsetup.sh
lunch cyanogen_cooperve-eng
make clean
time make -j6 bacon
This is my (trimmed down to remove some git revert checks) personal build script, you can modify it to fit your needs. The working directory is your home folder, change the "path" variable around the middle if yours is different.

Code:
Help() {
    echo -n "Usage: build [OPTIONS]
    -h, --help      show this screen
    -s, --sync      run repo sync before building
    -c, --clean     make clean"
    echo
}

box () {
    tput setaf 6
    echo
    str="$@"
    len=$((${#1}+4))
    for ((i = 1; i <= $len; i++)); do
        echo -n '*'
    done
    echo
    echo "* $str *"
    for ((i = 1; i <= $len; i++)); do
        echo -n '*'
    done
    echo
    tput sgr0
}

path="/home/germain/"
sync=0
clean=0
while :; do
    case $1 in
        -h | --help)
            Help
            exit 0
            ;;
        -s | --sync)
            sync=1
            shift
            ;;
        -c | --clean)
            clean=1
            shift
            ;;
        --)
            shift
            break
            ;;
        -*)
            echo "Unknown option $1, ignoring" >&2
            shift
            ;;
        *)
            break
            ;;
    esac
done

clear
box "Setting up \$PATH..."
export PATH="/opt/android-build:/opt/jdk1.6.0_45/bin:$PATH"
echo -n $(python -V)
echo -n $(java -version)

cd "$path"

(( "$sync"==1 )) && box "Syncing..." && repo sync -j64

box "Starting build..."
. build/envsetup.sh
lunch cyanogen_cooperve-eng
(( "$clean"==1 )) && box "Clean build!" && echo && make clean
time make -j6 bacon

box "Done!"

To set it up:
Code:
nano ~/bin/build
<copy the above script, press SHIFT + INSERT to paste, and CTRL+X followed by "Y" to save>
chmod +x ~/bin/build
Usage:
Code:
Usage: build [OPTIONS]
    -h, --help      show this screen
    -s, --sync      run repo sync before building
    -c, --clean     make clean
Sources
These web pages helped me a lot.
  1. http://f0rki.at/building-android-on-...ux-x86_64.html
  2. https://wiki.archlinux.org/index.php/Android
  3. https://bbs.archlinux.org/viewtopic.php?id=131939
The Following 26 Users Say Thank You to GermainZ For This Useful Post: [ View ]
2nd May 2013, 11:07 AM   |  #2  
lelinuxien52's Avatar
Senior Member
Flag Aix-en-Provence (04100)
Thanks Meter: 56
 
264 posts
Join Date:Joined: Jun 2012
More
Good job dude. I already use Arch Linux for developing Android firmware but I haven't the time to make one tutorial for others.
18th May 2013, 05:22 AM   |  #3  
Recognized Contributor
Flag Delhi
Thanks Meter: 1,495
 
3,782 posts
Join Date:Joined: May 2010
More
Thanks for the guide, but even after I have set the correct java path, (java -version shows Java SE), while building, it still gives a warning that I'm building with Java 1.7 (openjdk). Any pointers?

Checking build tools versions...
************************************************** **********
You are attempting to build with an unsupported version
of java.

Your version is: java version "1.7.0_21".
The correct version is: Java SE 1.6 or 1.7.

Please follow the machine setup instructions at
https://source.android.com/source/download.html



EDIT: NVM. Fixed by exporting JAVA_HOME and J2SDKDIR
Last edited by kalpik; 18th May 2013 at 05:58 AM.
The Following User Says Thank You to kalpik For This Useful Post: [ View ]
8th June 2013, 06:42 AM   |  #4  
Junior Member
Thanks Meter: 1
 
2 posts
Join Date:Joined: Jun 2013
Geat job GermainZ!

The packages in the AUR which should install alongside openjdk7 should work (it works for me) if you:
Code:
export PATH="/opt/java6/bin:$PATH"
Then (as you mention) you can check by:
Code:
echo -n $(java -version)

Anyway thanks for the guide, I think it is definitely worth updating the Arch Wiki to include this information!
The Following User Says Thank You to marno11 For This Useful Post: [ View ]
8th June 2013, 05:08 PM   |  #5  
GermainZ's Avatar
OP Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,333
 
5,910 posts
Join Date:Joined: Aug 2012
More
Quote:
Originally Posted by marno11

Geat job GermainZ!

The packages in the AUR which should install alongside openjdk7 should work (it works for me) if you:

Code:
export PATH="/opt/java6/bin:$PATH"
Then (as you mention) you can check by:
Code:
echo -n $(java -version)

Anyway thanks for the guide, I think it is definitely worth updating the Arch Wiki to include this information!

I see they were recently updated. They weren't building for me at the time, and I didn't have enough time to check the PKGBUILD.
I'll do my best to update the wiki when I can, including both options. Thanks.
The Following 2 Users Say Thank You to GermainZ For This Useful Post: [ View ]
18th June 2013, 10:57 PM   |  #6  
Senior Member
Flag Frankfurt
Thanks Meter: 211
 
108 posts
Join Date:Joined: Jan 2011
Donate to Me
More
Thanks for putting this up, I landed on this after following the link in the Arch wiki.

I have a suggestion concerning point 3 (python). Wouldn't it be more sane to use python's virtualenv to set up a python distro for Android?

And BTW, I am trying out the new android-studio, which works for me out of the box, even with openjdk7. Just make sure you install openjdk7-src as Java sources are not (yet) in the dependencies of the android-studio package from the AUR.
The Following User Says Thank You to stammler For This Useful Post: [ View ]
19th June 2013, 06:18 PM   |  #7  
GermainZ's Avatar
OP Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,333
 
5,910 posts
Join Date:Joined: Aug 2012
More
Quote:
Originally Posted by stammler

Thanks for putting this up, I landed on this after following the link in the Arch wiki.

I have a suggestion concerning point 3 (python). Wouldn't it be more sane to use python's virtualenv to set up a python distro for Android?

And BTW, I am trying out the new android-studio, which works for me out of the box, even with openjdk7. Just make sure you install openjdk7-src as Java sources are not (yet) in the dependencies of the android-studio package from the AUR.

So basically, create a python 2.7 virtualenv, activate and build from it?
Personally, I find that creating a symlink and adding it to your path (temporary) seems easier and requires no extra tools, but that's up to you. Have you tried it out? Can you please elaborate on why it would be preferable?

Thanks
24th June 2013, 10:34 PM   |  #8  
Guest
Thanks Meter: 164
 
0 posts
Join Date:Joined: Jun 2013
Question
i have to ask, instead of doing all these steps, wouldn't it be easier just to install BBQLinux and change the java version with a purge command and reinstall 1.6 ?
24th June 2013, 10:40 PM   |  #9  
GermainZ's Avatar
OP Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,333
 
5,910 posts
Join Date:Joined: Aug 2012
More
Quote:
Originally Posted by Warped420

i have to ask, instead of doing all these steps, wouldn't it be easier just to install BBQLinux and change the java version with a purge command and reinstall 1.6 ?

Are you suggesting that installing a whole distro on top of the one you use, just to build ROMs, is easier than installing one package, making a symlink and prepending something to your path? Because if you think that's hard, then I must say Arch might be the wrong distro for you.

All these instructions should not take more than 2 minutes, excluding the download time (frankly, I spent most of my time deciding if I should get openjdk6 or java6, then customizing my build script (you can just use a bash profile which virtually takes no time to setup, but I needed some extra stuff)).

That being said, if you want to downgrade, you can also do it using Arch (get openjdk6 from the ARM (Arch Rollback Machine), install it, edit pacman.conf to ignore it - very straightforward to do). The whole point was not to, but you can.
Last edited by GermainZ; 24th June 2013 at 10:44 PM.
24th June 2013, 10:49 PM   |  #10  
Guest
Thanks Meter: 164
 
0 posts
Join Date:Joined: Jun 2013
??
Last edited by Warped420; 24th June 2013 at 11:47 PM.

Post Reply Subscribe to Thread

Tags
arch linux, building, custom rom, java, python
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes