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-androidIt'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:
Code:
~$ 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.
Code:
~$ sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
Now we’re clear to install the correct JDK.
Code:
~$ 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 USERSIf 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.
_________________________
Code:
~$ sudo nano ~/.bashrc
Once the file is opened up, paste in the following at the end of the file, save, and close it.
Code:
#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.
Code:
~$ 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
Code:
[email protected]:~$>
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:
Code:
~$ 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.
Code:
~$ sudo nano ~/.bashrc
Once the file is opened up, paste in the following at the end of the file, save, and close it.
Code:
#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.
Code:
~$ sudo nano /etc/udev/rules.d/99-android.rules
Code:
#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?
Code:
~$ 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:
Code:
~$ 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.
Code:
~$ 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.
Code:
~$ sudo nano ~/.bashrc
Once the file is opened up, paste in the following at the end of the file, save, and close it.
Code:
#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.
Code:
~$ 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)
Code:
~$ git config –global user.name (firstname.lastname)
~$ git config –global user.email ([email protected])
Just so no one is confused, it should read like the following:
Code:
~$ git config –global user.name john.doe
~$ git config –global user.email [email protected]
Now we can use git to pull in the device code:
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:
Code:
~$ 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.
Code:
~$ 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.
Code:
~$ 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
Code:
~$ 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:
Code:
~$ ./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.
Code:
~$ sudo nano ~/.bashrc
Once the file is opened up, paste in the following at the end of the file, save, and close it:
Code:
#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:
Code:
~$ 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:
Code:
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:
Code:
~$ 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
Automated ROM update script!!!
Want to make updating your ROM super easy? Not a problem! Download the following 'buildromupdate.sh' script from Lindroidsoup.com, or simply use a text editor to copy and paste the following! Don't forget to 'chmod +x' and make it executable- then just run it from the command line with ~$ ./buildromupdate.sh -It doesn't get much easier!
Code:
#!/bin/bash
# This script will clear out old files, and update your ROM
# Flash this updated .zip on top of your existing ROM
# You should see 'Android is updating' on next boot
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
Download the script: http://lindroidsoup.com/Downloads/buildromupdate.sh
Cheers!
I have moved your thread to general, as typically users will find guides here. I am sorry for any inconvenience.
Lindroidsoup.com will be down for maintenance on 10/16/2013
LindroidSoup.com will be down for maintenance on 10/16 - 10/19
We apologize for any inconvenience this may cause, and are providing the direct links for both the Android SDK and Java JDK below:
Java JDK 1.6.35- http://download.oracle.com/otn/java/jdk/6u35-b10/jdk-6u35-linux-x64.bin
Android SDK- http://developer.android.com/sdk/index.html#linux-bundle
The server will be up and operational again on 10/19/2013.
Lindroidsoup.com completed maintenance ahead of schedule
LindroidSoup.com is back online!
We're pleased to announce that the wonderful team at KnownHost, LLC was able to finish site/server maintenance well ahead of schedule, and we're now back online!
Linux Mint Users Note
If you're a Linux Mint user, just a handy little note-
Mint is notorious for over-writing /etc/bash.bashrc when major system updates are pushed out. This becomes a pain in the ass when your PATHs keep getting over-written and you receive errors when trying to build an update after you've set everything up.
To work around it, just make a copy of your /etc/bash.bashrc file- and then put it back in place if you see the original's been over-written:
To make a backup of /etc/bash.bashrc after initial setup
Code:
~$ sudo cp /etc/bash.bashrc /home/bash.bashrc.backup
To replace an over-written /etc/bash.bashrc after a system update
Code:
~$ sudo rm -rf /etc/bash.bashrc && cp /home/bash.bashrc.backup /etc/bash.bashrc
That should keep you from pulling your hair out!
Cheers
Damn it, Google!!!
Google changed the storage location of their repo code, so trying to download it was causing a '/bin/repo: line 1: syntax error near unexpected token `newline'' error.
I've adjusted the guide to reflect the new storage location for the curl command.
Sorry if this caused anybody any headaches.
Regards,
C
Any guide for Windows? If not is it cool to develop via a VMware image of Linux?
drivel2787 said:
Any guide for Windows? If not is it cool to develop via a VMware image of Linux?
Click to expand...
Click to collapse
Yes, using a vm is fine
Slithering from the nether regions of a twisted mind and tarnished soul
Hello, I am on ubuntu 14.4 and I am trying to build CM-12. When the rom is building, it keep stoppinig at the following error;
target R.java/Manifest.java: com.android.emailcommon (/home/larmyv/android/system/out/target/common/obj/JAVA_LIBRARIES/com.android.emailcommon_intermediates/src/R.stamp)
/home/larmyv/android/system/out/host/linux-x86/bin/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
make: *** [/home/larmyv/android/system/out/target/common/obj/JAVA_LIBRARIES/com.android.emailcommon_intermediates/src/R.stamp] Error 127
make: *** Waiting for unfinished jobs....
Any Ideas? Any help would be greatly appreciated.
Thanks
LARMYV said:
Hello, I am on ubuntu 14.4 and I am trying to build CM-12. When the rom is building, it keep stoppinig at the following error;
target R.java/Manifest.java: com.android.emailcommon (/home/larmyv/android/system/out/target/common/obj/JAVA_LIBRARIES/com.android.emailcommon_intermediates/src/R.stamp)
/home/larmyv/android/system/out/host/linux-x86/bin/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
make: *** [/home/larmyv/android/system/out/target/common/obj/JAVA_LIBRARIES/com.android.emailcommon_intermediates/src/R.stamp] Error 127
make: *** Waiting for unfinished jobs....
Any Ideas? Any help would be greatly appreciated.
Thanks
Click to expand...
Click to collapse
Sounds like you're running into this: http://ideid.blogspot.co.uk/2013/01/resolve-shared-library-problem-with.html
Give it a shot, and let me know what you get.
samoled said:
Sounds like you're running into this: http://ideid.blogspot.co.uk/2013/01/resolve-shared-library-problem-with.html
Give it a shot, and let me know what you get.
Click to expand...
Click to collapse
Thank you so much, i was looking for days on the error. When I put in the following command;
sudo apt-get install ia32-libs
it gave me an error that said that it was no longer available. It said to download the following;
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0
I downloaded those packages and i am now in business and have finally built a rom. Now I am learning on the whole cherry picking.
Thanks again.
Awesome, glad to hear you got that sorted out.
Let me know if you run into anything else.
samoled said:
Awesome, glad to hear you got that sorted out.
Let me know if you run into anything else.
Click to expand...
Click to collapse
Hi, I have a new question for you. I am currently building slim roms and I have an issue with the kernel. The phone will boot up but would be stuck on the samsung logo screen. My question to you is how do I port over the CM12 kernel and merge it with the slim rom?
Build LineageOS 14.1 for the AT&T Samsung Galaxy SIII (d2att)
on Windows with VirtualBox and Ubuntu 16.04
VirtualBox and Ubuntu 16.04 Desktop
Download and install VirtualBox from their website for your computer.
Download Ubuntu 16.04 Desktop from their website
(Make sure you have hundreds of gbs free storage space on your computer)
Run VirtualBox and click on the new button
Click on expert mode
Type a name into the space provided
Choose linux for type
Make memory size about 4600 mbs
Tic Make a virtual hard drive now
Make file size about 320GB
Tic vdi and tic Dynamically allocated
Click create
Click on the start button
Browse to the save location of the ubuntu 16.04 .iso when it pops up
Click on it and then click open
Follow all the on screen installation instructions
After installation move on to setting up the build environment
Setting up the build environment, Getting the Proprietary files, and compiling the ROM
Right click mouse on the desktop and highlight Open terminal left click
type in
sudo apt-get install android-sdk-platform-tools bc build-essential ccache curl g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libwxgtk3.0-dev libxml2 libxml2-utils lzop m4 openjdk-8-jdk pngcrush repo rsync schedtool squashfs-tools xsltproc zip zlib1g-dev (press enter)
(Type your password when prompted and press enter)
type in
sudo add-apt-repository ppapenjdk-r/ppa (press enter)
(smiley face is a comma and an o no spaces)
type in
sudo apt-get update && sudo apt-get install openjdk-8-jdk (press enter)
type in
mkdir -p ~/bin (press enter)
type in
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo (press enter)
type in
mkdir -p ~/android/lineage && cd android/lineage (press enter)
type in
repo init -u https://github.com/LineageOS/android.git -b cm-14.1 (press enter)
type in
repo sync (press enter)
(this takes a long time)
(Errors can be met with repo sync --force-sync, repo sync -f, repo sync --force-broken, repo sync -j1 -f --force-sync, repo sync -l )
when it finishes
type in
source build/envsetup.sh (press enter)
type in
breakfast d2att (press enter)
when it finishes close and reopen terminal
Extract the proprietary blobs
(get .zip of a rom that is for the phone put it in the downloads folder and rename it blobs.zip)
type in
mkdir ~/android/system_dump/ (press enter)
type in
cd ~/android/system_dump/ (press enter)
type in
unzip ~/Downloads/blobs.zip system.transfer.list system.new.dat (press enter)
type in
git clone https://github.com/xpirt/sdat2img (press enter)
type in
python sdat2img/sdat2img.py system.transfer.list system.new.dat system.img (press enter)
type in
mkdir system/ (press enter)
type in
sudo mount system.img system/ (press enter)
(type in your password when prompted and press enter)
close terminal and open again
type in
cd ~/android/lineage/device/samsung/d2att (press enter)
type in
./extract-files.sh ~/android/system_dump/ (press enter)
type in
sudo umount ~/android/system_dump/system (press enter)
(type in password when prompted and press enter)
close terminal and reopen
type in
rm -rf ~/android/system_dump/ (press enter)
type in
cd ~/android/lineage (press enter)
type in
gedit ~/.bashrc (press enter)
Add this to the bottom of the file
export USE_CCACHE=1
export USE_NINJA=false
export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4G"
export CCACHE_COMPRESS=1
save and close the file (The save button is in the upper right hand corner)
type in
export USE_CCACHE=1 (press enter)
type in
ccache -M 50G (press enter)
type in
export CCACHE_COMPRESS=1 (press enter)
type in
source ~/.bashrc (press enter)
type in
source build/envsetup.sh (press enter)
type in
breakfast d2att (press enter)
type in
croot (press enter)
type in
brunch d2att (press enter)
The build takes a while to compile. My experience was 12 hours.
When the build does finnish the new ROM .zip will be in your ~/android/lineage/out/target/product/d2att folder (I uploaded mine to dropbox so i could retrieve it from Ubuntu onto the device. I've not been able to get adb working) All thats left is to flash the ROM.