【Android源码编译】遇到的问题

环境准备

安装依赖

参考AOSP的官网:https://source.android.com/docs/setup/start/initializing?hl=zh-cn
安装所需软件包。
当前我使用的Ubuntu版本是20.04,目前还没有对应的版本相关的内容,所以我选择安装了文档中最新的18.04版本的依赖:

安装所需的软件包 (Ubuntu 18.04)
您需要 64 位版本的 Ubuntu。

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

问题1

执行repo命令时提示:

repo: error: Python 2 is no longer supported; Please upgrade to Python 3.5+.

思路1:安装python3.6,并指定为系统使用的python版本。
安装过程,参考这个链接

安装完成后,进入repo的目录,执行repo。提示:

error: repo is not installed.  Use "repo init" to install it here.

此时repo可以使用了,将repo加入环境变量。

问题2

repo init 超时。
执行

repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest

时报错:

fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 110] Connection timed out

解决方法:
从前的解决方法一般都是改repo文件中的REPO_URL,但是本人实际操作下来,感觉最简单的方式是按照鸿蒙源码下载的方式安装码云上的repo,这样可以直接规避这一系列问题。
安装码云repo工具,可以执行如下命令:

curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo  #如果没有权限,可下载至其他目录,并将其配置到环境变量中
chmod a+x /usr/local/bin/repo
pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests

问题3

使用m命令执行编译时报错:

FAILED: out/soong/.bootstrap/build.ninja 
out/soong/.minibootstrap/minibp -t -l out/.module_paths/Android.bp.list -b out/soong -n out -d out/soong/.bootstrap/build.ninja.d -o out/soong/.bootstrap/build.ninja Android.bp
internal error: could not open symlink hardware/qcom/sm8150/Android.bp; its target (data/ipacfg-mgr/os_pickup.bp) cannot be opened
internal error: could not open symlink hardware/qcom/sm7250/Android.bp; its target (gps/os_pickup.bp) cannot be opened
internal error: could not open symlink hardware/qcom/sdm845/Android.bp; its target (data/ipacfg-mgr/os_pickup.bp) cannot be opened
internal error: could not open symlink hardware/qcom/sm7150/Android.bp; its target (gps/os_pickup.bp) cannot be opened
internal error: could not open symlink hardware/qcom/sm8150p/Android.bp; its target (gps/os_pickup.bp) cannot be opened

根据这篇文章中的内容,该问题问:找不到高通芯片有关的符号连接。
解决方法:
实际是空的文件,使用rm直接删除上面几个Android.bp文件
比如 rm hardware/qcom/sm8150p/Android.bp

问题4

编译时报错:

hardware/qcom/power/Android.mk:3: error: hardware/qcom/sdm845/Android.mk: No such file or directory

根据这篇文章的内容:
解:查了一下sdm845目录下只有一个空的mk,删除sdm845目录解决。

问题5

如何将源码导入到 AndroidStudio?
参见这篇文章的内容。
基本上是分为三步:

  1. 编译源码
  2. 编译成功后,执行:make idegen,编译出 out/host/linux-x86/framework/idegen.jar
  3. 最后执行: ./development/tools/idegen/idegen.sh,生成 android.ipr 文件,并将其导入AndroidStudio。

问题6

如何在windows上查看源码?
我们可以首先在linux中编译好源码,并正确生成 android.ipr 文件,然后将编译后的源码目录直接copy到windows中,解压缩后,像Linux下一样,使用AndroidStudio加载 android.ipr 文件即可。

问题7 ERROR: x86_64 emulation currently requires hardware acceleration!

Virtualbox 的 Ubuntu 系统中源码下载完成后,使用如下命令进行编译

source build/envsetup.sh
lunch sdk_phone_x86_64
m

编译成功后,使用 emulator 命令启动模拟器的时候报错:

ERROR: x86_64 emulation currently requires hardware acceleration!
CPU acceleration status: KVM requires a CPU that supports vmx or svm
More info on configuring VM acceleration on Linux:
https://developer.android.com/studio/run/emulator-acceleration#vm-linux
General information on acceleration: https://developer.android.com/studio/run/emulator-acceleration.

而且在 Virtualbox 中使用 AndroidStudio 启动模拟器也会报错:
在这里插入图片描述
经过一番调查,发现这是一个无解的问题,结论是你无法在 Virtualbox 虚拟机的 Ubuntu 中运行Android模拟器。
相关问题链接:Android Emulator not starting in a Virtualbox Ubuntu Instance
关键信息:

You can’t do that for two reasons: the emulator use the Intel Virtualization Technology (VT) or the AMD Virtualization (AMD) extension but this is already used by the Ubuntu VM running inside the VirtualBox and you cannot use that a second time inside an already running VM.

翻译成中文:

您不能这样做有两个原因:模拟器使用英特尔虚拟化技术(VT)或AMD虚拟化(AMD)扩展,但这已经被VirtualBox内运行的Ubuntu VM使用,并且您不能在已经在运行的VM中第二次使用它。

意思就是说,Android模拟器使用的虚拟化技术扩展资源已经被 VB 虚拟机占用了,没有办法在 VB 虚拟机中第二次使用。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值