1、Mac OS 会在一个保留大小写但不区分大小写的文件系统中运行,因此需要创建区分大小写的磁盘映像。在此磁盘中下载aosp,完成编译。
创建40G磁盘空间:
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/android.dmg
调整大小:
hdiutil resize -size <new-size-you-want>g ~/android.dmg.sparseimage
装载磁盘:
mountAndroid() { hdiutil attach ~/android.dmg -mountpoint /Volumes/android; }
卸载磁盘:
umountAndroid() { hdiutil detach /Volumes/android; }
2、安装brew JDK
3、安装Xcode命令行工具
xcode-select --install
(1)
安装MacPorts
前往macports.org下载
vim ~/.bash_profile添加:
export PATH=/opt/local/bin:$PATH
通过 MacPorts 获取 Make、Git 和 GPG 软件包
POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg
可选 brew install gnupg git
报错:
Error: Port gnupg not found
---> Some of the ports you installed have notes:
libidn has the following notes:
Please be aware that GNU libidn2 is the successor of GNU libidn. It
comes with IDNA 2008
and TR46 implementations and also provides a compatibility layer for GNU
libidn.
libpsl has the following notes:
libpsl API documentation is provided by the port 'libpsl-docs'.
python27 has the following notes:
To make this the default Python or Python 2 (i.e., the version run by
the 'python' or 'python2' commands), run one or both of:
sudo port select --set python python27
sudo port select --set python2 python27
rsync has the following notes:
To use the rsyncd server you must copy
/opt/local/etc/rsyncd.conf.example to rsyncd.conf and add your modules
there. See 'man rsyncd.conf' for more information.
A startup item has been generated that will aid in starting rsync with
launchd. It is disabled by default. Execute the following command to
start it, and to cause it to launch at startup:
sudo port load rsync
解决:先执行 sudo port -d sync
然后 sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
然后 POSIXLY_CORRECT=1 sudo port install gnupg2
如果您使用的是 Mac OS X v10.4,还需要安装 bison
POSIXLY_CORRECT=1 sudo port install bison
设置文件描述符数量上限和编译器缓存
vim ~/.bash_profile 添加
# set the number of open files to be 1024
ulimit -S -n 1024
# Compiler cache
export USE_CCACHE=1
4、下载源代码
安装Repo(如果用brew安装过repo,可省略)
在主目录下创建bin目录
mkdir ~/bin
PATH=~/bin:$PATH
下载Repo
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
清华:
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo
初始化Repo客户端
创建一个空目录存放源代码
mkdir aosp9
cd aosp9
配置git
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
选择下载版本
google :repo init -u https://android.googlesource.com/platform/manifest -b android-9.0.0_r22
清华 :repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-9.0.0_r22
报错:repo: command not found
解决:echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
export PATH=$PATH:$HOME/bin
报错:python3
解决:vim ~/.bash_profile
将python默认版本改为python2.7
报错:fatal: unable to access 'https://gerrit.googlesource.com/git-repo/': OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to gerrit.googlesource.com:443
fatal: cloning the git-repo repository failed, will remove '.repo/repo'
解决:vim ~/.bashrc
添加 export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
下载
repo sync
5、编译
build aosp9 for Raspberry Pi 3 Model B & B+
1 Download Raspbery Pi 3 device configuration files
$ mkdir -pv device/brobwind
$ git clone git://github.com/brobwind/pie-device-brobwind-rpi3 device/brobwind/rpi3
2 Add local manifest file
$ mkdir -p .repo/local_manifests
$ ln -sv ../../device/brobwind/rpi3/local_manifest.xml .repo/local_manifests/
$ repo sync
3 Apply patch to Android framework
path:/Users/zhangzhiqiang/aosp9/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index cd8fdbf..6918bc3 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -769,7 +769,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
// appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
// layers the ability to match their parent sizes and be able to skip
// such arbitrary size settings.
- mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
+ mSurfaceSize = (int)(Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 1.4);
final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
.setSize(mSurfaceSize, mSurfaceSize)
4 Configure build environment
$ . build/envsetup.sh
$ lunch rpi3-eng
5 Build taret
$ m -j
报错:internal error: Could not find a supported mac sdk: ["10.10" "10.11" "10.12" "10.13"]
ninja: build stopped: subcommand failed.
19:18:50 soong bootstrap failed with: exit status 1
#### failed to build some targets (16 seconds) ####
解决:
第一种:
查看macOS sdk版本
xcodebuild -showsdks
vim AOSP/build/soong/cc/config/x86_darwin_host.go
添加
darwinSupportedSdkVersions = []string{
"10.10",
"10.11",
"10.12",
"10.13",
"10.14", // 添加mac sdk 10.14
}
第二种:https://github.com/phracker/MacOSX-SDKs 下载10.13
放入 Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ 目录下
报错:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOTypes.h:38:10: fatal error: 'IOKit/IOReturn.h' file not found
#include <IOKit/IOReturn.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
[ 18% 18626/102652] //system/core/libunwindstack:libunwindstack_dex clang++ DexFiles.cpp [arm]
ninja: build stopped: subcommand failed.
12:52:30 ninja failed with: exit status 1
#### failed to build some targets (36:36 (mm:ss)) ####
解决:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
安装头文件
Xcode降级
Then you will get following images in the out/target/product/rpi3 folder:
rpiboot.img
boot.img
system.img
vendor.img
userdata.img