转自http://forum.xda-developers.com/showthread.php?t=1552090
Building CM9 From Source On The Epic 4G
I just recently built CM9 for the Epic 4G since Contacts.apk and the Honeycomb Ripple Lockscreen Mod need to be built from source to work properly on our phones. If you follow my instructions exactly, you should have a working CM9 build for the Epic 4G. You can then modify whatever you need to customize your apks, jar files, etc.
Now lets get started. You will need to install Ubuntu 11.10 64-Bit on your computer. It can be a virtual machine, an install using Wubi, or an actual partition for Ubuntu. You will need at least 30gb available for Ubuntu since the repository and the build take up a lot of space.
(Note: It Must Be Ubuntu 11.10 64-Bit And Have A Working Internet Connection!)
Install Java JDK
Once Ubuntu is installed the first thing you will need to do is install Java JDK. Open up a terminal or press Ctrl+Alt+T on the keyboard and copy the following commands:
Code:
sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-plugin
After the first command is entered, it will ask you for your password. Enter it and continue with the commands. Once Java is about to install, it will tell you how much additional disk space Java will add to your hard drive and ask if you want to continue. Press Y and hit Enter. When Java is done installing, you should see a window that pops up with the Java Licensing Agreement. Use the arrow keys or the Tab key on your keyboard to navigate to the OK button and press Enter. Then Navigate to Yes and hit Enter again. Java is now installed on your Computer!
Install Android SDK For Linux
Next, you will need to install android sdk. Google search android sdk and it should be the first link that pops up. Click on it and download android-sdk_r18-linux.tgz for Linux. Now go back to your terminal and enter the following commands:
Code:
cd Downloads
tar -xvzf android-sdk_r18-linux.tgz
rm *.tgz
mv android-sdk-linux/ ..
cd ../android-sdk-linux/
In case you don't know what you just did, you navigated to your Downloads folder and extracted the android-sdk-linux folder. Then you deleted the compressed file and moved your android-sdk-linux folder to your Home directory. Finally, you navigated to your android-sdk-linux folder.
Now we need to open the Android SDK Manager and download the necessary packages. In the terminal, copy:
It should pop up the Android SDK Manager. Now make sure the Tools folder, and Android 4.0.3 (API 15) packages are selected and click on Install Packages. Check Accept All and click on Install. Once all the packages have been loaded, close out of the Download window and the Android SDK Manager. Go back to your terminal and Type:
This will navigate you back to your Home Directory.
The Rest Of The Guide Will Need To Be Done In The Root Terminal!
In the terminal type:
Then enter your password. You are now logged in as root! (Or superuser)
Install Packages
Now we need to install all the necessary packages to make the CM9 build. In the terminal, copy:
Code:
apt-get install python git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline-gplv2-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils libsdl1.2-dev libesd0-dev libwxgtk2.6-dev squashfs-tools build-essential pngcrush schedtool gcc-multilib
Again, press Y and hit Enter.
Configuring USB
Time to set up all devices to work with USB.
Code:
gksudo gedit /etc/udev/rules.d/51-android.rules
This will create a new file to configure the USB devices. Copy and paste this into the file:
Code:
#Acer
SUBSYSTEM==usb, SYSFS{idVendor}==0502, MODE=0666
#ASUS
SUBSYSTEM==usb, SYSFS{idVendor}==0b05, MODE=0666
#Dell
SUBSYSTEM==usb, SYSFS{idVendor}==413c, MODE=0666
#Foxconn
SUBSYSTEM==usb, SYSFS{idVendor}==0489, MODE=0666
#Garmin-Asus
SUBSYSTEM==usb, SYSFS{idVendor}==091E, MODE=0666
#Google
SUBSYSTEM==usb, SYSFS{idVendor}==18d1, MODE=0666
#HTC
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE=0666
#Huawei
SUBSYSTEM==usb, SYSFS{idVendor}==12d1, MODE=0666
#K-Touch
SUBSYSTEM==usb, SYSFS{idVendor}==24e3, MODE=0666
#KT Tech
SUBSYSTEM==usb, SYSFS{idVendor}==2116, MODE=0666
#Kyocera
SUBSYSTEM==usb, SYSFS{idVendor}==0482, MODE=0666
#Lenevo
SUBSYSTEM==usb, SYSFS{idVendor}==17EF, MODE=0666
#LG
SUBSYSTEM==usb, SYSFS{idVendor}==1004, MODE=0666
#Motorola
SUBSYSTEM==usb, SYSFS{idVendor}==22b8, MODE=0666
#NEC
SUBSYSTEM==usb, SYSFS{idVendor}==0409, MODE=0666
#Nook
SUBSYSTEM==usb, SYSFS{idVendor}==2080, MODE=0666
#Nvidia
SUBSYSTEM==usb, SYSFS{idVendor}==0955, MODE=0666
#OTGV
SUBSYSTEM==usb, SYSFS{idVendor}==2257, MODE=0666
#Pantech
SUBSYSTEM==usb, SYSFS{idVendor}==10A9, MODE=0666
#Philips
SUBSYSTEM==usb, SYSFS{idVendor}==0471, MODE=0666
#PMC-Sierra
SUBSYSTEM==usb, SYSFS{idVendor}==04da, MODE=0666
#Qualcomm
SUBSYSTEM==usb, SYSFS{idVendor}==05c6, MODE=0666
#SK Telesys
SUBSYSTEM==usb, SYSFS{idVendor}==1f53, MODE=0666
#Samsung
SUBSYSTEM==usb, SYSFS{idVendor}==04e8, MODE=0666
#Sharp
SUBSYSTEM==usb, SYSFS{idVendor}==04dd, MODE=0666
#Sony Ericsson
SUBSYSTEM==usb, SYSFS{idVendor}==0fce, MODE=0666
#Toshiba
SUBSYSTEM==usb, SYSFS{idVendor}==0930, MODE=0666
#ZTE
SUBSYSTEM==usb, SYSFS{idVendor}==19D2, MODE=0666
Save the file and close the window. Next set the permissions for the file you just created:
Code:
chmod a+r /etc/udev/rules.d/51-android.rules
Installing Repo
Next, we need to install the CM9 repository.
Code:
mkdir ~/bin
gedit /etc/environment
This will open up your Environment Variables so you can use adb and other commands no matter what directory you're in.
Copy and paste this into the end of the file:
Code:
:/home/gooch/android-sdk-linux/tools:/home/gooch/android-sdk-linux/platform-tools:/root/bin
Replace gooch with your Username that you set up and make sure to leave the quotes! It should look like one big line.
Now Logout and Log back in! This will update your Environment Variables.
Once you're logged back in, open up the terminal and log back in as root:
Enter your password and then copy the following commands:
Code:
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
mkdir CM9
cd CM9
repo init -u git://github.com/CyanogenMod/android.git -b ics
repo sync
These commands will set everything up and download the CM9 repository. (This will take a long time to download!)
(Note: If your download freezes or hangs, close the terminal and open up a new one. Log back into root and repeat these steps)
This will continue where you left off. Once everything is synced, enter in the terminal:
This will open up a root file explorer. navigate to the CM9/device/samsung folder and see if there is a folder called "epicmtd". If there is, skip to Copy Proprietary Files. If not, close the file explorer and type:
This should gather the epicmtd folder for you. If it starts to build, exit the terminal Immediately!
Open another terminal, log into root, and open up the root file explorer again:
Check if the "epicmtd" is there again. If it's there, Navigate back to the CM9 folder and then navigate to the out/target/product folder. If there is a folder called "epicmtd", delete it and close the root file explorer.
Copy Proprietary Files
Next you need to download the proprietary files from your phone. You must have a working CM9 ROM currently on your phone. Make sure USB Debugging is on and plug your phone into your computer. (You can find this under Settings-Developer Options-USB Debugging)
In the terminal, navigate the the "CM9" folder if you're not already there:
Then copy the following commands:
Code:
cd device/samsung/epicmtd
./extract-files.sh
This will gather all the necessary files needed from your phone. Once this is finished, navigated back to the "CM9" folder by entering:
Now enter:
Code:
vendor/cm/get-prebuilts
(Note: The whole "Copy Proprietary Files" step only needs to be done once to set everything up!)
Build Source
Finally, We can build the CM9 Source Code.
In the terminal, copy the commands:
Code:
. build/envsetup.sh
brunch epicmtd
This will take a while, but if you set up everything correct, you should have a working, flashable CM9 ROM in the CM9/out/target/product/epicmtd folder. The .zip is called something like "update-cm-9.0.0-RC0-epicmtd-KANG-signed".
Copy that to your phone's SD Card and reboot into recovery mode. Wipe user data, cache, and dalvik cache, and flash. If it installs and your phone boots up with CM9, You just made a successful build!
You can delete the "epicmtd" folder created in the CM9/out/target/product directory by running in CM9 directory:
Now you can modify the Source Code, and build again by issuing these two simple commands:
Code:
. build/envsetup.sh
brunch epicmtd