自编译cm10 cm11代码方法

How To Build CyanogenMod Android for Google Galaxy Nexus (GSM) ("maguro")

How to Build CyanogenMod for Galaxy Nexus (GSM) (codename: maguro)

Note:

This CyanogenMod build walkthrough is auto-generated specifically for theGalaxy Nexus (GSM) based on the device template atTemplate:device_maguro. You can find similar build instructions for every officially supported device. See here for more info.



Introduction

These instructions will hopefully assist you to start with a stock Galaxy Nexus (GSM), unlock the bootloader (if necessary), and then download the required tools as well as the very latest source code for CyanogenMod (based on Google’s Android operating system). Using these, you can build both CyangenMod and ClockworkMod recovery image from source code, and then install them both to your device.

It is difficult to say how much experience is necessary to follow these instructions. While this guide is certainly not for the very very very uninitiated, these steps shouldn’t require a PhD in software development either. Some readers will have no difficulty and breeze through the steps easily. Others may struggle over the most basic operation. Because people’s experiences, backgrounds, and intuitions differ, it may be a good idea to read through just to ascertain whether you feel comfortable or are getting over your head.

Remember, you assume all risk of trying this, but you will reap the rewards! It’s pretty satisfying to boot into a fresh operating system you baked at home :) And once you’re an Android-building ninja, there will be no more need to wait for “nightly” builds from anyone. You will have at your fingertips the skills to build a full operating system from code to a running device, whenever you want. Where you go from there-- maybe you’ll add a feature, fix a bug, add a translation, or use what you’ve learned to build a new app or port to a new device-- or maybe you’ll never build again-- it’s all really up to you.

What you’ll need

Read comments on this section
  • Galaxy Nexus (GSM)
  • A relatively recent computer (Linux, OS X, or Windows) w/a reasonable amount of RAM and about 35 GB of free storage. The less RAM you have, the longer the build will take. Using SSDs results in faster builds than traditional hard drives.
  • A micro USB cable
  • A decent Internet connection & reliable electricity :)
  • Some familiarity with basic Android operation and terminology. It would help if you’ve installed custom roms on other devices and are familiar with what a recovery image such as ClockworkMod is, for example. It may also be useful to know some basic command line concepts such as cd for “change directory”, the concept of directory hierarchies, that in Linux they are separated by /, etc.

If you are not accustomed to using Linux-- this is an excellent chance to learn. It’s free-- just download and run a virtual machine (VM) such as Virtualbox, then install a Linux distribution such as Ubuntu. Any recent 64-bit version should work great, but the latest is recommended.

Note:

You want to use a 64-bit version of Linux. According to Google, 32-bit Linux environment will only work if you are building older versions prior to Gingerbread (2.3.x)/CyanogenMod 7. However, as of 10.1 CyanogenMod does not build with 64bit host binaries on some systems. You will have to set something like BUILD_HOST_32bit=1 in your environment when building on such 64bit system.

Using a VM allows Linux to run as a guest inside your host computer-- a computer in a computer, if you will. If you hate Linux for whatever reason, you can always just uninstall and delete the whole thing. (There are plenty of places to find instructions for setting up Virtualbox with Ubuntu, so I’ll leave it to you to do that.)

So let’s begin!

Unlocking your Galaxy Nexus (GSM)

What does "unlocking" mean?

Note:

If you’ve already installed CyanogenMod or another ROM on your Galaxy Nexus (GSM), your device is already unlocked. Assuming you also have adb and fastboot installed on your computer, you can skip this whole section and proceed to the HOW TO BUILD section below.

The first step in putting any custom operating system on your Galaxy Nexus (GSM) is to unlock the bootloader. A bootloader is the very first program that runs when you turn on your device. The bootloader initializes some hardware and then loads the kernel and ramdisk, and gets the boot process going. If the bootloader is in locked mode, it will ensure that only the stock operating system can run. Since you will be installing yourown operating system, you need to turn this off. Luckily, Google and samsung make it easy.

Note: A Warning About Unlocking

THE PROCESS OF UNLOCKING THE BOOTLOADER WILL ERASE ALL YOUR PERSONAL DATA FROM THE DEVICE.

Okay. I’m in. What do I need to do this?

To unlock your bootloader, you’ll first need a program on your computer calledfastboot. One way to get fastboot is to download and install the Android SDK(Software Developer Kit) from Google. The SDK is used by app developers when they’re writing programs for Android, and who knows, you may want to write apps someday. But the SDK also contains two great tools that are useful even to non-developers. They are:


  • adb - Android Debug Bridge - this is a program that lets your computer “talk” to your Galaxy Nexus (GSM) while the device is running. Among the many things you can do with adb-- you can push files from your computer to the device or pull files from the device to your computer, you can get a running real-time log of Android activity (which is very useful for debugging or having others help you debug), you can create an interactive “shell” session (similar to Linux or OS X) to type commands to your device, and much more.


  • fastboot - fastboot works a little bit like adb, except it’s often used at a much earlier point in the boot process, even before Android or any operating system loads. You can put your Galaxy Nexus (GSM) into a “fastboot” mode, whereby, if you are connected via USB cable, you can copy entire partitions from your computer (usually in the form of an image file, such as boot.img or recovery.img) over to the device, wiping over whatever happened to be there. Fastboot is able to do more than that, however. It’s also used to send special commands to the device to do things such as unlock your bootloader.


How do I do the actual unlocking?

So this should be a one time thing...

Install the Android SDK
Add a comment to this section


To unlock your Galaxy Nexus (GSM), you will need fastboot installed. Go ahead and download the SDK, per the steps on Google's web page. Then install it by following thespecific instructions for your computer.

Note:

Google's instructions may be out of date for 12.04. The Sun JDK isn't available anymore as a dpkg AND they say Eclipse 3.6 isn't available as a package. Well, 3.7.X is now available. Doing a "$ sudo apt-get install eclipse" will now install the proper Eclipse and JDK (OpenJDK 6).

Unlocking the device

Once fastboot is installed:

Note:

Unlocking the bootloader on a Nexus device will automatically wipe all device data.

  1. Enable USB debugging on the device.
  2. Connect the device to the computer through USB.
  3. From a terminal on a computer, type the following to boot the device into fastboot mode:
    adb reboot bootloader
  4. Once the device is in fastboot mode, verify your PC sees the device by typingfastboot devices
    • If you don't see your device serial number, and instead see "<waiting for device>", fastboot is not configured properly on your machine. See fastbootdocumentation for more info.
    • If you see "no permissions fastboot", try running fastboot as root.
  5. From the same terminal, type the following command to unlock the bootloader (under Linux, you must be root):
    $ fastboot oem unlock
  6. A disclaimer will display on the device that must be accepted. Use the volume keys to cycle through the options. Pressing the power button should confirm your selection.
  7. If the device doesn't automatically reboot, reboot it from the menu. It should now be unlocked. You can confirm this is the case if you see an unlocked icon at the bottom of the Google boot screen during reboots.
  8. Since the device resets completely you need to re-enable USB debugging.
Troubleshooting
Add a comment to this section

If you have issues with fastboot or adb not being found, make sure that the Android SDK folder /platform-tools, which contains the adb and fastboot files, are in the path of execution for commands typed at the terminal. Usually typing something like

# PATH=$PATH:/your/specific/path/to/android/sdk/platform-tools/

will work for that terminal session.

Note:

The above command requires a bash-like shell. If you're running a linux distribution which uses a shell such as csh or tcsh, first run /bin/bash to start a bash shell. See http://www.cyberciti.biz/tips/how-do-i-find-out-what-shell-im-using.html or google for more help on that. You will need bash later as well, when using the ". build/envsetup.sh" command.

Note: Linux Mint users

If you have problems with adb (“file not found”) and you’re using 64-bit linux (I don’t know much about Mint, so maybe it’s all 64-bit?) try doing this to see if adb works better:

$ sudo apt-get install ia32-libs

You’ll be using fastboot again to install ClockworkMod recovery.


Build CyanogenMod and ClockworkMod Recovery

Prepare the Build Environment

Add a comment to this section

Note:

You only need to do these steps the first time you build. If you previously prepared your build environment and have downloaded the CyanogenMod source code for another device, skip to Prepare the device-specific code.


Install the SDK
Add a comment to this section
If you have not previously installed  adb and  fastboot, install the  Android SDK. "SDK" stands for Software Developer Kit, and it includes useful tools that you can use to flash software, look at the system logs in real time, grab screenshots, and more-- all from your computer.

Helpful Tip

While the SDK contains lots of different things-- the two tools you are most interested in for building Android are adb and fastboot, located in the/platform-tools directory.

Install the Build Packages
Read comments on this section

Several "build packages" are needed to build CyanogenMod. You can install these using the package manager of your choice.

Helpful Tip

package manager in Linux is a system used to install or remove software (usually originating from the Internet) on your computer. With Ubuntu, you can use the Ubuntu Software Center. Even better, you may also use the apt-get install command directly in the Terminal. (Learn more about the aptpackaging tool system from Wikipedia.)

For both 32-bit & 64-bit systems, you'll need:

bison build-essential curl flex git-core gnupg gperf libesd0-dev libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop openjdk-6-jdk openjdk-6-jre pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev

In addition to the above, for 64-bit systems, get these:

g++-multilib gcc-multilib lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev

Also see http://source.android.com/source/initializing.html which lists needed packages.

Create the directories

Add a comment to this section

You will need to set up some directories in your build environment.

To create them:

$ mkdir -p ~/bin
$ mkdir -p ~/android/system

Install the repo command

Add a comment to this section

Enter the following to download the "repo" binary and make it executable (runnable):

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

Put the ~/bin directory in your path of execution

Make sure that the ~/bin directory you just created is in your path of execution so that you can easily run the repo command even when you're not in ~/bin. Assuming you are using the BASH shell, the default in recent versions of Ubuntu, you can set it like this:

$ export PATH=${PATH}:~/bin

Helpful Tip

You can make this change to the path permanent for all future Terminal sessions:

$ gedit ~/.bashrc

This will launch a graphical text editor. Enter

export PATH=${PATH}:~/bin

on its own line, then save the file.

Initialize the CyanogenMod source repository

Add a comment to this section

Enter the following to initialize the repository:

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


Download the source code

Add a comment to this section

To start the download of all the source code to your computer:

$ repo sync

The CM manifests include a sensible default configuration for repo, which we strongly suggest you use (i.e. don't add any options to sync). For reference, our default values are -j 4 and -c. The -j 4 part means that there will be four simultaneous threads/connections. If you experience problems syncing, you can lower this to -j 3 or -j 2-c will ask repo to pull in only the current branch, instead of the entire CM history.

Prepare to wait a long time while the source code downloads.

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.

Get prebuilt apps

Read comments on this section

Next,

$ cd ~/android/system/vendor/cm

then enter:

$ ./get-prebuilts

You won't see any confirmation- just another prompt. But this should cause some prebuilt apps to be loaded and installed into the source code. Once completed, this does not need to be done again.


Prepare the device-specific code

Add a comment to this section

After the source downloads, ensure you are in the root of the source code (cd ~/android/system), then type:

$ source build/envsetup.sh
$ breakfast maguro

This will download the device specific configuration and kernel source for your device.

Note:

You MUST be using the newest version of repo or you will encounter errors with breakfast! Run repo selfupdate to update to the latest.

Helpful Tip

If you want to know more about what "$ source build/envsetup.sh" does or simply want to know more about the breakfastbrunch and lunch commands, you can head over to the Envsetup_help page

Extract proprietary blobs

Read comments on this section

Now ensure that your Galaxy Nexus (GSM) is connected to your computer via the USB cable and that you are in the ~/android/system/device/samsung/maguro directory (you can cd ~/android/system/device/samsung/maguro if necessary). Then run the extract-files.shscript:

$ ./extract-files.sh

You should see the proprietary files (aka “blobs”) get pulled from the device and moved to the right place in the vendor directory. If you see errors about adb being unable to pull the files, adb may not be in the path of execution. If this is the case, see the adb page for suggestions for dealing with "command not found" errors.

Note:

Your device should already be running the branch of CyanogenMod you wish to build your own version of for the extract-files.sh script to function properly. If you are savvy enough to pull the files yourself off the device by examining the script, you may do that as well without flashing CyanogenMod first.

Note:

It’s important that these proprietary files are properly extracted and moved to the vendor directory. Without them, CyanogenMod will build without error, but you’ll be missing important functionality, such as the ability to see anything!


Turn on caching to speed up build

Add a comment to this section

If you want to speed up subsequent builds after this one, type:

$ export USE_CCACHE=1

Helpful Tip

Instead of typing cd ~/android/system every time you want to return back to the root of the source code, here’s a short command that will do it for you: croot . To use this command, as with brunch, you must first do “. build/envsetup.sh” from ~/android/system. Notice there is a period and space (“”) in that command.


Start the build

Add a comment to this section

Time to start building! So now type:

$ croot
$ brunch maguro

The build should begin.

Helpful Tip

If the build doesn't start, try lunch and choose your device from the menu. If that doesn't work, try breakfast and choose from the menu. The commandmake maguro should then work.

Helpful Tip

A second, bonus tip! If you get a command not found error for croot orbrunch or lunch, be sure you’ve done the “ . build/envsetup.sh” command in this Terminal session from the ~/android/system directory.

If the build breaks...

Add a comment to this section
  • If you experience this not-enough-memory-related error...
ERROR: signapk.jar failed: return code 1make: *** [out/target/product/maguro/cm_maguro-ota-eng.root.zip] Error 1

...you may want to make the following change to:

$ system/build/tools/releasetools/common.py

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

Then start the build again (with brunch).

  • 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.

Install the build

Add a comment to this section


Assuming the build completed without error (it will be obvious when it finishes), type:

# cd $OUT

in the same terminal window that you did the build. Here you’ll find all the files that were created. The stuff that will go in /system is in a folder called system. The stuff that will become your ramdisk is in a folder called root. And your kernel is called...kernel.

But that’s all just background info. The two files we are interested in are (1)recovery.img, which contains ClockworkMod recovery, and (2) cm-[something].zip, which contains CyanogenMod.

Installing recovery using fastboot

You can use fastboot to install your recovery image to the device.

Installing ClockworkMod Recovery on the Galaxy Nexus (GSM)

  1. Connect the Galaxy Nexus (GSM) to the computer via USB.
  2. Make sure the fastboot binary is in your PATH or that you place the downloaded image in the same directory as fastboot.
  3. Open a terminal on your PC and reboot the device into fastboot mode by typing adb reboot bootloader or by using the hardware key combination.
  4. Once the device is in fastboot mode, verify your PC sees the device by typingfastboot devices
    • If you don't see your device serial number, and instead see "<waiting for device>", fastboot is not configured properly on your machine. See fastbootdocumentation for more info.
    • If you see "no permissions fastboot", try running fastboot as root.
  5. Flash ClockworkMod Recovery onto your device by entering the following command:fastboot flash recovery your_recovery_image.img where the latter part is the name of the file you downloaded.
  6. Once the flash completes successfully, reboot the device into recovery to verify the installation.
    • Note: Some ROMs overwrite recovery at boot time so if you do not plan to immediately boot into recovery to install CyanogenMod, please be aware that this may overwrite your custom recovery with the stock one.

Install CyanogenMod

Read comments on this section

Back to the $OUT directory on your computer-- you should see a file that looks something like:

cm-10.2-20140210-UNOFFICIAL-maguro.zip

Note:

The above file name may vary depending on the version of CM you are building. Your build may not include a version number or may identify itself as a "KANG" rather than UNOFFICIAL version. Regardless, the file name will end in .zip and should be titled similarly to official builds.

Now you can flash the cm...zip file above as usual via recovery mode. (Be sure you have backed up any previous installation before trying your new build.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值