Before we start this job, let’s check how my laptop looks. Here are some factors of my M1 MacBook Pro 2020
- OS version : macOS Monterey 12.1 Beta (21C5021h)
- Chipset: Apple M1
- Memory size: 16 GB
First of all, you will need to install the XCode command-line tools.
1 | xcode-select --install |
And, you should also install Rosetta
for code-building.
1 | /usr/sbin/softwareupdate --install-rosetta |
When I tried to install Rosetta, I found some system errors, and I can’t solve that, but it seems that doesn’t matter. You can still build the AOSP project.
Now, we should prepare a case-sensitive disk image cause the AOSP should build on the Ubuntu system, but MacOS is not a case-sensitive file system ref.
1 | hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 350g ~/aosp_source.dmg |
After this, let’s create a ZSH environment. You might first time hear about ZSH. Here are some helpful tools for empowering your ZSH env, such as Oh My Zsh, Powerlevel10k, etc. I highly recommend that you try PowerLevel10k, a successor of the powerlevel9k, and it’s a perfect theme for ZSH env.
When you finish up installing/setting the ZSH, we need to create and edit the .zshenv
with the following content:
1 | # set the number of open files to be 2048 |
Let’s use this env setting and start downloading the AOSP code. We are going to use android-11.0.0_r48 for the building.
1 | $ source ~/.zshenv |
Here are some commands to build AOSP:
1 | $ source build/envsetup.sh |
Then, you can start enjoying the AOSP journey now.
[Reference]
[Q&A]
Could not find a supported mac sdk: [“10.10” “10.11” “10.12” “10.13” “10.14” “10.15”]?
If you see this error message, you can check your MacOSX SDK under
1
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
To make sure you have correct SDKs for building. If you can’t see the needed SDKs under this folder, there are two ways you can solve this error:
a. You can download corresponding SDKs from
https://github.com/phracker/MacOSX-SDKs
and put these SDKs into the folder.b. You can edit the
build/soong/cc/config/x86_darwin_host.go
and add your current pointed SDK into this file.
When seeing : system/core/base/cmsg.cpp:36:21: error: use of undeclared identifier
PAGE_SIZE
Add this line into the file
size_t psize = getpagesize();
1
2
3
4
5
namespace base {
size_t psize = getpagesize();
ssize_t SendFileDescriptorVector(borrowed_fd sockfd, const void* data, size_t len,
...
And then, replace the two distances of the PAGE_SIZE with `psize`.
1
if (cmsg_space >= psize) {
When seeing
Segmentation fault: 11
Edit this file
system/sepolicy/tests/Android.bp
by deleting this linelibc++_static
and then re-compile.Check this official fix from google.
- When seeing these errors
1
2
3
4
5
external/python/cpython2/Modules/getpath.c:414:50: error: incompatible pointer types passing 'unsigned long *' to parameter of type 'uint32_t *' (aka 'unsigned int *') [-Werror,-Wincompatible-pointer-types]
else if(0 == _NSGetExecutablePath(progpath, &nsexeclength) && progpath[0] == SEP)
^~~~~~~~~~~~~
or
1
2
3
4
5
external/python/cpython3/Modules/getpath.c:414:50: error: incompatible pointer types passing 'unsigned long *' to parameter of type 'uint32_t *' (aka 'unsigned int *') [-Werror,-Wincompatible-pointer-types]
else if(0 == _NSGetExecutablePath(progpath, &nsexeclength) && progpath[0] == SEP)
^~~~~~~~~~~~~
You can solve these errors by modifying them.
1
2
3
4
5
6
7
uint32_t nsexeclength = MAXPATHLEN;
unsigned long nsexeclength = MAXPATHLEN;
to
1
2
3
uint32_t nsexeclength = MAXPATHLEN;
#Android #Android/Build