[G2 and Desire Z Android Development] teh5abiking:
Hello, fellow xda members. I'm teh5abiking and I'm gonna be showing you how to set up the Android SDK AND how to compile CyanogenMod.

Please note that we're gonna be doing a fair amount of work in the command line, and if you're not comfortable with using the command line, setting up the Android SDK and/or compiling CyanogenMod probably isn't for you.

This tutorial covers setting up the Android SDK and compiling CyanogenMod on Debian and Debian-derivatives (specifically Ubuntu and Linux Mint) I have included links for those of you who wish to set up the Android SDK on other operating systems aside from Ubuntu/Debian/Mint. I've also included a link for people who wish to compile CyanogenMod on Mac OS X instead of Linux.

I have tried to include a link for those of you who wish to set up the SDK on other Linux distributions such as Slackware, Fedora, openSUSE, Mandriva, and so on, however all the websites that I've visited that say they'll teach how to install the SDK on Linux systems in general are really for Ubuntu/Mint. Therefore, I'm sad to say that you'll have to make do with the general instructions on the Android Developer's website. If you're looking for distribution-specific tutorials, you'll have to look it up yourself (sorry :()

I'm also sorry to say that you can't compile CyanogenMod on anything other than Debian (and Debian-derivatives, specifically Ubuntu and Mint) and Mac OS X :(

>

UPDATE:

It IS possible to compile on Fedora. I've only tested on Fedora 15 and Fedora 16, but the process remains largely the same. The only differences there are is in the packages you must install to get things going.

Click me if you want to set up the Android SDK on Windows or Mac OS X, Gentoo Linux, or Arch Linux

Click me if you want to compile CyanogenMod on Mac OS X instead of Ubuntu/Debian/Linux Mint

Click me if you want to set up the SDK on other Linux systems

Prerequisites

-Ubuntu 10.04/10.10/11.04/11.10, Debian 6.0.X/Squeeze (I haven't tested on Lenny, Wheezy, or Sid yet) or Linux Mint installed (Either as VirtualBox, partitioned alongside your main operating system, or written to the entire disk)

-Patience, as the repo sync will take a while.

-A distraction/diversion to help pass the time.

Okay, let's get started shall we?

PART I - SETTING UP THE SDK.

Okay, so first you're gonna need to grab the SDK from the developer's site. If you don't have it, here's the link to the developer's site that contains the SDK: http://developer.android.com/sdk/index.html Download the one for Linux (should be listed as a tgz file.)

Okay, once you've downloaded the SDK, extract it to the home folder, like in the picture that's below (for the tutorial's sake, we're renaming it to androidsdk).

NOTE:

You are required to have Java installed in order to download the SDK platform tools otherwise users who go on without Java *WILL* get a Parse: XML error notice when downloading the SDK platform tools. This requirement has been noted on the "Installing the SDK" portion of the Android Developers website.

Installing Java can go one of two ways. The first way is to download the actual non-free Sun Java implementation by enabling the Canonical Partners repositories in your Software Sources (for Ubuntu users only. Sun Java 6 should be available in Debian's repositories by default across Squeeze, Wheezy, and Sid. Java 5 is available in Lenny's default repositories. Java 6 I believe is available in the Lenny backports. Linux Mint requires no additional configuration as Java comes preinstalled by default.) and downloading it via "apt-get" or Synaptic. If you install Java this way, you'll have to bear through slow download times as the mirrors aren't localized (unless you live in London or something), accepting an EULA, and having to manually maintain the said packages yourself since it's not software Debian or Canonical can support due to licensing issues.

However, the benefit for this is that installing the official Sun Java implementation on your system is that you can compile Android source, which the second post goes more in-depth about. To do so, go to your Software Sources. On Ubuntu 10.04, it's System -> Administration -> Software Sources. On 10.10 and 11.04, it's System -> Administration -> Update Manager -> Settings.

Once you have your software sources open, go to the "Other Software" tab and check off both Canonical Partners repositories. Once you hit the "Close" button, it will tell you your software listings are outdated. Hit "reload" and wait for the software sources menu to close.

IF YOU ARE USING UBUNTU 11.10

: Sun Java is NOT available in the default partner repositories for Oneiric Ocelot. You must add the Lucid partner repository to your /etc/apt/sources.list. Here's how to do it:

Open up a terminal and enter the following:

$ sudo nano -w /etc/apt/sources.list

In the Nano text editor that's been opened up on your terminal, copy and paste the following at the bottom of the file. Once you're done, Press CTRL+X, Y, and then hit Enter.

##Java Repository.
deb http://archive.canonical.com/ lucid partner

Now that your repository information has been changed, execute the following to update your repository information, upgrade your system, and then install the Sun Java packages.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install sun-java6-jre sun-java6-jdk sun-java6-bin

The second way is to download the OpenJDK implementation of Java. This is a bit out of date compared to the official Sun Java, however it should suffice for installing the Android SDK. The benefit for this is that a) It's free software, so that means software updates are supported by Debian and the community (OpenJDK is a part of Ubuntu's 'Universe' repository, meaning that it's community supported software.) b) You don't have to accept an EULA as it's free software. c) Since it's available in the default repositories, downloading it will be as fast as downloading normally. To install the OpenJDK implementation of Java, enter the following command:

sudo apt-get install openjdk-6-jre openjdk-6-jdk icedtea6-plugin

Now we must download the SDK platform tools as they're not included in the .tgz file you downloaded. To do so, we must start the Android SDK and AVD Manager which is located in the tools folder of the Android SDK. You can do this one of two ways, a) You can start up the file manager and manually navigate to the SDK's tools folder OR you can do it via command line. I find executing the Android SDK and AVD Manager from the command line to be easier so that's what we're going to do.

$ cd ~/androidsdk/tools
$ ./android

Click on "Available Packages" in the new window that pops up. Now, you have two options:

-Check off the first box and install all the SDK platform tools and nothing more. so we can progress with the tutorial.

-Check off both boxes so you install both the SDK platform tools and the third-party add-ons.

I recommend installing just the SDK platform tools, since it's quicker to do it like that, and the adb protocol is in the first repository, and that's what we're after. But you can do it in any way you chose. After choosing whether or not you want to install the SDK platform-tools along with the third-party add-ons, click on "Install Selected" then "Accept All" in the window that pops up and finally click on "Install." It's quite a bit to download (3.1 GB to be exact) if you download both the SDK platform tools and the third-party add-ons, but that gives us some time to get other stuff done.

UPDATE: The SDK and AVD manager has been updated as of SDK r15. Installation of Packages remains largely the same, sans for how you choose the repositories.

While we're downloading the SDK platform tools we have some work to do. See, we're gonna need to make use of ADB, and we can't set up our CM7 stuff in the platform-tools directory. Time to get nerdier :cool:

I find it tedious and messy to put stuff in the platform-tools directory every time I wanna do something like root a phone, so what we're gonna do is edit our PATH variable so that we can execute ADB from

ANY

location. With the terminal window that I hope you've kept open all this time, let's enter another command:

$ nano -w .bashrc

OR

$ gedit .bashrc

It'll open up a text editor, and it's showing us our .bashrc file. At the top of the .bashrc file, copy and paste the following:

#AndroidDev PATH
export PATH=${PATH}:~/androidsdk/tools
export PATH=${PATH}:~/androidsdk/platform-tools

NOTE:

As there is no "~/.bashrc" file included in Linux Mint, you must do the following to make sure it's executable.

$ chmod a+x ~/.bashrc

After you're finished, it should look like this:

Save your changes. (Nano users, just press CTRL+X, Y, and Enter. Gedit users, just click on File and then click on 'Save')

Now that we've got our SDK ready (for the most part), it's time to set up udev.

udev is the USB 'driver' for Linux, allowing your computer to talk to the device when using adb or fastboot. Just like how you needed drivers for Windows to make ADB work, the same principles apply to Linux, albeit in a different form. So, in that terminal window (That I hope you have kept open all this time) Enter the following, so we can locate and edit the file that our udev rules need.

$ gksudo gedit /etc/udev/rules.d/51-android.rules

.

OR

$ sudo nano -w /etc/udev/rules.d/51-android.rules

Once you've done that, copy the udev rules that are below and paste them into the rules file, as shown below.

SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0666"
SUBSYSTEM==”usb”, ATTRS{idVendor}==”18d1″, SYMLINK+=”android_adb”, MODE=”0666″
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666", GROUP="plugdev

It should be like in the picture below

Save all your changes (Nano: CTRL+X, Y, and hit Enter. Gedit: File, Save As), and then reboot otherwise adb won't be in your path.

NOTE:

Debian and Mint users MUST execute the following as root, otherwise udev will fail to recognize your device. If ADB won't recognize your device, execute the following as root:

$ chmod a+r /etc/udev/rules.d/51-android.rules

Once you do that, let's verify the success of our efforts, so open up a terminal (CTRL + ALT + T or Applications -> Accessories -> Terminal) and enter the following:

$ adb devices

You should get something like in the picture below.

Congratulations, you've set up the Android SDK! If you just wanted the SDK, you can stop here.

I have adapted this from multiple sources, however the sources that I've used the most in this tutorial are from Ubuntu's wonderful community-contributed documentation.

COMMUNITY UBUNTU DOCUMENTATION FOR INSTALLING THE ANDROID SDK

COMMUNITY UBUNTU DOCUMENTATION ON INSTALLING JAVA

If you want to learn how to compile one of the most popular custom ROMs for Android, read the next post to learn how.