1. 准备环境
- PC
- 系统:Mac OSX 10.14.4 (18E226)
- 至少250GB固态硬盘
- JDK 1.8.0_171
- Xcode 10 SDK
- Android SDK
- Mobile
- 设备: Google Pixel
2. 配置环境
-
2.1 创建大小写敏感的磁盘镜像
# 可以通过磁盘管理工具进行设置,也可以通过以下命令生成250g的镜像文件 $ hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 250g -volname android android.dmg android.dmg 表示当前目录下生成android.dmg.sparseimage
-
2.2 将镜像文件转为可读写磁盘
# 稍微会等一会,我的移动硬盘 # 已耗时: 6m 10.512s # 速度:414.6M 字节/秒 $ hdiutil convert android.dmg.sparseimage -format UDRW -o android.dmg
PS: 创建镜像的目的是方便移动,大文件移动挺快。无所谓的可以直接在大小写敏感的硬盘(磁盘管理工具格式化为大小写敏感)上直接操作,省去这一步。
# 查询当前目录所在分区的分区是否大小写敏感 $ diskutil info . | grep Name
3.下载源码
-
3.1 下载repo工具并且给这个工具可执行权限
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo -O repo & chmod +x repo
-
3.2 源码地址
# 推荐使用清华大学TUNA镜像源,使用每月更新的初始化包进行下载更新。具体步骤请看 https://mirror.tuna.tsinghua.edu.cn/help/AOSP/
-
3.3 同步分支
android-9.0.0_r36
源码,需要获取所有源码可以先repo sync
,然后再切换分支(我获取的所有源码,编译+源码总共200GB)# 查看可切换的分支 $ cd .repo/manifests $ git branch -a | cut -d / -f 3 # 切换到9.0分支 $ repo init -b android-9.0.0_r36 # long time ..., 报错继续repo sync $ repo sync # 直到显示下面内容,即为同步完成 Syncing work tree:100%,done.
- 同步源码报错,其他依赖环境貌似我这之前装过,没遇到其他错误
warning: gpg (GnuPG) is not available. warning: Installing it is strongly encouraged. # 解决方法: $ brew install gpg
4. 编译源码
-
4.1 首先进入
bash
环境$ bash
-
4.2 初始化编译环境
bash-5.0$ source build/envsetup.sh including device/generic/car/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-mips64/vendorsetup.sh including device/generic/mini-emulator-x86/vendorsetup.sh including device/generic/mini-emulator-x86_64/vendorsetup.sh including device/generic/uml/vendorsetup.sh including device/google/crosshatch/vendorsetup.sh including device/google/cuttlefish/vendorsetup.sh including device/google/marlin/vendorsetup.sh including device/google/muskie/vendorsetup.sh including device/google/taimen/vendorsetup.sh including device/linaro/hikey/vendorsetup.sh including sdk/bash_completion/adb.bash
-
4.3 配置编译信息
访问https://developers.google.com/android/images得到对应设备的combo名称,这里Pixel
对应sailfish
这里执行
lunch
后输入45
,或者输入aosp_sailfish-userdebug
$ lunch You're building on Darwin Lunch menu... pick a combo: ... 45. aosp_sailfish-userdebug ... Which would you like? [aosp_arm-eng] 45 ============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=9 TARGET_PRODUCT=aosp_sailfish TARGET_BUILD_VARIANT=userdebug TARGET_BUILD_TYPE=release TARGET_ARCH=arm64 TARGET_ARCH_VARIANT=armv8-a TARGET_CPU_VARIANT=kryo TARGET_2ND_ARCH=arm TARGET_2ND_ARCH_VARIANT=armv8-a TARGET_2ND_CPU_VARIANT=kryo HOST_ARCH=x86_64 HOST_2ND_ARCH=x86 HOST_OS=darwin HOST_OS_EXTRA=Darwin-18.5.0-x86_64-10.14.4 HOST_BUILD_TYPE=release BUILD_ID=PQ3A.190505.001 OUT_DIR=out ============================================
BUILD_ID=PQ3A.190505.001
这里提前把BUILD_ID
对应的设备驱动下载好,访问https://developers.google.com/android/drivers得到Pixel binaries for Android 9.0.0 (PQ3A.190505.001)的两个驱动,解压后放入源码目录下解压。解压后再执行对应的sh脚本即可。(用于编译好源码后,线刷安卓系统到Pixel手机上。)
PS: 执行shell脚本时需要同意协议,^ + c
快捷键可以快速跳过协议阅读,直接弹出同意协议输入位置。
-
4.4 开始构建
- 脚本(ccache.sh)
#!/usr/bin/env bash export USE_CCACHE=1 #开启CCACHE。此配置可以提高二次全编译的速度。可以添加到.bashrc文件中, export CCACHE_DIR=./.ccache #设置缓存目录的路径。也可以添加到.bashrc文件中, # prebuilts/misc/linux-x86/ccache/ccache -M 50G #设置缓存目录的大小。这个配置一次即可。 prebuilts/misc/darwin-x86/ccache/ccache -M 50G #设置缓存目录的大小。这个配置一次即可。
# 启动ccache缓存 $ sh ccache.sh # 开40个线程编译,等待编译完成 $ make -j40
-
遇到的报错
# 找不到jdk,这个在根目录的.bash_profile文件中添加
解决方法:
export ANDROID_JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
# 报错找不到对应的MacOSX.sdk,比如找不到MacOSX10.13.sdk ============================================ [1/1] out/soong/.minibootstrap/minibp out/soong/.bootstrap/build.ninja [55/56] glob prebuilts/ndk/stl.bp [77/77] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja FAILED: out/soong/build.ninja out/soong/.bootstrap/bin/soong_build -t -l out/.module_paths/Android.bp.list -b out/soong -n out -d out/soong/build.ninja.d -o out/soong/build.ninja Android.bp internal error: Could not find a supported mac sdk: ["10.10" "10.11" "10.12" "10.13"] ninja: build stopped: subcommand failed. 11:57:25 soong bootstrap failed with: exit status 1 #### failed to build some targets (16 seconds) ####
解决方法:下载Mac OSX SDK,Clone下来复制
MacOSX10.13.sdk
到目录/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
下(我测试的10.13版本,其他版本自测)# 报错sdm710 target not found [1/1] out/soong/.minibootstrap/minibp out/soong/.bootstrap/build.ninja FAILED: out/soong/.bootstrap/build.ninja out/soong/.minibootstrap/minibp -t -l out/.module_paths/Android.bp.list -b out/soong -n out -d out/soong/.bootstrap/build.ninja.d -o out/soong/.bootstrap/build.ninja Android.bp internal error: could not open symlink hardware/qcom/sdm710/Android.bp; its target (display/os_pickup.bp) cannot be opened ninja: build stopped: subcommand failed. 11:02:11 soong minibootstrap failed with: exit status 1 #### failed to build some targets (1 seconds) ####
解决方法:git clone 该链接的目录文件到
hardware/qcom/sdm710
目录下(全部clone)
https://android.googlesource.com/platform/hardware/qcom/sdm710/ -
4.5 编译完成
#### build completed successfully (25 seconds) ####
5. 修改源码
-
5.1 去掉wifi感叹号
// 去掉感叹号 // 进入文件夹 // /Volumes/sandisk/aosp/frameworks/base/services/core/java/com/android/server/connectivity/NetworkMonitor.java // 修改地址链接为如下 // private static final String DEFAULT_HTTPS_URL = "https://www.google.com/generate_204"; private static final String DEFAULT_HTTPS_URL = "https://www.qualcomm.cn/generate_204"; private static final String DEFAULT_HTTP_URL = // "http://connectivitycheck.gstatic.com/generate_204"; "http://www.qualcomm.cn/generate_204"; // private static final String DEFAULT_FALLBACK_URL = "http://www.google.com/gen_204"; private static final String DEFAULT_FALLBACK_URL = "http://www.qualcomm.cn/generate_204"; private static final String DEFAULT_OTHER_FALLBACK_URLS = // "http://play.googleapis.com/generate_204"; "http://www.qualcomm.cn/generate_204";
-
5.2 默认adb为root
ro.secure=0
即可/Volumes/sandisk/aosp/build/make/core/main.mk ## user/userdebug ## user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT)) enable_target_debugging := true tags_to_install := ifneq (,$(user_variant)) # Target is secure in user builds. ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0 ADDITIONAL_DEFAULT_PROPERTIES += security.perf_harden=1 ifeq ($(user_variant),user) ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=0 endif ifeq ($(user_variant),userdebug) # Pick up some extra useful tools tags_to_install += debug else # Disable debugging in plain user builds. enable_target_debugging := endif # Disallow mock locations by default for user builds ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1 else # !user_variant # Turn on checkjni for non-user builds. ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1 # Set device insecure for non-user builds. ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0 # Allow mock locations by default for non user builds ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1 endif # !user_variant
-
5.3 修改默认输入法(参考其他文章)
在
/Volumes/sandisk/aosp/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
添加如下内容:<string name="def_default_input_method" translatable="false">com.google.android.inputmethod.pinyin/.PinyinIME</string> <string name="def_enabled_input_methods" translatable="false">com.google.android.inputmethod.pinyin/.PinyinIME</string>
在
/Volumes/sandisk/aosp/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
方法内添加如下内容:loadStringSetting(stmt, Secure.ENABLED_INPUT_METHODS, R.string.def_default_input_method);
在
/Volumes/sandisk/aosp/packages/apps/
创建GoogleInput
文件夹,进入GoogleInput
创建Android.mk
文件,添加如下内容:LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := GoogleInput LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT) LOCAL_MULTILIB := 64
将GoogleInput.apk放入该目录下
在
build/make/target/product/core.mk
文件中修改如下:PRODUCT_PACKAGES += \ 移除Latin \ 末尾新增GoogleInput
编译模块:
# 编译系统镜像 $ mmm packages/apps/GoogleInput/ $ make snod
-
5.4 修改系统名称
修改
/device/google/marlin/aosp_sailfish.mk
文件内容为:PRODUCT_MODEL := Pixel
编译模块:
# 编译系统镜像 $ mmm packages/apps/GoogleInput/ $ make snod
网友评论