背景

编译6.0.1版本自己刷机到nexus 5x中

代码下载

这一步忽略,方法很多,我们直接开始编译遇到的问题。

遇到问题和解决方法

编译6.0系统需要openjdk 7

编译5.1系统需要jdk7,如果需要编译5.1的后面再出文章吧。

编译前提

删除源码目录下所有git

1
2
3
4
find ./ -name ".git" | xargs rm -rf

//大小
du -sh -BG

下载openjdk7

链接:https://pan.baidu.com/s/1u_GcyI-nrrQPLv_NQ2CwRg
提取码:0jt0

信不过网盘的可以去这里下
https://jdk.java.net/java-se-ri/7

1
2
3
4
5
6
7
8
9
10
11
12
13
14

sudo tar zxvf openjdk-7u75-b13-linux-x64-18_dec_2014.tar.gz -C /opt
# 修改profile文件
sudo gedit /etc/profile

# 加入下面的配置
export JAVA_HOME=/opt/java-se-7u75-ri
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

# 更新profile文件
source /etc/profile

继续修改其他mk文件

1
2
3
4
5
sudo gedit build/envsetup.sh
# 搜索 ANDROID_SET_JAVA_HOME
# 将刚才解压的jdk路径粘贴到下方的 JAVA_HOME 变量中

比如我的修改之后

图片描述

1
2

sudo gedit build/core/main.mk

注释这一句,让脚步正常,不能断。

图片描述

继续修改:

在源代码的根目录下找到 build/core/clang/HOST_x86_common.mk文件,打开文件找到 CLANG_CONFIG_x86_LINUX_HOST_EXTRA_ASFLAGS 的定义,在后面增加一行

1
-B$($(clang_2nd_arch_prefix)HOST_TOOLCHAIN_FOR_CLANG)/x86_64-linux/bin

图片描述

编译之后,可能遇到的错误,但是这是我的,错误后面有解决方法。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Notice file: external/guava/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//framework/guavalib.jar.txt
Notice file: external/jsilver/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//framework/jsilver.jar.txt
host Java: tagsouplib (out/host/common/obj/JAVA_LIBRARIES/tagsouplib_intermediates/classes)
Notice file: external/doclava/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//framework/doclava.jar.txt
Export includes file: external/boringssl/Android.mk -- out/host/linux-x86/obj/SHARED_LIBRARIES/libcrypto-host_intermediates/export_includes
Export includes file: external/boringssl/Android.mk -- out/host/linux-x86/obj/SHARED_LIBRARIES/libssl-host_intermediates/export_includes
Import includes file: out/host/linux-x86/obj/SHARED_LIBRARIES/libcrypto-host_intermediates/import_includes
Export includes file: external/conscrypt/Android.mk -- out/host/linux-x86/obj/EXECUTABLES/conscrypt_generate_constants_intermediates/export_includes
Notice file: external/conscrypt/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//bin/conscrypt_generate_constants.txt
Notice file: external/boringssl/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//lib64/libssl-host.so.txt
Notice file: external/boringssl/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//lib64/libcrypto-host.so.txt
Notice file: external/jarjar/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//framework/jarjar-apache-ant.jar.txt
Notice file: external/jarjar/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//framework/jarjar-maven-plugin-api.jar.txt
Notice file: external/jarjar/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//framework/jarjar.jar.txt
Import includes file: out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/import_includes
Yacc: aidl <= frameworks/base/tools/aidl/aidl_language_y.y
prebuilts/misc/linux-x86/bison/bison -d -o out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp frameworks/base/tools/aidl/aidl_language_y.y
Export includes file: frameworks/base/tools/aidl/Android.mk -- out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/export_includes
Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l
touch out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.hpp
Notice file: frameworks/base/tools/aidl/NOTICE -- out/host/linux-x86/obj/NOTICE_FILES/src//bin/aidl.txt
echo '#ifndef 'aidl_language_y_h > out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.h
flex-2.5.39: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
echo '#define 'aidl_language_y_h >> out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.h
cat out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.hpp >> out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.h
Export includes file: frameworks/base/libs/androidfw/Android.mk -- out/host/linux-x86/obj/STATIC_LIBRARIES/libandroidfw_intermediates/export_includes
Export includes file: frameworks/base/tools/aapt/Android.mk -- out/host/linux-x86/obj/STATIC_LIBRARIES/libaapt_intermediates/export_includes
echo '#endif' >> out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.h
build/core/binary.mk:646: recipe for target 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp' failed
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Aborted (core dumped)
make: *** Waiting for unfinished jobs....
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:8: warning: tag "sysui_statusbar_touch" (36000) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:8


works/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:8
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:9: warning: tag "sysui_heads_up_status" (36001) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:9
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:10: warning: tag "sysui_fullscreen_notification" (36002) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:10
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:11: warning: tag "sysui_heads_up_escalation" (36003) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:11
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:19: warning: tag "sysui_status_bar_state" (36004) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:19
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:24: warning: tag "sysui_panelbar_touch" (36010) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:24
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:29: warning: tag "sysui_notificationpanel_touch" (36020) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:29
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:38: warning: tag "sysui_lockscreen_gesture" (36021) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:38
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:43: warning: tag "sysui_quickpanel_touch" (36030) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:43
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:48: warning: tag "sysui_panelholder_touch" (36040) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:48
frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:53: warning: tag "sysui_searchpanel_touch" (36050) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:53
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

#### make failed to build some targets (51 seconds) ####

如果你希望编译不出错,就先执行下面的东西吧。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

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


sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utilsxsltproc zlib1g-dev:i386

sudo apt-get install git gnupg flex bison gperf build-essential zip curllibc6-dev libncurses5-dev:i386 x11proto-core-dev

sudo apt-get install bc

sudo apt-get install lzop

sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386

sudo apt-get install bison

sudo apt-get install libxml2-utils

sudo apt-get install curl

//根目录执行
export LC_ALL=C

export LC_ALL=C
make -j8前执行

最后就是执行编译了

1
2
3
代码根目录下
export LC_ALL=C
make -j8

图片描述

虚拟机配置了8g内存,几年前的台式机配置编译1.5小时这样。

如果配件都装好了,命令流程就这样的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//载入环境
aosp@ubuntu:~/android/android-6.0.1_r1$ source build/envsetup.sh
including device/asus/deb/vendorsetup.sh
including device/asus/flo/vendorsetup.sh
including device/asus/fugu/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-mips/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/htc/flounder/vendorsetup.sh
including device/huawei/angler/vendorsetup.sh
including device/lge/bullhead/vendorsetup.sh
including device/lge/hammerhead/vendorsetup.sh
including device/moto/shamu/vendorsetup.sh
including sdk/bash_completion/adb.bash

aosp@ubuntu:~/android/android-6.0.1_r1$ lunch

You're building on Linux

Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_arm64-eng
3. aosp_mips-eng
4. aosp_mips64-eng
5. aosp_x86-eng
6. aosp_x86_64-eng
7. aosp_deb-userdebug
8. aosp_flo-userdebug
9. full_fugu-userdebug
10. aosp_fugu-userdebug
11. mini_emulator_arm64-userdebug
12. m_e_arm-userdebug
13. mini_emulator_mips-userdebug
14. mini_emulator_x86-userdebug
15. mini_emulator_x86_64-userdebug
16. aosp_flounder-userdebug
17. aosp_angler-userdebug
18. aosp_bullhead-userdebug
19. aosp_hammerhead-userdebug
20. aosp_hammerhead_fp-userdebug
21. aosp_shamu-userdebug

Which would you like? [aosp_arm-eng]

编译模拟器选择5,也就是输入5,回车

Which would you like? [aosp_arm-eng] 5

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=6.0.1
TARGET_PRODUCT=aosp_x86
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=x86
TARGET_ARCH_VARIANT=x86
TARGET_CPU_VARIANT=
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.15.0-147-generic-x86_64-with-Ubuntu-18.04-bionic
HOST_BUILD_TYPE=release
BUILD_ID=MMB29K
OUT_DIR=out
============================================

aosp@ubuntu:~/android/android-6.0.1_r1$


export LC_ALL=C
make -j8

最后祝你好运~~~

欢迎关注公众号:黄大官AOSP