移植xposed_art到Android5.1.0_r1系统

移植xposed到Android5.1.0_r1源码

下载Android源码编译-android-5.1.0_r1

搭建编译源码环境即可并能正确编译源码。

同步xposed源码

在下载好android-5.1.0_r1源码并编译能正常刷机后。同步xposed相关源码,这里同步的分支为lollilpop-mr1分支。

  1. 同步xposed分支 ,源码在xposed源码,这部分主要是修改了app_process的内容和相关源码库文件。根据XposedTools的文档中介绍可以通过local_manifest的方式和手动同步的方式。这里使用手动方式同步。如下
cd aosp_dir
cd cd frameworks/base/cmds/
git clone https://github.com/rovo89/Xposed.git xposed

2.同步art部分源码
同步前先备份原始art源码,然后再同步xposed_art部分源码。如下

cd aosp_dir
#mv art/  path/to/你要备份的目录,这里我选择外层即可
备份原始程序
mv art/ ../ 
同步远程到本地
git clone https://github.com/rovo89/android_art.git art
进入到同步的分支
cd art 
同步分支代码为 xposed-lollipop-mr1,如果这里是xposed-marshmallow,则选择同步这部分
git checkout xposed-lollipop-mr1
切换分支完成后,查看当前分支是否正确
git branch -vv 
如果出现了*  xposed-lollipop-mr1那么就表示当前选中的分支是对的。

3.同步XposedBridge代码
这里代码版本没限制,选择直接clone到源码目录,如下

cd aosp_dir
git clone https://github.com/rovo89/XposedBridge.git 
完成后下载的源码应该在源码目录下。
  • 下载XposedTools
    这个工具是用来编译Xposed的脚本。 如下
cd path/to/你要保存的目录
执行
git clone https://github.com/rovo89/XposedTools.git

编译模块XposedBridge

因为已经编译好了源码,这里将通过mmm [模块名]的方式来编译XposeBridge.jar.在编译前需要编写一个Android.mk文件,将这个文件放到XposedBridge源码根目录下,内容如下

LOCAL_PATH :=$(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE :=XposedBridge
LOCAL_MODULE_OWNER :=moto

LOCAL_SRC_FILES := \
        $(call all-java-files-under,app/src) \
        $(call all-java-files-under,app/src/main/apacheCommonsLang/external/org/apache/commons/lang3) \
        $(call all-java-files-under,hiddenapistubs/src)
include $(BUILD_JAVA_LIBRARY)

$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := -C "$(LOCAL_PATH)" \
 assets -C "$(LOCAL_PATH)" NOTICE.txt

include $(call all-makefiles-under,$(LOCAL_PATH))

保存在aosp_dir/XposedBridge下。
执行编译命令
cd aosp_dir
source build/envsetup.sh
lunch 
这里我的手机为nexus5,选择7 hammarhead
执行编译模块
mmm XposedBridge
不出错的话,即可看到如下输出
---------------------------log-----------------------------
cattus@ubuntu:~/android-5.1.0_r1$ mmm XposedBridge
make: Entering directory '/home/cattus/android-5.1.0_r1'
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.1
TARGET_PRODUCT=aosp_hammerhead
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=krait
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.8.0-36-generic-x86_64-with-Ubuntu-16.04-xenial
HOST_BUILD_TYPE=release
BUILD_ID=LMY47D
OUT_DIR=out
============================================
PRODUCT_COPY_FILES device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml ignored.
No private recovery resources for TARGET_DEVICE hammerhead
target Java: XposedBridge (out/target/common/obj/JAVA_LIBRARIES/XposedBridge_intermediates/classes)
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Copying: out/target/common/obj/JAVA_LIBRARIES/XposedBridge_intermediates/classes-jarjar.jar
Copying: out/target/common/obj/JAVA_LIBRARIES/XposedBridge_intermediates/emma_out/lib/classes-jarjar.jar
Copying: out/target/common/obj/JAVA_LIBRARIES/XposedBridge_intermediates/classes.jar
Copying: out/target/common/obj/JAVA_LIBRARIES/XposedBridge_intermediates/noproguard.classes.jar
target Dex: XposedBridge
Copying: out/target/common/obj/JAVA_LIBRARIES/XposedBridge_intermediates/classes.dex
target Jar: XposedBridge (out/target/common/obj/JAVA_LIBRARIES/XposedBridge_intermediates/javalib.jar)
Install: out/target/product/hammerhead/system/framework/XposedBridge.jar  生成的XposedBridge.jar的文件
make: Leaving directory '/home/cattus/android-5.1.0_r1'

编译xposed的核心代码art部分

编译art部分内容执行,如下

cd XposedTools 

修改buidl.sample.conf文件
cp buidl.sample.conf  buidl.conf

编辑buil.conf文件内容如下
[General]
##added by loopher 2018-08-24
##这里要指定编译出来的XposedBridge.jar的目录,需要注意,一定要将XposedBridge.jar放到
##outdir下的jave目录。例如我这里的是在/home/cattus/tmpxposed/XposedBridge.jar
outdir =/home/cattus/tmpxposed


[Build]
# Please keep the base version number and add your custom suffix
##生成版本的名称
version = 65 (custom build by xyz / %s)
##编译要用的线程量。例如 make -j4 
makeflags = -j4

[GPG]
sign = release
user = 852109AA!

# Root directories of the AOSP source tree per SDK version
[AospDir]
##added by loopher 2018-08-24
###需要指定源码目录
22 =/home/cattus/android-5.1.0_r1

# SDKs to be used for compiling BusyBox
# Needs https://github.com/rovo89/android_external_busybox
[BusyBox]
arm = 21
x86 = 21
armv5 = 17

保存即可
执行编译命令
./build.pl -t arm:22
完成后,即可看到在outdir下的sdk22下找到对应的文件,
将tmpxposed/sdk22/arm/files/system下的xposed.prop复制到android-5.1.0_r1/out/target/product/hammerhead/system下,
将bin下的复制到android-5.1.0_r1/out/target/product/hammerhead/system/bin下,在复制bin的时候,需要注意的是app_process32_xposed要改名为app_process32,这个是用来替换了原生的app_process32
将lib下的所有文件复制到android-5.1.0_r1/out/target/product/hammerhead/system/lib下

重新编译system.im文件

在替换了上述文件后,需要重新生成镜像文件,执行命令

cd aosp_dir
source buil/envsetup.sh
lunch
选择hammarhead
make snod 
等待编译完成后,这里就完成了所有的移植工作

刷机

将新的镜像文件刷入手机即可。

刷机成功查看日志

abd shell logcat |grep -i xposed 
日志
shell@hammerhead:/system/framework $ logcat |grep -i xposed                    
D/XposedStartupMarker(  201): Current time: 43495194, PID: 201
I/Xposed  (  201): -----------------
I/Xposed  (  201): Starting Xposed version 65 (custom build by xyz / 20180826), compiled for SDK 22
I/Xposed  (  201): Device: AOSP on HammerHead (LGE), Android version 5.1 (SDK 22)
I/Xposed  (  201): ROM: aosp_hammerhead-userdebug 5.1 LMY47D eng.cattus.20180823.183608 test-keys
I/Xposed  (  201): Build fingerprint: Android/aosp_hammerhead/hammerhead:5.1/LMY47D/cattus08231837:userdebug/test-keys
I/Xposed  (  201): Platform: armeabi-v7a, 32-bit binary, system server: yes
I/Xposed  (  201): SELinux enabled: yes, enforcing: yes
E/Xposed  (  421): Could not stat /data/data/de.robv.android.xposed.installer/: No such file or directory
I/dex2oat (  845): /system/bin/dex2oat --zip-fd=6 --zip-location=/system/framework/XposedBridge.jar --oat-fd=7 --oat-location=/data/dalvik-cache/arm/system@framework@XposedBridge.jar@classes.dex --instruction-set=arm --instruction-set-features=div --runtime-arg -Xms64m --runtime-arg -Xmx512m --swap-fd=8

build.pl错误解决

执行./build.pl -a javac出现Can’t locate Config/IniFiles.pm in,缺少依赖文件

解决:perl -MCPAN -e ‘install Config::IniFiles’在后面的提示中,需要输入y,接着在最后的时候,选择sudo的模式,让其自己安装,安装结束后,最后需要输入sudo的密码即可。

你可能感兴趣的:(Android)