[AT&T, Rogers, Bell, Telus Samsung Galaxy S III] samoled:
How to compile CyanogenMod 10.1 for your Samsung D2ATT​

This post is a copy of the guide found at http://lindroidsoup.com/so-you-want-to-build-android​

It's a compilation of guides I've used along the way. It details the work-arounds I've used to get builds to complete, so I thought it would be nice to share. Special thank you to guys like DesignGears, pmos69, and Task650 for inspiring me to lean more about Android​

Tired of flashing someone else’s ROM? Ready to make your own? Read on!

This tutorial will take you from scratch to ROM with a clean new build of CyanogenMod 10.1 that you can slap on your AT&T SGS III as a daily driver. Once you’ve got the concept down, you’ll be able to change it up and build for whatever you’d like. Let’s take a look at what we’ll need to get going:

_______________________________

PREREQUISITES

Anything less would be uncivilized

Broadband Internet Connection (No, this IS a must. Attempting to sync a repo with dial-up will make your brain explode. Really).

A rooted Samsung Galaxy SIII D2ATT with CyanogenMod 10.1 or newer already flashed on it.

A 64bit Ubuntu 12.04 or later based Linux OS installed on your PC, or in a VM with adequate resources (at least 2 cores and 2-4GB RAM). This guide was written on Kubuntu 13.04, but even Mint works- notes included below.

@50GB of disk space to be used for repo storage and building.

Free Time (@3-6hrs, depending on the chomping power of your PC and the speed of your broadband).

_______________________________

!!!!! DISCLAIMER !!!!!​

This tutorial is posted as a guide for the adventurous who are eager to learn the basics of compiling a ROM. The procedures detailed here do have the ability to miff up your mobile device if something goes wrong. Since it has now been listed as a warning, you follow this guide at your own risk, and I take absolutely no responsibility for any consequences that result from any mishaps you may encounter.​

Part 1 – Setting Up The Environment

1.1 – Install The Necessary Packages

Copy and paste everything after the prompt symbol (~$) in terminal. A new prompt means a new line:

~$ sudo apt-get install git-core gnupg flex bison python rar original-awk gawk p7zip-full gperf libsdl1.2-dev libesd0-dev libwxgtk2.8-dev squashfs-tools build-essential zip curl libncurses5-dev zlib1g-dev pngcrush schedtool

~$ sudo apt-get install libc6-dev x11proto-core-dev libx11-dev libgl1-mesa-dev mingw32 tofrodos python-markdown libxml2-utils

~$ sudo apt-get install g++-multilib lib32z1-dev ia32-libs lib32ncurses5-dev lib32readline-gplv2-dev gcc-multilib g++-multilib xsltproc

1.2 – Make Sure We Have The Right JAVA

If you try to compile with anything other than JDK 1.6, you’ll receive errors and fail to compile. If you try to download JDK 1.6 from the Oracle site, you’ll have a heck-of-a-time trying to find their archives. Luckily LindroidSoup.com just happens to have a copy of a JDK you can use…

http://lindroidsoup.com/Downloads/jdk-6u35-linux-x64.bin

Once you have the JDK downloaded, make sure you move it into your home directory. Then we’ll need to clear out any other versions of Java installed on the machine.

~$ sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*

Now we’re clear to install the correct JDK.

~$ sudo mkdir -p /opt/java/64 && sudo cp jdk-6u35-linux-x64.bin /opt/java/64

~$ sudo su -

~$ cd /opt/java/64 && chmod +x jdk-6u35-linux-x64.bin

~$ ./jdk-6u35-linux-x64.bin

~$ exit

Now we need to make our first PATH entry. Using your text editor of choice, (I use nano, some use vi, others use gedit…just pick one) we’ll need to add the following to our .bashrc file:

_________________________​

IMPORTANT NOTE FOR LINUX MINT USERS​

If you’re using Linux Mint, you’ll need to make sure you’re editing the .bashrc file located at /etc/bash.bashrc

So if you see a reference to "~/.bashrc", you should replace it with "/etc/bash.bashrc"

Got it? Good.

_________________________​

~$ sudo nano ~/.bashrc

Once the file is opened up, paste in the following at the end of the file, save, and close it.

#Java PATH
export JAVA_HOME=/opt/java/64/jdk1.6.0_35
export PATH=$PATH:$JAVA_HOME/bin

1.3 - Install The Android SDK

Now that we have our JAVA situated, it’s on to installing the Android SDK. Once again, LindroidSoup is your one-stop-shop- hit the link below for the 64bit Linux flavor of the SDK. Make sure to move it to your home directory once it’s downloaded.

http://lindroidsoup.com/Downloads/adt-bundle-linux-x86_64-20130917.zip

Let’s set up our SDK directory, and put the SDK in place.

~$ cd ~

~$ mkdir android && mkdir android/sdk

~$ sudo cp adt-bundle-linux-x86_64-20130917.zip android/sdk

~$ cd android/sdk && unzip adt-bundle-linux-x86_64-20130917.zip

~$ sudo rm -rf adt-bundle-linux-x86_64-20130917.zip && cd adt-bundle-linux-x86_64-20130917/sdk

~$ sudo cp -R platform-tools ../.. && sudo cp -R tools ../..

Now we’ll need to make sure the platform-tools and tools have the proper ownership, or the command “android” won’t work when we invoke it after adding the tools to our PATH.

You’ll need to know your username for this one- it’s pretty easy, but for those new to the scene your username is what you see listed before the “@” symbol in your prompt. For instance, my prompt shows

christopher@Kubuntu13:~$>

So my username is “christopher”. Now we can correct the ownership of the files, just replace each instance of username on both sides of the colons below with your username:

~$ cd ~/android/sdk

~$ sudo chown -R username:username platform-tools && sudo chown -R username:username tools

We can now add the Android SDK to our PATH, and we’ll also need to add an Extra PATH for our Device. Mint users, don’t forget to edit /etc/bash.bashrc, not ~/.bashrc.

~$ sudo nano ~/.bashrc

Once the file is opened up, paste in the following at the end of the file, save, and close it.

#Android PATH
export PATH=$PATH:~/android/sdk
export PATH=$PATH:~/android/sdk/platform-tools
export PATH=$PATH:~/android/sdk/tools

And the Extra PATH for our device. **NOTE** Mint users will edit the same file this time.

~$ sudo nano /etc/udev/rules.d/99-android.rules

#Samsung
SUBSYSTEM==usb, SYSFS{idVendor}==04e8, MODE=0666
SUBSYSTEM==”usb”, ATTRS{idVendor}==”####:####”, SYMLINK+=”android_adb”, MODE=”0666″ GROUP=”plugdev”
TEST==”/var/run/ConsoleKit/database”, \
RUN+=”udev-acl –action=$env{action} –device=$env{DEVNAME}”

Let’s make that file executable, shall we?

~$ sudo chmod +x /etc/udev/rules.d/99-android.rules

Ok, now we’ll need to close our terminal and open a new one to load all the changes we’ve made to this point.

Failure To Close And Open A New Terminal At This Point Will Cause The Android Command To Fail!

Oooh. That looked important. We should make sure we do that then. Close your terminal and open a new one.

Now to install the tools:

~$ android

The “android” command will open up the Android SDK Manager. Make sure that both the “Android SDK Tools” and “Android SDK Platform-Tools” show to be installed. If they don’t show to be, make sure you install them.

Part 2 – Gettin’ That Source Code

2.1 – Installing The Repository

Now comes the part where you’ll need to find something to do for awhile. A long while. We’re going to initialize the repository, and then start the sync process to pull in the majority of the Android Source code you’ll need to compile your ROM- but it’s several gigabytes of data and will take a fair amount of time to sync.

~$ mkdir -p ~/bin

~$ mkdir -p ~/android/system

~$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

~$ chmod a+x ~/bin/repo

And then we can make our PATH entry for the repository. Again- Mint users need to edit /etc/bash.bashrc.

~$ sudo nano ~/.bashrc

Once the file is opened up, paste in the following at the end of the file, save, and close it.

#Repo PATH
export PATH=$PATH:~/bin

We need to close our terminal again, and open another one to load our changes.

Failure To Close And Open A New Terminal At This Point Will Cause The Repo Sync Command To Fail!

Close your terminal and open a new one.

This next batch of commands will start the repo sync.

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. The CM manifests include a sensible default configuration for repo, which they strongly suggest you use (i.e., don’t add any options to sync). For reference, their current default values are -j4, and -c. The “-j4” part means that there will be four simultaneous threads/connections. If you experience problems syncing, you can lower this to -j3 or -j2. “-c” will ask repo to pull in only the current branch, instead of the entire CM history.​

~$ cd ~/android/system

~$ repo init -u git://github.com/CyanogenMod/android.git -b cm-10.1

~$ repo sync -j4

2.2 – Grab The Device Code

Now that we have the Android Source Code, we need to pull in the code specifically for the D2ATT. We’re going to be pulling specifically from CyanogenMod’s Github, so you’ll need to make sure git is configured correctly on your machine- if their github doesn’t know who you are, you get no git! Make sure to enter you own info when configuring git. (NOTE- Those are double dashes in front of "global". Not sure why, but universally text boxes don't seem to like them, and don't display them correctly)

~$ git config –global user.name (firstname.lastname)

~$ git config –global user.email (youremail@provider.com)

Just so no one is confused, it should read like the following:

~$ git config –global user.name john.doe

~$ git config –global user.email johndoe@gmail.com

Now we can use git to pull in the device code:

~$ git clone https://github.com/CyanogenMod/android_device_samsung_d2att.git -b jellybean device/samsung/d2att

~$ git clone https://github.com/CyanogenMod/android_kernel_samsung_d2.git -b jellybean kernel/samsung/msm8960

Now we can get the prebuilts from CyanogenMod as well:

~$ cd ~/android/system/vendor/cm && ./get-prebuilts

2.3 - Breakfast

Now that we have all our device specific code from both the Android and CyanogenMod repo’s, we can setup our environment and make breakfast.

~$ cd ~/android/system

~$ source build/envsetup.sh

~$ breakfast d2att

2.4 - Extracting The Blobs

The manufacturer “blobs” are kind of like a PC’s device drivers. You have to have the specific ones for the phone’s hardware, or your ROM probably won’t do important stuff- like showing anything on the display… Let’s go get them.

Now, we have two separate ways of going about this:

Option 1 –

Connect your phone to your pc via usb. You’ll need to make sure you have “UserDebug” mode enabled, as well as “Root Access for Apps and ADB” under the Developer Options of the phone.

~$ cd ~/android/system/device/samsung/d2att

~$ ./extract-files.sh

Option 2 –

Extract them from an existing CyanogenMod ROM. You’ll need to make sure you have a current copy of a CyanogenMod Nightly ROM downloaded and extracted, and you’ll need to know the path to it.

CyanogenMod Nightlies can be found here: http://download.cyanogenmod.org/?type=nightly&device=d2att

~$ cd ~/android/system/device/samsung/d2att

~$ ./extract-files.sh path/to/your/extracted/ROM

Just so everyone is clear, if I extracted my nightly ROM inside my Downloads folder- my command for Option 2 would look like this:

~$ ./extract-files.sh /home/christopher/Downloads

Wow, this is exciting. We’re almost ready to build, but first we make our last PATH entry- adding our toolchain. This step is important, because it’s the only PATH entry that has your username in it. You remember getting your username earlier, don’t you? Good!

Mint users, same old song and dance- make sure you’re editing the .bashrc file at /etc/bash.bashrc.

~$ sudo nano ~/.bashrc

Once the file is opened up, paste in the following at the end of the file, save, and close it:

#Android Toolchain PATH
export ARCH=arm
export CCOMPILE=$CROSS_COMPILE
export CROSS_COMPILE=arm-eabi-
export PATH=$PATH:/home/(YOUR-USERNAME-HERE)/android/system/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin

Save that file, close it, and then close and open a new terminal to load our changes. For the last time.

Failure To Close And Open A New Terminal At This Point Will Cause The Brunch Command To Fail!

Close your terminal and open a new one.

Part 3 – BUILD ANDROID

Fire up that terminal one more time:

~$ cd ~/android/system

~$ . build/envsetup.sh && brunch d2att

And watch it go. Go grab yourself a stimulating beverage- this is gonna take awhile.

Once everything wraps up, you should see a nice neat “Package Complete” message in your terminal window. Congratulations! Now go flash it- you know you wanna!

Don’t forget to grab the latest version of GAPPS if you want your Google Apps!

BONUS SECTION!!!

Q.- What the hell do I do if the build breaks!?!?

A.- This is a very valid question, although if you followed the guide you shouldn’t run into any issues- but these things happen. Google is your friend when all else fails, but here are some common occurences:

ERROR: signapk.jar failed: return code 1make: *** [out/target/product/d2att/cm_d2att-ota-eng.root.zip] Error 1

Change the following in your system/build/tools/releasetools/common.py file:

Change: “java -Xmx2048m” to “java -Xmx1024m” or “java -Xmx512m”

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.

DOUBLE BONUS SECTION!!!

How do I make an update?

So glad you asked. So glad I saw that I left this out initially, and now I’m putting it in here…

To the terminal we go:

~$ cd ~/android/system

~$ repo sync -j4

~$ make installclean

~$ find ./out/ -name 'build.prop' | xargs rm

~$ find ./out/ -name 'cm_d2att-target_files-eng.*.zip' | xargs rm

~$ . build/envsetup.sh && brunch d2att

Just flash that update right on top of your already flashed build, and it will update it.

Again, Google is your friend.

Cheers