栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

自己编译安卓系统实践

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

自己编译安卓系统实践

一、需要的环境和信息来源

版本号与驱动匹配表:https://developers.google.com/android/drivers#hammerheadmra58k

android细分版本号:https://source.android.com/setup/start/build-numbers?hl=zh_cn

编译环境需求:https://source.android.google.cn/setup/build/older-versions

镜像使用帮助:https://mirrors.ustc.edu.cn/help/aosp.html

此处我们编译 :android-10.0.0_r17

二、实践

1、安装 Ubuntu 20.04 
2、设置语言与更新源,推荐ustc.edu.cn    中科大镜像源
3、下载初始化包并解压(aosp源码)

(1)mkdir ~/bin
 (2) cd ~/bin
 (3) wget https://mirrors.ustc.edu.cn/aosp-monthly/aosp-latest.tar
 wget可以使用-c选项,来支持断点下载
 (4)md5sum aosp-latest.tar 计算MD5值是否与网站一致
 (5) tar xvf aosp-latest.tar

 注意:解压后一定要保存快照

2、配置git

sudo apt-get install git
git config --global user.email 80491636@qq.com
git config --global user.name "zhangkai"

此处可在根目录中找到.gxxxx的文件  cat 查看后就是设置的邮箱和名称

3、安装repo工具

#mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
## 如果上述 URL 不可访问,可以用下面的:
## curl -sSL  'https://gerrit-googlesource.proxy.ustclug.org/git-repo/+/master/repo?format=TEXT' |base64 -d > ~/bin/repo
chmod a+x ~/bin/repo

4、安装python
注意,ubuntu默认是安装的有python的,执行python3可以查看到版本.(无需操作,略过此步)
增加软连接python:

sudo ln -s /usr/bin/python3.8 /usr/bin/python3

sudo ln -s /usr/bin/python2.7 /usr/bin/python

5、初始化仓库
(1)初始化特定android版本:

cd ~/bin/aosp
#repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-4.4.4_r1
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-10.0.0_r17

显示:repo has been initialized in /home/zhangkai/bin/aosp 表示初始化完成

(2)输入:

repo sync

6、安装依赖和JDK8:

sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig libncurses5

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk

7、安装驱动
根据 版本号与驱动匹配表 找到对应驱动下载到aosp目录下,解压后 ./命令运行。
会在vendor目录下生成文件
运行文件时需要根据提示输入:I ACCEPT

8、编译系统

make clobber
source build/envsetup.sh
lunch    
make -j8      (-j后面是分配的线程,根据电脑配置酌情设置)

lunch的选择

在官方安装包中:https://developers.google.com/android/images#hammerhead

找到自己手机对应的名字。例如:Nexus5

编译完成后会在 out 目录中生成相应的文件,具体的系统和对应生成的文件自己再查。

nexus5 4.4 生成在out/target/product/generic下 recovery.img,boot.img,system.img,cache.img,userdata.img

下载同版本官方安装包,将文件替换后 flash-all.bat 自动执行刷机

问题集锦:
fatal:不能重置索引文件至版本号 'xxxx'。
解决方法:
cd ~/bin/aosp/.repo/repo
git pull
cd ~/bin/aosp
再次repo init 和 repo sync

编译 android-4.4.4_r1        (看雪视频中用到的就是这个版本)

repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-4.4.4_r1


下载:https://www.oracle.com/java/technologies/javase-java-archive-javase6-downloads.html
这里下载的是:jdk-6u45-linux-x64.bin然后,可以把它放置在任何你喜欢的文件夹,建议把它放置到主文件夹(/home
解决步骤:

1、下载 3.81 或 3.82 版本的 make 压缩包

wget https://ftp.gnu.org/gnu/make/make-3.82.tar.gz

2、将 make 压缩包放到 Ubuntu 任意目录下解压

tar -zxvf make-3.82.tar.gz

3、进入 make-3.81 目录

$./configure        (请先安装依赖和 sudo apt-get install gcc -y)

$make

注意这里一般会报错。解决方案是,打开glob/glob.c,注释掉211行和232行。//符号为注释
重新执行

make clean
make
sudo make install

注意:中间一般不会出现错误,第三个命令必须加 sudo 给一个 root 权限,否则低版本的 make 安装不了。

4、查看 make 的版本(可能需要重新启动)

** make -v**

android4.4编译环境需要增加:

sudo apt-get install git gnupg flex bison gperf build-essential   zip curl libc6-dev x11proto-core-dev   g++-multilib  tofrodos   python-markdown libxml2-utils xsltproc

/ ************************** 手动刷机步骤        ******************/

Google官方factory-image地址:https://developers.google.com/android/images#bullhead
我的Nexus 5对应下载的是image-hammerhead-m4b30z
将压缩包解压,并且将image-hammerhead-m4b30z里面的分区image也解压放到与flash-all脚本相同的目录。

adb devices        查看usb调试是否正常
fastboot devices    查看fastboot模式是否正常

这里不先加锁,再解锁,启动会无限重启或一直google界面。
fastboot oem lock        加锁
fastboot reboot-bootloader
fastboot oem unlock        解锁
fastboot reboot-bootloader

fastboot erase cache
fastboot erase userdata
fastboot erase boot
fastboot erase recovery
fastboot erase system

fastboot flash bootloader bootloader-hammerhead-hhz11k.img
fastboot reboot-bootloader

fastboot flash radio radio-hammerhead-m8974a-1.0.25.0.23.img
fastboot reboot-bootloader

fastboot flash recovery recovery.img
fastboot flash boot boot.img
fastboot flash system system.img
fastboot flash cache cache.img
fastboot flash userdata userdata.img

#fastboot format cache——清除手机缓存
#fastboot format userdata——清除用户数据
fastboot reboot —— 重启手机

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/828586.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号