Nexus 搞机之路 —— aosp源码的获取与编译

本文介绍如何使用中科大镜像下载并编译Nexus5x的AOSP源码,包括安装repo工具、下载内核源码、编译过程及解决内存不足等问题。

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

Nexus5x 源码的下载与编译

由于国内的墙的关系,即使使用了梯子,在repo 源码的时候也会出现失败的现象,辛亏国内有中科大和清华大学aosp的源,加快了repo 的速度

国内镜像的说明

AOSP镜像的一些说明文档,可以根据说明进行下载
https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
https://lug.ustc.edu.cn/wiki/mirrors/help/aosp

1.下载安装repo

  1. Make sure you have a bin/ directory in your home directory and that it is included in your path:
    mkdir /bin PATH=~/bin:$PATH
  2. Download the Repo tool and ensure that it is executable:
    $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    $ chmod a+x ~/bin/repo

2.下载aosp源码

2-1.可以先下载他们提供的aosp.tar包,在通过repo sync同步到最新
2-2.如果需要切换到其他版本
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-7.1.1_r11
repo sync
注:

已有仓库如何改用科大源
如果您已经从官方同步了 AOSP 仓库,现在希望使用科大的 AOSP 仓库,请修改 .repo/manifests.git/config,将
url = https://android.googlesource.com/platform/manifest
修改成
url = git://mirrors.ustc.edu.cn/aosp/platform/manifest

3.下载kernel

Download the source for the kernel you want to build using the appropriate git clone command:
$ git clone https://android.googlesource.com/kernel/common.git
$ git clone https://android.googlesource.com/kernel/hikey-linaro
$ git clone https://android.googlesource.com/kernel/x86_64.git
$ git clone https://android.googlesource.com/kernel/exynos.git
$ git clone https://android.googlesource.com/kernel/goldfish.git
$ git clone https://android.googlesource.com/kernel/msm.git
$ git clone https://android.googlesource.com/kernel/omap.git
$ git clone https://android.googlesource.com/kernel/samsung.git
$ git clone https://android.googlesource.com/kernel/tegra.git

由于我们使用的是nexus5所以下载msm.git
git clone https://mirrors.ustc.edu.cn/aosp/kernel/msm.git

4.编译

make clobber
sourcebuild/envsetup.shor . build/envsetup.sh

$ lunch aosp_bullhead-userdebug
or lunch之后选择需要编译的项目

make bootimage编译boot.img

fastboot boot boot.img 不会刷入flash 中,
fastboot flash boot boot.img 刷入内存中

全编译的时候应该注意设置java虚拟机的堆栈大小git clone https://android.googlesource.com/kernel/msm.git
export JACK_SERVER_VM_ARGUMENTS=”-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m”
1. out/host/linux-x86/bin/jack-admin kill-server
2. out/host/linux-x86/bin/jack-admin start-server


!!!编译的时候会出现JAVA虚拟机内存不足的情况

  1. 提示:increasing heap size。就是Java虚拟机的heap size不够了,添加环境变量:
    export _JAVA_OPTIONS=-Xmx8192m

赋值大小看自己机器了。
然而,即使这样设置了,有时候也不起作用,因为可能机器本身硬件内存就不足了,根本就没有8G那么多好吗。由于自己的机器是8G的,而且运行在虚拟机上,只分配到4G的空间,所以build的过程中,内存不足的问题卡了自己很久很久,而且官方说,最好是有16g ram以上,几乎要放弃了。最后想了个办法,增加swap内存。
至于如何增加swap内存,参考这里。

自己直接swap增加了16G,由于本来是8G,所以最好是24G了。
感叹一下,UNIX的“Everything is file”的伟大,硬件不够,软件来补,呵呵~~~
解决这个内存问题后,就顺利的build出来了

增加swap分区
mkdir swap
cd swap
sudo dd if=/dev/zero of=swapfile bs=1024 count=10000000
sudo mkswap swapfile
sudo swapon swapfile

free -m查看swap 分区是否已经调整

bootimage编译方法:

git clone xxxxxxxxxxxxxxxxxxx/msm.git
在msm.git中解压的文件夹中进行编译
makeARCH=arm64bullheaddefconfig make ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -j41212

在aosp目录中编译

google中的方法
Building the kernel

When you know the last commit message for a kernel and have successfully downloaded the kernel source and prebuilt gcc, you are ready to build the kernel. The following build commands use the hikey kernel:
exportARCH=arm64 export CROSS_COMPILE=aarch64-linux-android-
cdhikeylinaro git checkout -b android-hikey-linaro-4.1 origin/android-hikey-linaro-4.1
makehikeydefconfig make
To build a different kernel, simply replace hikey-linaro with the name of the kernel you want to build.
The image outputs to the arch/arm64/boot/Image directory; the kernel binary outputs to thearch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb fle. Copy the Image directory and the hi6220-hikey.dtb file to the hikey-kernel directory.
Alternatively, you can include the TARGET_PREBUILT_KERNEL variable while using make bootimage (or any other make command line that builds a boot image). This variable is supported by all devices as it is set up via device/common/populate-new-device.sh. For example:
exportTARGETPREBUILTKERNEL= your_kernel_path/arch/arm/boot/zImage-dtb
Note: Kernel names differ by device. To locate the correct filename for your kernel, refer todevice// in the kernel source.

生成驱动目录

接下来需要在Android官网下载 Nexus5所需要的驱动:
Hardware Component
Company
Download
MD5 Checksum
SHA-1 Checksum
NFC, Bluetooth, Wi-Fi
Broadcom
Link
2c398994e37093df51b105d63f0eb611
991346159c95ae75f760014a6822b8b3e8667700
Camera, Sensors, Audio
LG
Link
74cf8235e6bb04da28b2ff738b13eee9
175dd5bae81bb54030d072cb0f0b4ec81eb3f71f
Graphics, GSM, Camera, GPS, Sensors, Media, DSP, USB
Qualcomm
Link
0a43395e175d3de3dc312d8abdcb4f20
007cf9d49f0409d5c703e7f2811fd153fee22353
下载完成后,解压出来是三个.sh文件,放到Android源码目录下面,然后执行.会将相关驱动放到vender目录下面.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值