[HTC Wildfire S] benjamingwynn:
TUTORIAL:How to build CM9 from source using Ubuntu 11.10

NOTE: I am always changing this tutorial to be more advance and easier, what you see one day may be changed the next so be careful!

1. Grab yourself a copy of 64-bit Ubuntu 11.10 -

You can try and use 12.04 but it is very unstable and extra steps are needed.

2. In terminal type in the following lines to grab the required sources for donwloading the packages:

sudo add-apt-repository ppa:ferramroberto/java; sudo apt-get update

3. Type in the following into terminal, this allows ubuntu to gather the needed packages to build CM9. You will be asked for a password, if you get a question asking if you would like to install all of the packages type Y and hit enter.

sudo apt-get install git-core gnupg flex bison gperf libesd0-dev libwxgtk2.6-dev squashfs-tools build-essential zip curl libncurses5-dev zlib1g-dev sun-java6-jdk pngcrush schedtool g++-multilib lib32z1-dev lib32ncurses5-dev libc6-dev ia32-libs x11proto-core-dev lib32z-dev mingw32 tofrodos python-markdown python python-lunch libxml2-utils xsltproc libx11-dev:i386

4. To download a needed stack on top of git for developing CM we need to type the following command...

mkdir ~/bin; curl [url]https://dl-ssl.google.com/dl/googlesource/git-repo/repo[/url] > ~/bin/repo; chmod a+x ~/bin/repo

5. Download this: http://dl.google.com/android/android-sdk_r18-linux.tgz and this: http://dl.google.com/android/ndk/android-ndk-r7c-linux-x86.tar.bz2 - These are the NDK and SDK, native development kit and software development kit.

6. Open your file manger and make a folder inside your home folder, call it "android".

7. Make the folders "sdk" and "ndk" inside it

8. Extract all of the stuff from "android-ndk-r7c-linux-x86.tar.bz2" into NDK and all the stuff from "android-sdk_r18-linux.tgz" to SDK.

10. Type in the following line to open a text document

sudo gedit .bashrc

11. Add the following lines to the bottom of the script - this changes you "path" so you can run scrips from these places as normal linux commands anywhere else on your system

# Android Software
export PATH=${PATH}:~/android/sdk/tools
export PATH=${PATH}:~/android/sdk/platform-tools
export PATH=${PATH}:~/android/ndk/android-ndk-r7/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin
export PATH=${PATH}:~/bin

13. Save and exit, then type the following lines to make a folder and bring you into it

mkdir -p ~/cyanogenmod/system; cd ~/cyanogenmod/system

14. Now type in these next lines to set another (fallback) path and inizalize the CM repo in that folder

PATH=~/bin:$PATH; repo init -u git://github.com/CyanogenMod/android.git -b ics

15. Now enter the following command

gedit .repo/local_manifest.xml

to open up another text document, in this document - it will be empty, add these lines then save and exit

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="cryptomilk"
fetch="git://git.cryptomilk.org/" />

<project name="CyanogenMod/android_device_htc_common" path="device/htc/common" revision="refs/heads/gingerbread" />
<project name="projects/marvel/android_device_htc_marvel.git" path="device/htc/marvel" remote="cryptomilk" />
<project name="projects/marvel/android_vendor_htc_proprietary.git" path="vendor/htc" remote="cryptomilk" />
<project name="projects/marvel/kernel_htc_msm7227.git" path="kernel/htc/msm7277" remote="cryptomilk" />
<project name="benjamingwynn/cm9-marvel-flaming-fixes" />
</manifest>

16. If you do not wish to download pointless files for different devices then type in

gedit .repo/manifest.xml

and delete the following lines (thanks to dudeman1996 for this protip)

<project path="device/moto/common" name="CyanogenMod/android_device_moto_common" />
<project path="device/moto/stingray" name="CyanogenMod/android_device_moto_stingray" />
<project path="device/moto/wingray" name="CyanogenMod/android_device_moto_wingray" />

aswell as these other lines

<project path="device/samsung/maguro" name="CyanogenMod/android_device_samsung_maguro" />
<project path="device/samsung/p5-common" name="CyanogenMod/android_device_samsung_p5-common" />
<project path="device/samsung/toro" name="CyanogenMod/android_device_samsung_toro" />
<project path="device/samsung/tuna" name="CyanogenMod/android_device_samsung_tuna" />

17. Now to preform the first sync with CM type in the following.. -- This will take a long time! so don't be worried if you think it's taking a while. If for whatever reason you need to stop the sync then hit CTRL+Z on your keyboard.

repo sync

18. You must now setup the vendor, type:

./vendor/cm/get-prebuilts

19. Set up the environment by typing the following to tell ubuntu that you are going to be making CM9.

source build/envsetup.sh; lunch cm_marvel-eng

20. Type the following to prepare use the cache for stuff

export USE_CCACHE=1

21. Now, finally build CM9. To do this I always times the number of cores in your CPU by two. For example on a 4 core machine I would put 8. Once you have worked that out type the following where xx is your number.

make -jxx bacon

22. If sucessful, you will get something like this:

Package complete: /home/benjamin/cyanogenmod/system/out/target/product/marvel/update-cm-9.0.0-RC0-marvel-UNOFFICIAL-signed.zip

Go to that folder and copy and paste the zip file above to your phone, install in recovery.

FAQ

People like asking the same god damn questions over and over again.

Q. Could you please help me it says the bits

A. That doesn't make any sense. Try and copy some lines from terminal

Q. Could you help please, It says these lines when I "repo sync"

Fetching projects: 100% (249/249), done.
Syncing work tree: 95% (237/249) fatal: cannot create directory at 'eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors': No space left on device
Traceback (most recent call last):
File "/home/benjamin/cyanogenmod/system/.repo/repo/main.py", line 385, in
_Main(sys.argv[1:])
File "/home/benjamin/cyanogenmod/system/.repo/repo/main.py", line 365, in _Main
result = repo._Run(argv) or 0
File "/home/benjamin/cyanogenmod/system/.repo/repo/main.py", line 137, in _Run
result = cmd.Execute(copts, cargs)
File "/home/benjamin/cyanogenmod/system/.repo/repo/subcmds/sync.py", line 467, in Execute
project.Sync_LocalHalf(syncbuf)
File "/home/benjamin/cyanogenmod/system/.repo/repo/project.py", line 1027, in Sync_LocalHalf
self._InitWorkTree()
File "/home/benjamin/cyanogenmod/system/.repo/repo/project.py", line 1814, in _InitWorkTree
raise GitError("cannot initialize work tree")
error.GitError: cannot initialize work tree

A. Your disk drive is full. Free some stuff up and try again

Q. Could you help please...

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

Your version is: java version "1.6.0_24".
The correct version is: Java SE 1.6.

Please follow the machine setup instructions at
http://source.android.com/source/download.html
************************************************************
grep: build/target/board/generic/recovery.fstab: No such file or directory
build/core/java.mk:20: *** dalvik/dexgen: Invalid LOCAL_SDK_VERSION '4' Choices are: current . Stop.

A. You have a slightly different version of Java for some reason, try the following...

sudo -i
[[enter password]]
apt-get remove openjdk-6-jdk
apt-get remove sun-java6-jdk
add-apt-repository "deb http://archive.canonical.com/ lucid partner"
apt-get update
apt-get upgrade
sudo apt-get install sun-java6-jdk
sudo update-alternatives --config java
[[select the sun one]]
exit

if that doesn't work then try

Q. I downloaded Ubuntu 12.04 instead, it's not working! Do you have a quick work-around?

A. First type in

sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev:i386 \
g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown \
libxml2-utils xsltproc zlib1g-dev:i386
to get the extra packages.

Then type "sudo gedit /usr/include/linux/usb/ch9.h" and on line 592 replace

return __le16_to_cpu(epd->wMaxPacketSize);

with

# return le16_to_cpu(epd->wMaxPacketSize);
return __le16_to_cpu(epd->wMaxPacketSize);

Q. I get this error

benjamin@benjamin-Sienna-510:~/cyanogenmod/system$ lunch cm_marvel-eng
build/core/product_config.mk:189: *** _nic.PRODUCTS.[[device/*/marvel/cm.mk]]: "device/*/marvel/cm.mk" does not exist. Stop.
Device marvel not found. Attempting to retrieve device repository from CyanogenMod Github (http://github.com/CyanogenMod).
Repository for marvel not found in the CyanogenMod Github repository list. If this is in error, you may need to manually add it to your local_manifest.xml.
build/core/product_config.mk:189: *** _nic.PRODUCTS.[[device/*/marvel/cm.mk]]: "device/*/marvel/cm.mk" does not exist. Stop.

A. Make sure you followed the instructions correctly, this is probably a misconfiguration of an XML :(

Q. I have a problem, do you have a fix? The following happens:

xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 1, column 2

A. I had that problem (in fact I have had all of these faq problems when building CM but I solved em') - type "sudo gedit .repo/local_manifest.xml" into terminal and change the first line to "" without spaces at the start

Q. I get

** Don't have a product spec for: 'cm_marvel'
** Do you have the right repo manifest?

do you have a fix

A. Redo the instructions from step 20

Q. I get this very annoying error: "build/core/java.mk:20: *** dalvik/dexgen: Invalid LOCAL_SDK_VERSION '4' Choices are: current . Stop"

A. Type "rm -rf prebuilt; repo sync -l prebuilt" - credit to dudeman1996 for this find in Chinese - Credit to me for translating it into usable words from Google Translate :D

Q. I get a strange kernel error about cm9 prebuilt kernels

A. Use aswerth's temp patch

This is the last commit before CM9 gave this error.

Q. Upon installation of packages it says that Java has no installation candiate

A. Run the following command: sudo add-apt-repository ppa:ferramroberto/java; sudo apt-get update