# [GUIDE] Building CM10.1 for Nexus 4 with Mac OS X Mountain Lion (aka OS X 10.8)



## inffy (Nov 12, 2011)

This is a guide to build cyanogenmod 10.1 (Android 4.2.1) for Google Nexus 4. This guide is for OS X Mountain Lion (10.8).

*Pre Requirements:*

1) go to App Store on your OS X and Download Xcode 4. Once that is installed, open Xcode and go to preferences. There you find a tab "DOWNLOADS", open it and there you can find "Command line tools" and next to it click INSTALL. It will take a few minutes to download and install
2) Make sure you have the android-sdk downloaded and setup adb and fastboot, so they work. It is recommended to place the android-sdk to /usr/local/

*Initializing the build environment*

First we need to set up our OS X to be able to build Android. This needs some extra things compared to for example, building in Linux, but the main stuff is pretty much the same. So let's get started then, shall we?

Open up Terminal and type


```
java
```
If you don't have java installed you will get a prompt to install it.

Next we will install homebrew (you can also use macports if you like)

```
<br />
/usr/bin/ruby -e "$(/usr/bin/curl –fsSL [URL=https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew]https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew[/URL].rb)"
```
Now make sure android-sdk and homebrew are in $PATH


```
<br />
touch ~/.bash_profile && echo "PATH=/usr/local/bin:/usr/local/sbin:$PATH:/usr/local/android-sdk/tools:/usr/local/android-sdk/platform-tools" >> ~/.bash_profile
```
I also recommend to add this edit to the .bash_profile file:

```
<br />
nano –w ~/.bash_profile
```


```
<br />
export BUILD_MAC_SDK_EXPERIMENTAL=1
```
The upper will ensure that the build process starts. It seems the newest Xcode is not "officially supported" or something like that, and that's why it's needed. Otherwise the building process will stop right before it even has started.

I don't really know the reason why it behaves like that but I have build couple of CM roms with these and they all work fine.

Now run this and see if you need to update anything.


```
<br />
brew doctor
```
If you do (and you probably will once a day) type:

```
<br />
brew update
```
Now we need to get our dev packages

```
<br />
brew install git coreutils findutils gnu-sed gnupg pngcrush repo<br />
```
Once that is done, run

```
<br />
brew outdated
```
if it shows anything, run

```
<br />
brew upgrade
```
Now run this the correct a few symlinks [Not sure if these are needed anymore]:

```
<br />
ln -s /usr/local/bin/gfind /usr/local/bin/find && ln -s /usr/local/bin/gsed /usr/local/bin/sed
```
Now to create our case sensitive image for our CM work [NOTE: the 60g can be changed to anything. It only takes up what it needs but I used 60GB]:

```
<br />
hdiutil create -type SPARSE -fs "Case-sensitive Journaled HFS+" -size 60g -volname "android" -attach ~/Desktop/Android<br />
```
Now to create our working directory

```
<br />
cd /Volumes/Android && mkdir cm10.1 && cd cm10.1
```
*Getting the source*

Now to initialize the git and to download it

```
<br />
repo init -u [URL=git://github.com/CyanogenMod/android.git]git://github.com/CyanogenMod/android.git[/URL] -b cm-10.1
```
Download the sources:

```
<br />
repo sync
```
Wait until it is finished. It will take a long time, depending on your internet connection.

*Obtain the device build files and proprietary files:*

To do this create a file named 'local_manifest.xml" in the .repo folder. This is a hidden folder, so you have to allow your visualisation of hidden files, alternatively run "open .repo" code from terminal. Or you can just run the code below to create the file directly into the folder.


```
<br />
nano -w /Volumes/android/cm10.1/.repo/local_manifest.xml
```
Paste the following lines into the file:


```
<br />
<manifest><br />
<project name="TheMuppets/proprietary_vendor_lge.git" path="vendor/lge" remote="github" revision="cm-10.1"/><br />
<project name="CyanogenMod/android_device_lge_mako" path="device/lge/mako" remote="github" revision="cm-10.1"/><br />
<project name="CyanogenMod/lge-kernel-mako" path="kernel/lge/mako" remote="github" revision="jellybean"/><br />
</manifest>
```
Save the file. And rerun the code:


```
<br />
repo sync
```
Download the necessary pre-builts:


```
<br />
/Volumes/android/cm10.1/vendor/cm/get-prebuilts
```
That is all. The sources are now ready.

*Building CyanogenMOD*

If you build now, you're probably gonna get kernel build errors regarding the missing elf.h header (this error might be device specific). Fortunately, we already have this file downloaded, so we only need to copy it to /usr/local/include:


```
<br />
cp /Volumes/android/cm10.1/external/elfutils/libelf/elf.h /usr/local/include
```
FINALLY, we are ready to build:

```
<br />
cd /Volumes/android/cm10.1 && source build/envsetup.sh && brunch mako
```
Change "mako" to something else if you want to build for another device (of course needs to be supported by CM)

Then we just let the mac do the rest. Remember that it will take a while to do the build, and meantime you Macs fans will scream for mercy while CM punishes your system ☺

After the build is finished successfully you can find your newly created flashable zip by typing:

```
<br />
cd $out
```
Look for .zip file with a tag UNOFFICIAL 

Happy building!

*Credits:*​
Imperticus (borrowed some stuff from his guide)
ArmanUV (borrowed some stuff from his guide)​


----------



## inffy (Nov 12, 2011)

*Some advanced stuff (will add more later)*​
*Want to compile a custom kernel (like Franco)?*

The process is easy. We only have to edit the local_manifest.xml file in the .repo directory


```
<br />
nano -w /Volumes/android/cm10.1/.repo/local_manifest.xml
```
From that file look up the line which says:


```
<br />
<project name="CyanogenMod/lge-kernel-mako" path="kernel/lge/mako" remote="github" revision="jellybean"/>
```
and replace it with this:


```
<br />
<br />
<project name="franciscofranco/mako" path="kernel/lge/mako" remote="github" revision="android-msm-mako-3.4-jb-mr1"/>
```
Save the file (I recommend you do a backup of the original file so you can easily go back if you want.

I also recommend that you delete the directory kernel/lge/mako


```
<br />
rm -Rf /Volumes/android/cm10.1/kernel/lge/mako
```
After that is done, just do a repo sync so the source updates to use Francos kernel sources


```
<br />
repo sync
```


----------



## inffy (Nov 12, 2011)

this too


----------



## wildstang83 (Aug 17, 2011)

OP, the only reason you are using brew is to get the dev stuff right? I believe I could just get all the same stuff without brew just by using sudo port install [package]?

Basically I'm not asking if I have to use brew, I just don't know of anyone who has done it without brew. I've tried with and without and have been unsuccessful either way. I wanna be able to build but I'm getting tired of building in a VM.

BTW, I'm not building for the N4, but I am building for an unsupported device with successful builds that can be built in an Ubuntu VM, I just haven't figured out how to get it to build successfully in native OSX yet.


----------

