前段时间做了一个Android 的升级包,总结一下制作升级包的过程。
先说明下升级包的作用吧,第一,当然是可以将新的功能添加到原来的版本上; 还有就是一种算是可选配置,例如 Google 的GMS(Google Mobile Service)包,因为并不是所有的版本都带有GMS服务,所以把GMS做成升级包提供给需要的客户。
升级的时候,把升级包放到sd卡上,按住特殊的键开机进入recovery 模式,选择从SD卡升级,选择升级包就可以了。
先来看一下一个完整的升级包的目录结构:
主要有两部分,一部分是update-binary和updater-script , 另一部分是用于更新的文件。(CERT.RSA ,CERT.SF和 MANIFEST.MF是签名是产生的文件,不用管它)
下面来制作升级包:
1. 准备好升级的文件,如上图所示,建一个system 目录和一个META-INF/com/google/android/目录,然后按照更新后所在的位置建立目录结构。
2. 准备update-binary 文件,这个文件是从 bootable/recovery/updater/编译出的,编译成out/target/product/xxxxxx/system/bin/updater 文件,把此文件拷贝过来命名成update-binary. 文件名“update-binary” 是在bootable/recovery/install.c中定义的,recovery 会执行这个文件完成升级。
3.准备updater-script 文件,这是个文本文件,文件里写的是升级的命令, update-binary 执行时会解析这个文件,执行升级的命令。文件名"updater-script" 是在 bootable/recovery/updater/updater.c 中定义的。命令的格式在bootable/recovery/updater/install.c中有定义。
一般的升级三个命令就够了:(1) mount system to /system. (2) extract system in zipfile to /system. (3) unmount system. (mount 命令会根据文件系统格式的不同有所不同)。
4.打包 :zip -r update.zip system META-INF .
5.签名:java –jar signapk.jar -w testkey.x509.pem testkey.pk8 update.zip update_signed.zip
signapk.jar 在out/host/linux-x86/framework/ 目录下
testkey.x509.pem testkey.pk8 在 build/target/product/security/ 目录下
6.你可能会遇到下面的错误:
Function Name: mount
Function Syntax: mount(fs_type, partition_type, location, mount_point)
Parameter Details:
fs_type = "yaffs2" | "ext4"
partition_type="MTD" | "EMMC"
location = partition | device
mount_point = target folder to mount FS.
Action: Mounts a filesystem to the defined mount point
Returns: The mount point if successful, null if failed
Function Name: is_mounted
Function Syntax: is_mounted(mount_point)
Parameter Details: mount_point = string, mount point to check if is mounted
Action: Checks if a filesystem is mounted.
Returns: The mount point if mounted, otherwise, returns null
Function Name: unmount
Function Syntax: unmount(mount_point)
Parameter Details: mount_point = string, mount point to unmount
Action: Unmounts the filesystem
Returns: The mount point that was dismounted if successful, otherwise it returns null