Galaxy Nexus (GSM): Compile CyanogenMod 9 (Linux)

本文档详细介绍了如何在Ubuntu 12.04环境下为GSM Galaxy Nexus (Maguro)编译CyanogenMod 9.x (Ice Cream Sandwich)。内容包括设置构建环境、同步相关仓库、复制专有文件等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


How to compile CyanogenMod for Maguro (GSM Galaxy Nexus).

This how-to was written for Ubuntu 12.04 for Maguro running CyanogenMod 9.x (Ice Cream Sandwich), on 12 April 2012.

Contents

[hide]

Prepare the Build Environment

NOTE: These steps only need to be performed once. If the build environment is already prepared, skip to Copy proprietary files.

Install the ADB

Install the Android SDK.

Install the Build Packages

Install using preferred package manager:

For 64-bit systems:

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 pngcrush schedtool tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386

Create the Directories

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

To create them:

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

Install the Repository

Enter the following to download make executable the "repo" binary:

curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
NOTE: You may need to reboot for these changes to take effect.

Now enter the following to initialize the repository:

cd ~/android/system/
repo init -u git://github.com/CyanogenMod/android.git -b ics
repo sync -j16

Sync Relevant Repositories

NOTE: This only needs to be done the first time after installing the repository. If you have already done this step, you may skip to Copy Proprietary Files.

By default, CyanogenMod 9 only syncs the core android repositories and none of the device or kernel trees to save both bandwidth and time. Run the following command to sync the necessary components for the device:

. build/envsetup.sh && brunch maguro

Copy Proprietary Files

NOTE: This only needs to be done the first time you build. If you have already done these steps, you may skip to Download Prebuilts.

You will need to have a maguro with a working copy of CyanogenMod install and ADB working on the computer. This script will copy the proprietary files from the device.

Connect the device to the computer and ensure that ADB is working properly.

cd ~/android/system/device/samsung/maguro/
./extract-files.sh
NOTE: If some hardware isn't functioning properly, you may need to run the above command again for updated proprietary files.

Download Prebuilts

Download Prebuilts needed by the build:

~/android/system/vendor/cm/get-prebuilts

Building CyanogenMod

Check for updates

First, check for updates in the source:

cd ~/android/system/
repo sync

Configure Build & Compile

Now, the environment must be configured to build and the ROM compiled, from code, for the maguro.

. build/envsetup.sh && brunch maguro

Install

  1. Copy your .zip file from ~/android/system/out/target/product/maguro/update.cm-XXXXX-signed.zip to the root of the SD card.
    Optional: Download Google Apps for CyanogenMod 9 and place it on the root of the SD card.
  2. Flash both of these .zip files from recovery.
### 解决 `compile_commands.json` 文件为空的问题 当遇到 `compile_commands.json` 文件为空的情况时,这通常意味着编译过程未能正确记录到此 JSON 文件中。为了使 Clangd 插件能够正常工作并提供有效的代码补全和其他功能,确保 `compile_commands.json` 正确生成至关重要。 #### 卸载 VSCode 官方 CMake 扩展的影响 卸载了 Visual Studio Code 的官方 CMake 扩展可能会影响 Bear 工具的工作方式。Bear 需要通过调用实际的构建工具来捕获编译命令,并将其写入 `compile_commands.json` 文件。如果缺少必要的构建工具或其路径未被正确识别,则可能导致生成的文件为空[^1]。 #### 使用命令行安装 CMake 并验证设置 重新安装 CMake 可能解决了上述问题,因为 CMake 是许多现代 C++ 项目的默认构建系统之一。安装完成后应确认: - 系统 PATH 中包含了 CMake 的可执行文件位置; - 运行简单的 cmake 命令测试是否成功找到 CMake 版本号; - 如果使用的是特定版本控制下的项目结构,请确保 `.gitignore` 或其他忽略列表不会意外排除掉重要的构建产物目录如 build/ 或者 _builds/。 #### 修改 .vscode/settings.json 来支持自定义构建配置 对于那些不依赖传统 Makefile 构建系统的项目来说,在 `.vscode/settings.json` 中指定合适的参数可以更好地兼容不同的开发环境需求。例如: ```json { "C_Cpp.default.compilerPath": "/usr/bin/gcc", "C_Cpp.default.browse.path": [ "${workspaceFolder}", "/path/to/additional/include/files" ], "cmake.configureSettings": { "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" } } ``` 这段配置指定了 GCC 编译器的位置以及额外包含头文件搜索路径,并开启了导出编译命令的功能以供后续分析工具读取。 #### 利用 Bear 工具生成 compile_commands.json 考虑到某些情况下即使有完整的 CMake 设置也可能无法得到预期的结果,采用独立的方式利用 Bear 工具直接处理源码也是一种可行的方法。具体操作如下所示: ```bash bear -- make -j$(nproc) ``` 这条指令会启动多线程模式下最大可用核心数目的编译作业,并由 Bear 收集所有涉及的编译选项最终形成所需的 `compile_commands.json` 文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值