编译android源码xcode,MacOS 10.13 编译 Android 源码

前言

原来下载下来编译其实还挺简单的,直接照官方指导执行就行了,结果现在再编译就各种问题,搞了大半天才算彻底搞定,主要是因为系统、软件等版本问题,记录下,避免以后别人再采坑了。

以下顺序不要搞错,不然会来回返工反而费时费力:

检查 jdk 版本

检查 Xcode 版本

检查 Xcode 命令行工具是否安装

安装 MacPorts

安装 Make、git、GPG 等

编译

环境准备

切换 Java 版本到 1.7

关于 java sdk 的版本要求可以看 jdk 版本要求

我要编译的是 Android 6.0,需要的 java 版本是 1.7,但是我平时使用的是 1.8,所以可以在 ~/.bash_profile 添加如下代码:

export JAVA_7_HOME="$(/usr/libexec/java_home -v 1.7)"

export JAVA_8_HOME="$(/usr/libexec/java_home -v 1.8)"

#默认JDK 8

export JAVA_HOME=$JAVA_8_HOME

alias jdk7="export JAVA_HOME=$JAVA_7_HOME"

alias jdk8="export JAVA_HOME=$JAVA_8_HOME"

当编译 Android 版本时直接命令行执行如下命令就可以直接切换到 Java 1.7 了:

jdk7

Xcode 降级

对于 Xcode 9.0 版本的童鞋需要降级到 8.+ 版本才可使用,不然报错如下:

In file included from external/libcxxabi/src/cxa_exception.cpp:18:

external/libcxx/include/cstdlib:159:44: error: declaration conflicts with target of using declaration already in scope

inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);}

^

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:111:44: note: target of using declaration

inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);}

^

external/libcxx/include/cstdlib:134:9: note: using declaration

using ::abs;

^

external/libcxx/include/cstdlib:161:44: error: declaration conflicts with target of using declaration already in scope

inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}

122fff2d4e37

xcode_downgrade_tip.png

完整卸载 Xcode 9,依次删除如下文件(或者使用其他工具)

/Applications/Xcode.app

/Library/Preferences/com.apple.dt.Xcode.plist

~/Library/Preferences/com.apple.dt.Xcode.plist

~/Library/Caches/com.apple.dt.Xcode

~/Library/Application Support/Xcode

~/Library/Developer

下载 Xcode 8.3.3,解压缩并拖入 /Application 中后点击安装

安装 Xcode 命令行工具,执行命令如下:

xcode-select --install

安装 MacPorts

请确保 /opt/local/bin 在路径中显示在/usr/bin 前面。否则,请将以下内容添加到 ~/.bash_profile 文件中:

export PATH=/opt/local/bin:$PATH

安装 Make、git、GPG 等

POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg2

编译

然后就是编译啦,在源文件根目录(此处我的示例就是 /Volumes/android/android-6.0.1_r77)依次执行如下命令:

清空以前编译操作的遗留的输出

make clobber

初始化环境

source build/envsetup.sh

选择要编译的目标:

lunch

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]

然后选择你想执行的,我选的是 aosp_hammerhead-userdebug,然后 Enter 键执行选择

编译

make -j8

122fff2d4e37

make_completed.png

硬件配置:2015顶配 MBP,Intel i7 2.5GHz、4核、16G内存、500 ssd,用时 1小时 11分钟

刷机

先转到 FastBoot 模式,执行命令如下:

adb reboot bootloader

跳转到输出 img 的目录:

cd 源码位置/out/target/product/hammerhead/

然后就是刷机啦(这样刷机数据可都是会丢失的哈,注意用测试机):

fastboot -w flashall

MacOS 10.13 常见的一些错误:

gnupg2

Error: gnupg has been deprecated. If you absolutely want to stay on the classic version, install the gnupg1 port. All other users are recommended to install gnupg2.

如文中所示,gnupg 已经被废弃了,但是有可能任然需要用,所以安装的时候要安装 gnupg2

POSIXLY_CORRECT=1 sudo port install gnupg2

MacOS sdk

build/core/combo/mac_version.mk:38: *****************************************************

build/core/combo/mac_version.mk:39: * Can not find SDK 10.6 at /Developer/SDKs/MacOSX10.6.sdk

build/core/combo/mac_version.mk:40: *****************************************************

build/core/combo/mac_version.mk:41: *** Stop.. Stop.

122fff2d4e37

macos_sdk_tip.png

顾名思义,就是缺少了 MacOS sdk,直接非官方下载就可以了,下载到的文件是 MacOSX10.11.sdk.tar.xz 文件

先解压缩:

tar -xf MacOSX10.11.sdk.tar.xz

然后将解压得到的 MacOSX10.11.sdk文件夹复制到/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs文件夹下

Xcode 命令行工具没有安装或者版本问题

Yacc: libmcldScript <= frameworks/compile/mclinker/lib/Script/ScriptParser.yy

prebuilts/misc/darwin-x86/bison/bison -d -o out/host/darwin-x86/obj/STATIC_LIBRARIES/libmcldScript_intermediates/ScriptParser.cpp frameworks/compile/mclinker/lib/Script/ScriptParser.yy

frameworks/compile/mclinker/lib/Script/ScriptParser.yy:28.1-5: invalid directive: `%code'

frameworks/compile/mclinker/lib/Script/ScriptParser.yy:28.7-14: syntax error, unexpected identifier

make: *** [out/host/darwin-x86/obj/STATIC_LIBRARIES/libmcldScript_intermediates/ScriptParser.cpp] Error 1

make: *** Waiting for unfinished jobs....

122fff2d4e37

xcode_commandline_tip.png

如果没有安装执行如下命令安装:

xcode-select --install

如果已经安装但仍有问题,可以删除后重新安装:

sudo rm -rf /Library/Developer/CommandLineTools

xcode-select --install

bison

make: *** [out/host/darwin-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] Abort trap: 6

make: *** Waiting for unfinished jobs....

122fff2d4e37

bison_error_tip.png

具体原因可见 build aosp on Mac OS 10.13 failed,原因就是直接下载下来的源码中的 bison 版本中包含一个 bug,官方也已修复,所以直接下载官方的最新版本替换即可

解压缩

在解压缩的到文件的根目录下直接执行

./configure

make

make install

安装成功后复制最新的可执行文件 /bison 所在的位置/src/bison到 /Android 源码所在位置/android-6.0.1_r77/prebuilts/misc/darwin-x86/bison/

liuxiaoquan@192 ComfyUI % pip install sentencepiece Collecting sentencepiece Using cached sentencepiece-0.2.0.tar.gz (2.6 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Building wheels for collected packages: sentencepiece Building wheel for sentencepiece (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for sentencepiece (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [134 lines of output] /private/var/folders/58/s36ty3bn6bbd05gf79j9fg4w0000gn/T/pip-build-env-vf9ck0_e/overlay/lib/python3.13/site-packages/setuptools/_distutils/dist.py:289: UserWarning: Unknown distribution option: 'test_suite' warnings.warn(msg) /private/var/folders/58/s36ty3bn6bbd05gf79j9fg4w0000gn/T/pip-build-env-vf9ck0_e/overlay/lib/python3.13/site-packages/setuptools/dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: Apache Software License See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! self._finalize_license_expression() running bdist_wheel running build running build_py creating build/lib.macosx-10.13-universal2-cpython-313/sentencepiece copying src/sentencepiece/__init__.py -> build/lib.macosx-10.13-universal2-cpython-313/sentencepiece copying src/sentencepiece/_version.py -> build/lib.macosx-10.13-universal2-cpython-313/sentencepiece copying src/sentencepiece/sentencepiece_model_pb2.py -> build/lib.macosx-10.13-u
最新发布
05-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值