Windows11:如何下载Android源代码

AOSP简介

AOSP就是安卓开放的源代码,我们可以下载下来学习,或者进行二次开发。本文章主要介绍如何通过清华大学的镜像源下载AOSP,并进行编译。

WSL安装

Android源代码的编译需要在Linux下进行的,但是如果我们只有一台Windows电脑,又不想折腾双系统,那么可以通过WSL简单轻松的在window下建立一个Linux子系统。

启动WSL

通过【控制面板 -> 程序 -> 启动或关闭Windows功能 -> 勾选“虚拟机平台”和“适用于Linux的Windows子系统” -> 重启】即可打开WSL。
在这里插入图片描述

下载Ubuntu

通过Windows的Microsoft Store搜索Ubuntu然后 下载 即可,这里我们选择Ubuntu 20.04 LTS
在这里插入图片描述
下载完成以后双击即可打开一个Linux命令行,此时就相当于处于一个linux环境了

如果出现了WslRegisterDistribution failed with error:这样的错误
那么可能出现的原因是因为WSL内核没有升级,可以通过下载如下连接进行升级
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

repo下载

Android源代码通过repo工具进行下载

  1. 下载git
sudo apt-get install git
  1. 下载repo
mkdir ~/bin
sudo apt install curl
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
  1. 配置权限和环境变量
chmod a+x ~/bin/repo
PATH=~/bin:$PATH
  1. repo的使用需要python
sudo apt-get install python

可能会出现下载了python3,但是repo只识别python,所以需要建立一个软链接

sudo ln -s /usr/bin/python3 /usr/bin/python

拉取源代码

  1. 建好目录
mkdir Android
cd Android
  1. 初始化仓库
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest

可能会出现的错误

root@DESKTOP-8QPLOGT:~/AOSP# repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
Downloading Repo source from https://gerrit.googlesource.com/git-repo
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error EOF occurred in violation of protocol (_ssl.c:1131)
fatal: cloning the git-repo repository failed, will remove '.repo/repo'

这个时候通过在~/.bashrc文件下添加如下代码即可解决

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
  1. 同步代码
repo sync
  1. 漫长的等待

参考

  1. https://zhuanlan.zhihu.com/p/364020370
  2. https://blog.csdn.net/Luoshengyang/article/details/6559955
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值