清华TUNA镜像源下载Android源码的方法

本文介绍如何在Ubuntu上安装Git并下载Android源码,提供了详细的步骤指导,并列出了一系列从Android 5.1.0到6.0.1各版本的版本号及支持设备。

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

本文在写作时是测试成功的,建议参考以下网页 
Google教程: 
https://source.android.com/source/downloading.html 
TUNA的AOSP使用帮助: 
https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/


安装GIT(Ubuntu)

sudo apt-get install git

源码下载

下载 repo 工具:

mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

建立工作目录:

mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY

初始化仓库:

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest

或 repo init -u Git://aosp.tuna.tsinghua.edu.cn/aosp/platform/manifest

如果提示无法连接到 gerrit.googlesource.com,可以编辑 ~/bin/repo,把 REPO_URL 一行替换成下面的: 
REPO_URL = ‘https://gerrit-google.tuna.tsinghua.edu.cn/git-repo

如果需要某个特定的 Android 版本(以android-4.0.1_r1为例):

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-4.0.1_r1

查看Android版本编号: 
本文最后一部分有更新于2016.04.28Android5.0.1-6.0.1的版本号 
来源:https://source.android.com/source/build-numbers.html#source-code-tags-and-builds

开始同步:

repo sync

接下来就是漫长的等待…… 
在校园网中下载速度会比较快 
下载Android5.0源码压缩成.tar.gz后有26GB,可以参考一下


Android 5.1.0 - 6.0.1 版本号

更新于2016.04.28

Build Branch Version Supported devices
M5C14J android-6.0.1_r31 Marshmallow Pixel C
MOB30D android-6.0.1_r30 Marshmallow Nexus 5, Nexus 6, Nexus 7 (flo/deb), Nexus 9 (volantis/volantisg), Nexus Player, and Android One
MHC19Q android-6.0.1_r24 Marshmallow Nexus 5X, Nexus 6P
MHC19J android-6.0.1_r22 Marshmallow Nexus 5X
MHC19I android-6.0.1_r21 Marshmallow Nexus 6P
MMB29X android-6.0.1_r20 Marshmallow Nexus 5, Nexus 6, Nexus 7 (deb), Nexus 9 (volantisg)
MXC14G android-6.0.1_r18 Marshmallow Pixel C
MMB29V android-6.0.1_r17 Marshmallow Nexus 5, Nexus 5X, Nexus 6, Nexus 6P, Nexus 7 (flo/deb), Nexus 9 (volantis/volantisg)
MXB48T android-6.0.1_r16 Marshmallow Pixel C
MMB29U android-6.0.1_r13 Marshmallow Nexus Player
MMB29R android-6.0.1_r12 Marshmallow Nexus 9 (volantis/volantisg)
MMB29Q android-6.0.1_r11 Marshmallow Nexus 5, Nexus 5X, Nexus 6, Nexus 6P, Nexus 7 (flo/deb)
MMB29T android-6.0.1_r10 Marshmallow Nexus Player
MMB29S android-6.0.1_r9 Marshmallow Nexus 5, Nexus 6, Nexus 9 (volantis/volantisg)
MMB29P android-6.0.1_r8 Marshmallow Nexus 5X, Nexus 6P
MMB29O android-6.0.1_r7 Marshmallow Nexus 7 (flo/deb)
MXB48K android-6.0.1_r5 Marshmallow Pixel C
MXB48J android-6.0.1_r4 Marshmallow Pixel C
MMB29M android-6.0.1_r3 Marshmallow Nexus 6P, Nexus Player
MMB29K android-6.0.1_r1 Marshmallow Nexus 5, Nexus 5X, Nexus 6, Nexus 7 (flo/deb), Nexus 9 (volantis/volantisg)
MMB29N android-6.0.0_r41 Marshmallow Nexus 6P
MDB08M android-6.0.0_r26 Marshmallow Nexus 5X, Nexus 6P
MDB08L android-6.0.0_r25 Marshmallow Nexus 5X, Nexus 6P
MDB08K android-6.0.0_r24 Marshmallow Nexus 6P
MDB08I android-6.0.0_r23 Marshmallow Nexus 5X
MDA89E android-6.0.0_r12 Marshmallow Nexus 5X
MDA89D android-6.0.0_r11 Marshmallow Nexus 6P
MRA59B android-6.0.0_r7 Marshmallow Nexus 7 (deb)
MRA58X android-6.0.0_r6 Marshmallow Nexus 6
MRA58V android-6.0.0_r5 Marshmallow Nexus 7 (flo/deb)
MRA58U android-6.0.0_r4 Marshmallow Nexus 7 (flo)
MRA58N android-6.0.0_r2 Marshmallow Nexus 5, Nexus 6, Nexus 7 (flo/deb), Nexus 9 (volantis/volantisg), Nexus Player
MRA58K android-6.0.0_r1 Marshmallow Nexus 5, Nexus 6, Nexus 7 (flo/deb), Nexus 9 (volantis/volantisg), Nexus Player
LMY49J android-5.1.1_r37 Lollipop Nexus 10
LMY49I android-5.1.1_r36 Lollipop Nexus 10
LMY49H android-5.1.1_r35 Lollipop Nexus 10
LMY49G android-5.1.1_r34 Lollipop Nexus 10
LMY49F android-5.1.1_r33 Lollipop Nexus 9 (volantisg), Nexus 10
LMY48Z android-5.1.1_r30 Lollipop Nexus 6, Nexus 7 (deb), Nexus 9 (volantisg), Nexus 10
LYZ28N android-5.1.1_r28 Lollipop Nexus 6 (For T-Mobile ONLY)
LMY48Y android-5.1.1_r26 Lollipop Nexus 6
LMY48X android-5.1.1_r25 Lollipop Nexus 6, Nexus 7 (deb), Nexus 9 (volantisg), Nexus 10
LMY48W android-5.1.1_r24 Lollipop Nexus 6
LVY48H android-5.1.1_r23 Lollipop Nexus 6 (For Project Fi ONLY)
LYZ28M android-5.1.1_r22 Lollipop Nexus 6 (For T-Mobile ONLY)
LMY48U android-5.1.1_r20 Lollipop Nexus 7 (deb)
LMY48T android-5.1.1_r19 Lollipop Nexus 4, Nexus 6, Nexus 9 (volantis/volantisg), Nexus 10
LVY48F android-5.1.1_r18 Lollipop Nexus 6 (For Project Fi ONLY)
LYZ28K android-5.1.1_r17 Lollipop Nexus 6 (For T-Mobile ONLY)
LMY48P android-5.1.1_r16 Lollipop Nexus 7 (deb)
LMY48N android-5.1.1_r15 Lollipop Nexus Player
LMY48M android-5.1.1_r14 Lollipop Nexus 4, Nexus 5, Nexus 6, Nexus 7 (flo), Nexus 9 (volantis/volantisg), Nexus 10
LVY48E android-5.1.1_r13 Lollipop Nexus 6 (For Project Fi ONLY)
LYZ28J android-5.1.1_r12 Lollipop Nexus 6 (For T-Mobile ONLY)
LMY48J android-5.1.1_r10 Lollipop Nexus Player
LMY48I android-5.1.1_r9 Lollipop Nexus 4, Nexus 5, Nexus 6, Nexus 7 (flo), Nexus 9 (volantis/volantisg), Nexus 10
LVY48C android-5.1.1_r8 Lollipop Nexus 6 (For Project Fi ONLY)
LMY48G android-5.1.1_r6 Lollipop Nexus 7 (flo)
LYZ28E android-5.1.1_r5 Lollipop Nexus 6 (For T-Mobile ONLY)
LMY47Z android-5.1.1_r4 Lollipop Nexus 6 (All carriers except T-Mobile US)
LMY48B android-5.1.1_r3 Lollipop Nexus 5
LMY47X android-5.1.1_r2 Lollipop Nexus 9 (volantis)
LMY47V android-5.1.1_r1 Lollipop Nexus 7 (flo/grouper), Nexus 10, Nexus Player
LMY47O android-5.1.0_r5 Lollipop Nexus 4, Nexus 7 (flo/deb)
LMY47M android-5.1.0_r4 Lollipop Nexus 6 (For T-Mobile ONLY)
LMY47I android-5.1.0_r3 Lollipop Nexus 5, Nexus 6
LMY47E android-5.1.0_r2 Lollipop Nexus 6
LMY47D android-5.1.0_r1 Lollipop Nexus 5, Nexus 6, Nexus 7 (grouper/tilapia), Nexus 10, Nexus Player
<think>我们正在处理用户关于使用清华大学镜像下载Android源码后编译时遇到内核缺失的问题。根据用户提供的信息和引用内容,我们需要分析可能的原因并提供解决方案。首先,用户提到使用清华大学镜像下载Android源码,这通常意味着用户通过AOSP镜像获取了源代码。但在编译过程中遇到内核缺失的问题,这可能是由于以下几个原因:1.**未正确同步内核源码**:Android系统需要Linux内核才能编译。通常,内核源码是单独下载的,并不包含在AOSP主仓库中。2.**内核源码路径配置错误**:在编译Android时,需要指定内核源码的位置,如果配置不正确,会导致编译系统找不到内核源码。 3. **内核版本不匹配**:下载的内核版本与Android源码版本不兼容。 根据引用[1]中的信息,我们看到了一个关于红外遥控配置的日志,但这似乎与Android编译无关。引用[2]展示了编译本地定义工具(localedef)的命令,引用[3]提供了CMake的下载链接,引用[4]是关于elevation_mapping_cupy的安装说明。这些引用似乎与当前问题关联不大,因此我们主要依靠对Android编译流程的理解来解决问题。###解决方案步骤####1.确认内核源码是否已下载在编译Android之前,需要为特定的设备下载内核源码。例如,如果用户是为Pixel设备编译,那么需要下载对应设备的内核源码。-使用清华大学镜像下载内核源码:例如,为Pixel3(设备代号为blueline)下载内核源码的命令如下:```bashgitclone https://aosp.tuna.tsinghua.edu.cn/kernel/msm.git -b android-msm-blueline-4.9-pie-qpr2```注意:分支名称(-b后面的参数)需要根据用户要编译的Android版本和设备来确定。 ####2.将内核源码放置在正确的位置通常,内核源码应放在AOSP源码根目录下的`kernel`子目录中,并按照设备制造商和芯片组分类。例如:-高通MSM芯片组的设备:`kernel/msm`-其他设备请参考AOSP官方文档。####3.配置环境变量在编译Android之前,需要设置环境变量,告诉编译系统内核源码的位置。在`lunch`选择设备后,可以设置`TARGET_KERNEL_SOURCE`和`TARGET_KERNEL_CONFIG`等环境变量。但更常见的做法是使用预编译的内核(如果设备支持)或者通过构建系统自动处理。 ####4.使用正确的编译命令如果已经将内核源码放在标准位置(如`kernel/msm`),那么编译系统会自动找到它。否则,可能需要修改构建配置。 ####5.如果使用预编译内核有些设备允许使用预编译的内核镜像(如`prebuilt`中的内核),这样就不需要下载内核源码。但用户需要确保预编译的内核与当前编译的Android版本兼容。 ###具体操作示例假设用户正在为Pixel3(blueline)编译Android10,步骤如下: 1.下载AOSP主代码(使用清华大学镜像):```bashrepoinit -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-10.0.0_r41repo sync-j4```2.下载内核源码:```bashgit clonehttps://aosp.tuna.tsinghua.edu.cn/kernel/msm.git -b android-msm-blueline-4.9-pie-qpr2mvmsmkernel/msm``` 3.初始化编译环境:```bashsourcebuild/envsetup.shlunch aosp_blueline-userdebug``` 4.开始编译:```bashmake-j8```如果用户是为其他设备编译,请替换相应的设备代号和内核分支。 ###常见问题排查-**问题:编译时提示找不到内核源码**解决方案:检查内核源码路径是否正确,并确保内核分支与Android版本匹配。- **问题:内核版本不匹配**解决方案:查看设备对应的内核分支,确保下载的内核分支与Android版本兼容。可以查阅设备厂商的官方文档或AOSP官方文档。 ###参考建议如果用户不确定设备的内核分支,可以访问清华大学镜像站点的内核部分(https://aosp.tuna.tsinghua.edu.cn/kernel/)查看可用的内核仓库和分支。另外,用户也可以考虑使用预编译的内核,但需要确保设备支持。在编译时,可以通过设置`TARGET_PREBUILT_KERNEL`环境变量指向预编译的内核镜像(如`zImage`或`Image.gz-dtb`)来跳过内核编译。 ###生成相关问题§§相关问题§§1.如何确定Android设备的内核源码分支?2.使用清华大学镜像下载内核源码时遇到问题怎么办? 3.如何配置Android编译系统以使用自定义位置的内核源码?4.在编译Android时如何启用预编译内核?5.如何解决Android编译过程中出现的内核版本不匹配错误?</think>### Android源码编译缺失内核问题解决方案 在使用清华大学镜像下载Android源码后编译时遇到内核缺失问题,通常是由于Android源码树不包含Linux内核源码(需单独下载)。以下是详细解决步骤: #### 1. 确认内核需求 - 查看设备对应内核版本:在AOSP根目录执行 ```bash grep "TARGET_KERNEL_SOURCE" device/*/*/BoardConfig*.mk ``` 输出示例: `device/google/coral/BoardConfig-common.mk:TARGET_KERNEL_SOURCE := kernel/google/msm-4.14` 这表示需要`msm-4.14`内核分支[^1]。 #### 2. 通过清华镜像下载内核 ```bash mkdir kernel && cd kernel # 以高通平台为例(msm内核): git clone https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/kernel/msm.git -b android-msm-coral-4.14-android12 ``` **注意**:分支名必须匹配设备要求(上一步查到的分支名)[^3]。 #### 3. 配置内核路径 在设备BoardConfig.mk中指定路径: ```makefile # device/<vendor>/<device>/BoardConfig.mk TARGET_KERNEL_SOURCE := kernel/msm TARGET_KERNEL_CONFIG := my_defconfig ``` #### 4. 生成内核配置 ```bash cd kernel/msm make ARCH=arm64 my_defconfig ``` #### 5. 重新编译 ```bash # 在AOSP根目录 source build/envsetup.sh lunch aosp_coral-userdebug # 替换为你的设备target make -j$(nproc) ``` ### 常见问题排查 1. **分支不匹配错误** 错误信息:`Kernel configuration is invalid` 解决方案: ```bash git branch -a | grep android-msm # 查看可用分支 git checkout android-msm-coral-4.14-android12 # 切换到正确分支 ``` 2. **内核版本冲突** 检查`KERNEL_DEFCONFIG`配置: ```bash grep "KERNEL_DEFCONFIG" device/*/*/BoardConfig*.mk ``` 确保与下载内核的defconfig一致[^2]。 3. **清华镜像同步问题** 若遇到`HTTP 404`错误,尝试: ```bash repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest repo sync -j4 --optimized-fetch ``` ### 预编译内核替代方案 若无需修改内核,可使用预编译内核: ```makefile # BoardConfig.mk TARGET_PREBUILT_KERNEL := device/google/coral-kernel/Image.lz4 ``` ### 验证成功 编译完成后检查: ```bash file out/target/product/coral/kernel # 应显示:Linux kernel ARM64 executable ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值