1.配置问题

参考教程链接,此文章已经写的很细致了,里面还有各种的其他配置或学习的链接:

尽量不要用ubuntu16的版本去编译,因为没有python3,最好升级到ubuntu 18的版本去编译;目前我编译的8.0.0_r1源码,但是同步下来的安卓系统源码包aosp-latest.tar已经有130G了(2021年9月)解压还需要很大的空间,我为了保险起见分配了300G的内存给虚拟机。

2.repo和python的冲突

repo可以看作就是python写的git扩展工具类,为了更好的管理Androd系统源码,需要注意的问题是当前谷歌的repo是以python3为基准写的,在我使用ubuntu16版本时python默认是2.7版本,所以执行 repo sync 命令时出现了各种问题:

Traceback (most recent call last):
 File "/xxx/.repo/repo/main.py", line 56, in <module>
from subcmds.version import Version
 File "/xxx/.repo/repo/subcmds/__init__.py", line 38, in <module>
['%s' % name])
 File "/xxx/.repo/repo/subcmds/upload.py", line 27, in <module>
from hooks import RepoHook
File "/xxx/.repo/repo/hooks.py", line 472
file=sys.stderr)
    ^
 SyntaxError: invalid syntax

原因就是无论是谷歌官方的还是清华源上的repo都是最新的,是以python3为基准做的

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
//国内
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo

只要我们去下载旧的版本repo文件就好了:

curl https://storage.googleapis.com/git-repo-downloads/repo-1 > ~/bin/repo

其实这在官网上有说明,我也是从官网上找到的这个版本,官网链接:

https://source.android.com/setup/develop?hl=zh-cn

3.repo sync 版本不一致问题  Could not reset index file to revision (无法将索引文件重置)

repo sync 从解压后的aosp中同步代码,但是出现了这个错误:

info: A new version of repo is available
warning: repo is not tracking a remote branch, so it will not receive updates
repo reset: error: Entry 'git_superproject.py' not uptodate. Cannot merge.
fatal: Could not reset index file to revision 'v2.15.4^0'

真的是一脑门官司,本来是以为bin目录下repo文件不是最新的,各种找文章搜索,终于在一个评论里找到了这个问题解决方法,步骤也是大同小异,感谢评论区的大神给的解答,要不然一点头绪都没有,解决方式就是:

cd 到.repo/repo
git reset --hard 倒数第二个commit
git pull
最后再repo sync就可以了

具体的原因我猜应该就是git 提交的版本不一致导致的,但是为什么是这个repo文件夹出的问题我也不清楚具体原因。

4.执行 make命令后出现的异常,各种异常,首先是ubuntu18 我们同步aosp的时候使用的是pyton3,但是编译的时候要改成python2

[记录] Ubuntu18.04 切换 Python 版本 | Python 技术论坛

5.libesd0安装失败 ,配置编译环境时,要安装各种软件:
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib
sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install lib32z-dev ccache
sudo apt-get install libssl-dev

有可能libesd0安装失败,解决方案:

6.去除本地化配置,make之前加上下面这句
export LC_ALL=C
7.各种编译警告
[ 15% 9460/61548] target thumb C: netperf <= external/netperf/src/nettest_bsd.c
external/netperf/src/nettest_bsd.c:4524:7: warning: variable 'len' is uninitialized when used here [-Wuninitialized]
        if ((len >=0) || SOCKET_EINTR(len)) {
             ^~~
external/netperf/src/nettest_bsd.c:4153:10: note: initialize the variable 'len' to silence this warning
  int len;
         ^
          = 0
1 warning generated.
[ 15% 9462/61548] target thumb C: netserver <= external/netperf/src/netserver.c
external/netperf/src/netserver.c:602:5: warning: variable 'do_inet6' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
    default:
    ^~~~~~~
external/netperf/src/netserver.c:607:9: note: uninitialized use occurs here
    if (do_inet6)
        ^~~~~~~~
external/netperf/src/netserver.c:570:15: note: initialize the variable 'do_inet6' to silence this warning
  int do_inet6;
              ^
               = 0
1 warning generated.

...........

external/neven/Embedded/common/src/b_BitFeatureEm/LocalScanDetector.c:678:81: warning: for loop has empty body [-Wempty-body]
                        for( iL = ( sizeL >> 1 ); iL < sizeL && actArrL[ idxArrL[ iL ] ] >= 0; iL++ );
                                                                                                     ^
external/neven/Embedded/common/src/b_BitFeatureEm/LocalScanDetector.c:678:81: note: put the semicolon on a separate line to silence this warning
1 warning generated.
[ 12% 7440/61548] target thumb C: libFFTEm <= external/neven/FaceRecEm/common/src/b_FDSDK/SDK.c
external/neven/FaceRecEm/common/src/b_FDSDK/SDK.c:209:42: warning: implicit conversion from enumeration type 'btk_Status' to different enumeration type 'btk_Error' [-Wenum-conversion]
        if( hsdkA->hidE != btk_HID_SDK )        return btk_STATUS_INVALID_HANDLE;
                                                ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
[ 13% 8005/61548] Check module type: out/target/product/generic/obj/SHARED_LIBRARIES/libreference-ril_intermediates/link_type
hardware/ril/reference-ril/Android.mk: warning: libreference-ril (native:platform) should not link to libril (partition:vendor)
[ 14% 8754/61548] Check Java library module types: out/target/common/obj/APPS/Dialer_intermediates/link_type
packages/apps/Dialer/Android.mk: warning: Dialer (java:system) should not link to libprotobuf-java-lite (java:platform)
[ 14% 8777/61548] target Java: volley (out/target/common/obj/JAVA_LIBRARIES/volley_intermediates/classes)
Note: external/volley/src/main/java/com/android/volley/RequestQueue.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

.........

2 warnings generated.
[ 40% 25139/61548] target thumb C++: camera.ranchu <= device/generic/goldfish/camera/EmulatedQemuCamera.cpp
In file included from device/generic/goldfish/camera/EmulatedQemuCamera.cpp:25:
In file included from device/generic/goldfish/camera/EmulatedQemuCamera.h:26:
device/generic/goldfish/camera/EmulatedQemuCameraDevice.h:55:14: warning: 'android::EmulatedQemuCameraDevice::Initialize' hides overloaded virtual function [-Woverloaded-virtual]
    status_t Initialize(const char* device_name);
             ^
device/generic/goldfish/camera/EmulatedCameraDevice.h:125:22: note: hidden overloaded virtual function 'android::EmulatedCameraDevice::Initialize' declared here: different number of parameters (0 vs 1)
    virtual status_t Initialize();
                     ^
In file included from device/generic/goldfish/camera/EmulatedQemuCamera.cpp:25:
device/generic/goldfish/camera/EmulatedQemuCamera.h:46:15: warning: 'android::EmulatedQemuCamera::Initialize' hides overloaded virtual function [-Woverloaded-virtual]
     status_t Initialize(const char* device_name,
              ^
device/generic/goldfish/camera/EmulatedCamera.h:75:22: note: hidden overloaded virtual function 'android::EmulatedCamera::Initialize' declared here: different number of parameters (0 vs 3)
    virtual status_t Initialize();
                     ^
2 warnings generated.

总之就是各种警告,但是最终却编译完成了,运行emulator出现:

emulator
emulator: WARNING: system partition size adjusted to match image file (2048 MB > 200 MB)

emulator: WARNING: data partition size adjusted to match image file (550 MB > 200 MB)

emulator: WARNING: encryption is off
sh: 1: glxinfo: not found
libGL error: MESA-LOADER: failed to open vmwgfx (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)
libGL error: failed to load driver: vmwgfx
libGL error: MESA-LOADER: failed to open swrast (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)
libGL error: failed to load driver: swrast

解决方案暂时没找到