04 Android系统之添加预编译模块

举报
王建峰 发表于 2021/11/19 00:06:57 2021/11/19
【摘要】 理解 在实际的系统开发过程中,有很多文件都是预先编译好的,比如第三方APK,so库, jar包, bin 文件,配置文件等。我们需要在系统编译时能把这些文件打包编译到系统镜像里面。 操作准则 我们有...

理解

在实际的系统开发过程中,有很多文件都是预先编译好的,比如第三方APK,so库, jar包, bin 文件,配置文件等。我们需要在系统编译时能把这些文件打包编译到系统镜像里面。

操作准则

我们有两种方法可以达到我们的目的: PRODUCT_COPY_FILES 和 定义 prebuilt 模块。

  • 如果这个文件只需要预置到指定目录就可以了,那我们就可以简单的将其加入 PRODUCT_COPY_FILES 变量就行, 比如一些 bin 文件, 配置文件。
  • 如果这个文件有其他模块编译依赖,或者这个文件需要系统签名,那我们就得定义一个预编译模块,比如一些 so 库,APK 文件, jar 包等。

添加预编译模块

这里先记录一下添加预编译模块到PRODUCT_COPY_FILES的过程,另外如何定义prebuilt,方法请查看原文
Android系统开发入门-5.添加预编译模块

1、 定义目录结构
为了维护方便,我们一般把 PRODUCT_COPY_FILES 的设置提取到一个单独的文件。在 $product.mk 里面 include 就行。这里在pure目录下创建一个prebuilt目录如下

hinzer@ubuntu:android-10$ tree ./device/mi/pure/prebuilt/
./device/mi/pure/prebuilt/
├── apk      # 预置 apk 模块
├── libs       # 预置库模块,so 库, jar 包等
└── vendor    # PRODUCT_COPY_FILES 类型预置,按实际输出路径组织
    └── bin
        └── busybox-i686

4 directories, 1 file

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2、下载bin文件

hinzer@ubuntu:android-10$ cd ./device/mi/pure/prebuilt/vendor/bin
hinzer@ubuntu:bin$ wget https://busybox.net/downloads/binaries/1.21.1/busybox-i686
....
hinzer@ubuntu:bin$ file busybox-i686
busybox-i686: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3、添加product_copy_files.mk

hinzer@ubuntu:pure$ vim product_copy_files.mk
hinzer@ubuntu:pure$ cat product_copy_files.mk
# product copy files

LOCAL_PREBUILD_DIR := device/mi/pure/prebuilt

PRODUCT_COPY_FILES += \
    $(LOCAL_PREBUILD_DIR)/vendor/bin/busybox-i686:vendor/bin/busybox

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

4、在 $product.mk 文件中 include

hinzer@ubuntu:pure$ echo "include device/mi/pure/product_copy_files.mk" >> product01.mk 

  
 
  • 1

编译验证

# 编译
hinzer@ubuntu:android-10$ source ./build/envsetup.sh
hinzer@ubuntu:android-10$ lunch product01-eng
hinzer@ubuntu:android-10$ make -j4

# 启动emulator虚拟机
hinzer@ubuntu:android-10$ emulator
...

# adb shell验证
hinzer@ubuntu:~$ adb devices
List of devices attached
emulator-5554	device

hinzer@ubuntu:~$ adb shell busybox          # 运行可执行文件
BusyBox v1.21.1 (2013-07-08 10:44:30 CDT) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2012.
Licensed under GPLv2. See source distribution for detailed
copyright notices.
.....


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

参考资料

文章来源: blog.csdn.net,作者:hinzer,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/feit2417/article/details/105235231

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200