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的意思。

你可能感兴趣的:(Android 更改源码后的编译工作)