曾经参考了网上很多制作差分包的流程,结果一直起不来, 最后经过各种摸索和测试,终于在android M 上制作出了可以正常工作Android M 差分包。 希望献给正在迷茫于此的你。

Android 差分包(update.zip) 主要用于Android OS 的OTA update。 Android 的OTA 更新主要包含两种更新:
1) FULL OTA
2) Diff OTA 更新。
FULL OTA 是整个包的更新, 而diff OTA 是基于上一版update.zip 的差异的更新(即差分包update.zip里面主要包含一些patch)。所以在进行OTA 差分包更新的时候, 一定要先进行一次FULL OTA 更新, 更新的update.zip 就是你制作差分包的Base 版本。

我们下面来描述制作Android M 差分包的详细流程:

1. 制作Base 版本的update.zip

$ source build/envsetup.sh$ lunch xxx$ make otapackage

等编译完成后, 你需要保存两个文件:
1) 用于第一次FULL OTA 更新的Base 版本的update.zip
该文件的路径为:out/target/product/$(product_name)/update.zip
2) 用于制作差分包的base 版本的update.zip
该文件的路径为: out/target/product/$(product_name)/obj/PACKAGING/target_files_intermediates/$(product_name)-target_files-eng.root.zip
它是在用命令make otapackage之后的中间生产物,是最原始的升级包。 里面包含了制作差分包所需要的文件。
注意:制作差分包不能用out/target/product/$(product_name)/update.zip。 否则根本不会制作出对应的差分包。
我们先将out/target/product/$(product_name)/obj/PACKAGING/target_files_intermediates/$(product_name)-target_files-eng.root.zip命名为Base.zip.

 $ mv  $(product_name)-target_files-eng.root.zip   Base.zip

2. 修改Android OS 源码部分;

为了测试, 我们就只给一个app 中加入log.d(“####”) 用于debug.

3. 制作新版本update.zip

   $  source build/envsetup.sh   $ lunch xxx   $ make otapackage   

和1 不同的是, 只需要保存一个文件:
即out/target/product/$(product_name)/obj/PACKAGING/target_files_intermediates/$(product_name)-target_files-eng.root.zip. 我们将其命名为new.zip.

  $ mv  $(product_name)-target_files-eng.root.zip   New.zip   

4. 修改 build/tools/releasetools/ota_from_target_files.py 脚本

system_items.GetMetadata(target_zip)system_items.Get("system").SetPermissions(temp_script)

改为:

system_items.GetMetadata(target_zip)#system_items.Get("system").SetPermissions(temp_script)system_items.Get("system").SetPermissions_NonSelinux(temp_script) 

否则,在更新的时候会出现错误。

5. 使用修改后的脚本制作差分包:

$ ota_from_target_files.py  -i     Base.zip  New.zip  update.zip

等完成后, 我们的差分包就制作成功了。

6. 使用1产生的update.zip 进行FULL OTA 更新

update.zip即1中产生的out/target/product/$(product_name)/update.zip。

7. 使用5 产生的update.zip 进行增量更新即可。

至此,Android M 的差分包更新就完成了。 下面我们描述下一些可能出现的错误信息:


a).

file "/system/etc/recovery-resource.dat" doesn't have any of expected sha1 sums; checking cachefailed to stat "/cache/saved.file": No such file or directoryfailed to load cache filescript aborted: "/system/etc/recovery-resource.dat" has unexpected contents.

这个错误是apply_patch_check()打印的, 该函数检查是否符合升级条件,判断sha值,确认是A状态或者C状态。
通常打印这个消息就是不具备更新的条件, 例如: 你没有预先进行 FULL OTA更新, 就直接进行 DIFF OTA 更新, 就会打印该错误。

b).

script aborted: set_metadata_recursive: some changes failedSymlinks and permissions...ApplyParsedPerms: lsetfilecon of /system/lost+found to u:object_r:system_file:s0 failed: Operation not supported on transport endpointset_metadata_recursive: some changes failedE:Error in /cache/update.zip(Status 7) 

这个我按照4 修改后, 问题就得到了解决。
Qing 2017/08/31

注意:
如果有人没有selinux 的定义,可以参考这个脚本,附件如下:
https://github.com/jwzl/ota_from_target_files.git

更多相关文章

  1. android 各版本区别
  2. Android ant自动打包脚本:自动替换友盟渠道、版本号、包名
  3. Android 版本兼容适配
  4. android sdk 各个版本的区别
  5. Android M及以上版本系统 悬浮窗权限 的解决方案
  6. Android(2)—Mono For Android App版本自动更新

随机推荐

  1. android app 设计总结
  2. wifi和GPRS下获取android的IP信息
  3. 安卓布局
  4. [Android各版本特性]Android(安卓)7.0 No
  5. 刚刚接触Android,写第一个Hello world 小
  6. Android自学笔记(番外篇):全面搭建Linux环境
  7. android布局属性预览
  8. android 环境的搭建
  9. Android实现文件夹目录选择器
  10. Android(安卓)showDialog时报错requestFe