Android 更改源码后的编译工作

1.引言

第一次参与到framwork开发,framwork开发按照我的理解,就是更改系统的源码,如aws,ws的代码之后,编译成一个系统包,安装到硬件板上,以达到自己想要的效果。

参考文章:https://blog.csdn.net/fuchengbo000/article/details/43193801

2.正题

系统: Ubantu 18.04
采用:服务器编译android源码的手段
工具:Sshfs工具,将远程服务器的系统代码,映射到本地文件夹。对本地文件夹的代码任务修改,将同步到远程服务器上

注意: sshfs 偶尔出现过没同步成功的状况,


case 1:

项目实战:TV端 得到应用的任务快照截图

更改的文件:
TaskSnapshotController.java 和 AppWindowToken.java 都是位于/framwork/base/services/目录下。

编译:在/framwork/base/services/目录下进行mm编译 不能再在 /framwork/base/services/core/目录下进行mm编译也行

编译成功之后,拷贝如下几个文件:

/out/target/product/<产品名称>/system/framwork/services.jar
/out/target/product/<产品名称>/system/framwork/oat/arm/services.odex
/out/target/product/<产品名称>/system/framwork/oat/arm/ services.art
/out/target/product/<产品名称>/system/framwork/oat/arm/ services.vdex

将这个几个jar,分别push到 手机/system/下面对应的目录中。如:将services.jar push到手机的/system/framwork/目录中; 将services.odex push到手机的 /system/framwork/oat/arm/

sh脚本:


case 2:

更改的代码位于/framwork/base/core/java目录下,需要在/framwork/base 执行mm.

实践中报了一个错:

[ 86% 2232/2569] //frameworks/base/libs/usb/tests/accessorytest:accessorytest link accessorytest [linux_glibc]
FAILED: out/soong/.intermediates/frameworks/base/libs/usb/tests/accessorytest/accessorytest/linux_glibc_x86_64/accessorytest 
prebuilts/clang/host/linux-x86/clang-4691093/bin/clang++  @out/soong/.intermediates/frameworks/base/libs/usb/tests/accessorytest/accessorytest/linux_glibc_x86_64/accessorytest.rsp out/soong/.intermediates/system/core/libusbhost/libusbhost/linux_glibc_x86_64_static/libusbhost.a out/soong/.intermediates/system/core/libcutils/libcutils/linux_glibc_x86_64_static/libcutils.a out/soong/.intermediates/external/tinyalsa/libtinyalsa/linux_glibc_x86_64_static/libtinyalsa.a -Wl,--start-group out/soong/.intermediates/external/compiler-rt/libcompiler_rt-extras/linux_glibc_x86_64_static/libcompiler_rt-extras.a -Wl,--end-group out/soong/.intermediates/external/libcxx/libc++/linux_glibc_x86_64_shared/libc++.so  -o out/soong/.intermediates/frameworks/base/libs/usb/tests/accessorytest/accessorytest/linux_glibc_x86_64/accessorytest -target x86_64-linux-gnu -Bprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--no-undefined-version --gcc-toolchain=prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8 --sysroot prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/sysroot -m64 -Bprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/lib/gcc/x86_64-linux/4.8 -Lprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/lib/gcc/x86_64-linux/4.8 -Lprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/lib64 -ldl -lpthread -lm -lrt -Wl,-rpath,\$ORIGIN/../lib64 -Wl,-rpath,\$ORIGIN/lib64  -pie -nodefaultlibs -lgcc_s -lgcc -lc -lgcc_s -lgcc
external/tinyalsa/pcm.c:567: error: undefined reference to 'pm_trans_data_write'
external/tinyalsa/pcm.c:600: error: undefined reference to 'pm_trans_data'
external/tinyalsa/pcm.c:873: error: undefined reference to 'pm_deinit'
external/tinyalsa/pcm.c:933: error: undefined reference to 'pm_init'
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
[ 88% 2262/2569] //external/protobuf:libprotobuf-cpp-lite g++ src/google/protobuf/extension_set.cc [windows]
In file included from external/protobuf/src/google/protobuf/extension_set.cc:43:0:
external/protobuf/src/google/protobuf/stubs/map_util.h:624:65: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
                        const typename Collection::value_type& vt) {
                                                                 ^
external/protobuf/src/google/protobuf/stubs/map_util.h:639:61: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
     const typename Collection::value_type::second_type& data) {
                                                             ^
[ 89% 2292/2569] //external/protobuf:libprotobuf-cpp-lite g++ src/google/protobuf/extension_set.cc [windows x86_64]
In file included from external/protobuf/src/google/protobuf/extension_set.cc:43:0:
external/protobuf/src/google/protobuf/stubs/map_util.h:624:65: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
                        const typename Collection::value_type& vt) {
                                                                 ^
external/protobuf/src/google/protobuf/stubs/map_util.h:639:61: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
     const typename Collection::value_type::second_type& data) {
                                                             ^
[ 89% 2305/2569] //frameworks/base/libs/hwui:hwuimacro link hwuimacro
Warning: request a ThreadPool with 1 threads, but LLVM_ENABLE_THREADS has been turned off
ninja: build stopped: subcommand failed.
09:49:22 ninja failed with: exit status 1

编译accessorytest 报错。我们只需要进入accessorytest下,将Android.bp移除,再编就通过了

framwork的更改需要推送很多的jar 到本地系统,主要有以下俩部分:

  • /out/target/product/<产品名称>/system/framwork/ 下时间发生改变的,都要push到系统相应位置(观察jar的时间是否改变)

  • /out/target/product/<产品名称>/system/framwork/arm 将arm文件夹,复制粘贴,push 到系统。

经过验证,前前后后有大概17个要push到系统的文件。为此特意写了一个脚本。

framwork.sh 脚本:


3.工程中引入 framwork.jar

参考链接:https://blog.csdn.net/qq_31939617/article/details/107183617

  • out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar改名得到 framework.jar 把framework.jar 复制到Androidstudio项目目录的libs文件夹下;鼠标点击右键,选择Add As Library ,接着选择framework.jar 所在的module,即可在module的build.gradle自动引入framework.jar

  • App-> build.gradle
    添加compileOnly files('libs/framework.jar') 依赖

    使用compileOnly 目的是 framework.jar只在编译阶段使用,打包 apk时候不打包进入,可以减小apk包的大小;

  • 在project的build.gradle中的allprojects闭包中添加
gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        //注:app\\libs\\framework.jar是framework.jar 在项目的中存放的路径
        options.compilerArgs.add('-Xbootclasspath/p:app\\libs\\framework.jar') 
    }
}


坑1:

一定得将 out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar改名字添加到libs中。

不能直接将/system/framwork/framwork.jar 直接拿出来,放进libs中。这样做死活找不到 api

坑2:

dependencies {
    //注释掉此引入
    //implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compileOnly  files('libs/framework.jar')
}

implementation fileTree(include: ['*.jar'], dir: 'libs') 和 compileOnly files('libs/framework.jar') 不能共存,否则会提示jar冲突

implementation fileTree(include: ['*.jar'], dir: 'libs') 本身就是引用了全部jar的意思。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269