定制Android系统(编译Xposed和刷机)
The following article is from 小白技术社 Author 吾爱小白
编译完aosp源码,就开始编译xposed了
编译环境
安卓设备 sailfish 编译环境 MacOS(10.15绝对是坑)推荐kali(最终是在kali上搞定)
安装工具
更新&&配置 安装git
apt install git -y
git config --global user.email "your mail"
git config --global user.name "your name"
apt install -y gcc make libstdc++.i686 libstdc++-devel.i686 zlib-devel openssl-devel perl cpio expat-devel gettext-devel autoconf glibc.i686 glibc-devel.i686 zlib-devel.i686 libstdc++.i686 libX11-devel.i686 ncurses-devel.i686 ncurses-libs.i686 gperf flex gcc-c++ bison patch
apt install -y java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 java-1.8.0-openjdk-headless.x86_64
apt install perl -y
apt -q perl-CPAN
安装repo工具
mkdir ~/bin
PATH=~/bin:$PATH
curl -sSL 'https://gerrit-googlesource.proxy.ustclug.org/git-repo/+/master/repo?format=TEXT' |base64 -d > ~/bin/repo
chmod +x ~/bin/repo
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
装个看CPU、内存、缓存的htop
yum install htop -y
同步源码
我们有两种方式同步源码,清华和谷歌,这次试用的是腾讯云,就用清华了。
创建存放源码的文件夹
mkdir n/
cd /root/n/
初始化仓库 从清华的服务器同步
repo init -u https://android.googlesource.com/platform/manifest
也可以指定特定的版本同步源码,记得输入y
选择源码版本 https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds
以Pixel为例, 对应的Android 7源码tag是android-7.1.2_r33, build id是NZH54D.
PS: 这里版本不要选错,不然后面没办法成功刷机.
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-7.1.2_r33 --depth=1
同步源码树 下面三行命令其中一行就行。
repo sync
repo sync -j8 #8个线程同步代码
nohup repo sync -j8 >>sync.log 2>&1 & #推荐:后台去同步,ssh断开也没事。
可以看到htop下,多个cpu已经跑起来了。
同步xposed源码
XposedTools
cd ~
git clone https://github.com/rovo89/XposedTools.git
修改配置文件
cp build.conf.sample build.conf
vim build.conf
如下配置
[General]
outdir = /Users/zxc/Android/n/out #输出目录,out一定要存在
javadir = /Users/zxc/Android/n/XposedBridge #XposedBridge的 位置
[Build]
# Please keep the base version number and add your custom suffix
version = 89 (custom build by xyz / %s)#我们这里是89版本
makeflags = -j8 #8个线程同步
[GPG]
sign = release
user = 852109AA!
# Root directories of the AOSP source tree per SDK version
[AospDir]
#19 = /android/aosp/440
#21 = /android/aosp/500
25 = /Users/zxc/Android/n #安卓7.1源码位置,上边两个注释
# SDKs to be used for compiling BusyBox
# Needs https://github.com/rovo89/android_external_busybox
[BusyBox]#下面的都改成25,看资料说不改也行
arm = 25
x86 = 25
armv5 = 25
xposed xposed为整个Xposed框架的native部分,主要内容为xposed修改的app_process源码和相关库文件.这里需要提一下,这部分源码有两种同步方式.第一采用修改local_manifests,然后repo sync的方式.第二种则为手动下载合并.本文采用第二种方式.
cd /Users/zxc/Android/n
cd frameworks/base/cmds/
git clone https://github.com/rovo89/Xposed.git xposed
android_art Xposed为了支持新的runtime,修改了art的源码.我们需要把原来的art源码替换成Xposed提供的代码.
cd /root/n
rm -rf art
git clone https://github.com/rovo89/android_art.git -b xposed-nougat-mr2 art
XposedBridge XposedBridge的代码直接clone即可,没有版本的限制.需要注意与javadir对应.
cd /root/n
git clone https://github.com/rovo89/XposedBridge.git
安装
下载地址 (自己提取的,没测试) https://dl.google.com/android/repository/platform-25_r03.zip https://dl.google.com/android/repository/sources-25_r01.zip 之前在as里面已经装了,就不在装了。我们需要改 XposedBridge/app/build.gradle
为下面的(这里是安卓7.1就是sdk25)。在XposedBridge/local.properties添加
sdk.dir=/Users/zxc/Android/sdk#自己的sdk目录
编译
初始化编译环境
source build/envsetup.sh
lunch 18
编译XposedBridge
cd /root/XposedTools
./build.pl -a java
编译完成
BUILD SUCCESSFUL
Total time: 1.478 secs
Copying APK to XposedBridge.jar...
Skipping non-existent /Users/zxc/Android/n/XposedBridge/app/build/outputs/apk/app-release.apk
Skipping non-existent /Users/zxc/Android/n/XposedBridge/app/build/outputs/apk/app-release-unaligned.apk
/Users/zxc/Android/n/XposedBridge/app/build/outputs/apk/app-release-unsigned.apk => /Users/zxc/Android/n/out/java/XposedBridge.jar
Done!
编译native层代码
./build.pl -t arm64:25 #25是sdk版本 对应安卓7.1
错误
kali
flex-2.5.39: fatal internal error, exec of /usr/bin/m4 failed
sudo apt-get install libxml2-utils
刷机
这里不能直接刷进去 感谢肉丝大佬的指点 修改XposedInstaller的源码 这里的url都换成你自己的
public Builder setUrl(String url) {
mUrl = url;
System.out.println("xposed=" + url);
if (url.contains("uninstaller")) {
mUrl = "http://192.168.2.185:8000/xposed-uninstaller-20180117-arm64.zip";
} else {
mUrl = "http://192.168.2.185:8000/xposed-v89-sdk25-arm64-custom-build-by-xyz-20200726.zip";
}
return this;
}
刷入错误 这里下载一下官方的卸载zip,替换下 先刷入卸载包,再刷入安装包即可
mac
mac10.15 劝退
python3会出现 print错误 修改build/tools/findleaves.py里面的print r为print(r) 即可
大小写敏感问题 mac 分区是默认不是大小敏感,所以需要重新分区。参考这里 https://blog.bihe0832.com/mac-disk-utility.html
Checking build tools versions...
build/core/main.mk:159: ************************************************************
build/core/main.mk:160: You are building on a case-insensitive filesystem.
build/core/main.mk:161: Please move your source tree to a case-sensitive filesystem.
build/core/main.mk:162: ************************************************************
build/core/main.mk:163: *** Case-insensitive filesystems not supported.
Can not find SDK 10.8 at /Developer/SDKs/MacOSX10.8.sdk 解决办法就是将mac_sdk_versions_supported改为系统中所装版本或者自己下载一个放在sdk目录
export MAC_SDK_VERSION="10.11"
https://github.com/phracker/MacOSX-SDKs/releases/download/10.11/MacOSX10.8.sdk.tar.xz
#mac_sdk_versions_supported := 10.6 10.7 10.8 10.9
mac_sdk_versions_supported := 10.11
Bad CPU type in executable
brew install wsk
external/libcxx/include/cstdlib:167:44: error: declaration conflicts with target of using declaration already in scope
https://stackoverflow.com/questions/47060910/error-declaration-conflicts-with-target-of-using-declaration-already-in-scop