1.1. Android Open Source Project 下载及编译

Android源码使用repo仓库来管理,需要使用repo进行下载。

curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo

1.1.1. 下载源码

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-8.0.0_r4
repo sync -j8

上面的命令指定了分支名称,如果init的时候未指定分支名称,在代码下载完成后,可以通过命令repo start android-8.0.0_r4 --all切换分支。

如果下载不下来,可以先指定repo的仓库路径

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'

1.1.2. 编译源码

source ./build/envsetup.sh
lunch // 选择编译的平台

make -j16

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_car_arm-userdebug
     8. aosp_car_arm64-userdebug
     9. aosp_car_x86-userdebug

如果编译后使用模拟器启动,可以选aosp_x86-eng

BUILDTYPE 指的是编译类型,有以下三种:

  • user:用来正式发布到市场的版本,权限受限,如没有 root 权限,不能 dedug,adb默认处于停用状态。
  • userdebug:在user版本的基础上开放了 root 权限和 debug 权限,adb默认处于启用状态。一般用于调试真机。
  • eng:开发工程师的版本,拥有最大的权限(root等),具有额外调试工具的开发配置。一般用于模拟器。

在启动编译前,可以通过 make clobber 检查环境是否ok。

编译过程需要配置ANDROID_JAVA_HOME和PATH路径,如果是首次编译,还需要指定路径。

export ANDROID_JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
export PATH=$(brew --prefix curl)/bin:$PATH

1.1.3. 启动模拟器

emulator

编译完成后,使用emulator命令启动模拟器。

1.1.4. 问题记录

Q:

build/core/main.mk:103: warning: ************************************************************
build/core/main.mk:104: warning: You are building on a case-insensitive filesystem.
build/core/main.mk:105: warning: Please move your source tree to a case-sensitive filesystem.
build/core/main.mk:106: warning: ************************************************************
build/core/main.mk:107: error: Case-insensitive filesystems not supported.

A: 创建大小写敏感分区

Q:

(error Error: could not find jdk tools.jar at $(HOST_JDK_TOOLS_JAR), please check if your JDK was installed correctly)

A: 配置环境变量ANDROID_JAVA_HOME

export ANDROID_JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home

Q:

error: ro.build.fingerprint cannot exceed 91 bytes: Android/mini_emulator_x86_64/mini-emulator-x86_64:8.0.0/OPR6.170623.010/ccfyyn10192339:userdebug/test-keys (106)
[ 26% 11427/43370] target  C++: libinit <= system/core/init/action.cpp

A:

build/tools/post_process_props.py 修改:PROP_VALUE_MAX = 127 bionic/libc/include/sys/system_properties.h 修改:#define PROP_VALUE_MAX 128

Q:

frameworks/native/cmds/installd/installd.cpp:43:1: error: static_assert failed "Size mismatch."

A: frameworks/native/cmds/installd/installd_deps.h 修改:constexpr size_t kPropertyValueMax = 128u;

Q:

FAILED: setup-jack-server

A: 在prebuilts/sdk/tools 目录下执行一下以下命令:

./jack-admin install-server jack-launcher.jar jack-server-4.11.ALPHA.jar

https://blog.csdn.net/qq_25564621/article/details/80253983

Q:

Jack server failed to (re)start, see Jack server log Unsupported curl, please use a curl not based on SecureTransport Unsupported curl, please use a curl not based on SecureTransport ninja: build stopped: subcommand failed. make: *** [ninja.intermediate] Error 1

A:

brew install curl --with-openssl
export PATH=$(brew --prefix curl)/bin:$PATH

https://blog.csdn.net/u012915455/article/details/52382630

Q:

out/target/product/mini-emulator-x86_64/obj/STATIC_LIBRARIES/libext_intermediates/initext.c:130:13: error: invalid suffix '_init' on integer constant
 libxt_set-1_init();

A: 把上述问题中的initext.c文件中的 libxt_set-1_init 修改成 libxt_set_1_init

Q:

'linux/netfilter/xt_connmark.h' file not found

A: 在external/iptables/include/linux/netfilter目录下创建xt_connmark.h文件

https://blog.csdn.net/bulreed/article/details/44950085 http://git.oschina.net/androidsourcecode/external_iptables/tree/master/include/linux

Q:

out/target/product/generic/obj/STATIC_LIBRARIES/libext_intermediates/libxt_dscp.c:45: error: 'XT_DSCP_MAX' undeclared here (not in a function)

A:

diff --git a/include/linux/netfilter/xt_DSCP.h b/include/linux/netfilter/xt_DSCP.h
-/* target info */
-struct xt_DSCP_info {
+#define XT_DSCP_MASK   0xfc    /* 11111100 */
+#define XT_DSCP_SHIFT  2
+#define XT_DSCP_MAX    0x3f    /* 00111111 */

https://stackoverflow.com/questions/8273823/how-can-i-discard-modified-files

Q:

BISON_PKGDATADIR=external/bison/data prebuilts/misc/darwin-x86/bison/bison -d

A:

在log中出现BSION等字样,这个bsion的一个bug,解决方法:拉取新的分支,重新编译 bison:

#cd external/bison
#git cherry-pick c0c852bd6fe462b148475476d9124fd740eba160

如果这步骤发生错误了(比如之前删除了.repo文件夹),这时候我们就把bison这个文件夹删除,下载一个新的:

wgethttps://android.googlesource.com/platform/external/bison/+archive/c0c852bd6fe462b148475476d9124fd740eba160.tar.gz

解压后进入bison文件夹,执行:

# mm
# cp out/host/darwin-x86/bin/bison prebuilts/misc/darwin-x86/bison/

https://www.linuxidc.com/Linux/2019-07/159303.htm

Q:

internal error: Could not find a supported mac sdk: ["10.10" "10.11" "10.12" "10.13"]

A:

https://www.cnblogs.com/larack/p/9646860.html

参考链接

results matching ""

    No results matching ""