Android 5.1编译大于2G的OTA包是会出 AndroidOverflowError: size does not fit in an int或者would require ZIP64extensions,这样的错误
网上的解决方法只能解决第二种错误
当system分区预制过多apk时如果img size超过2G 在make otapackage时会报如下错误
zipfile.LargeZipFile: Zipfile size wouldrequire ZIP64 extensions
或
in writestr zinfo.CRC = crc32(bytes) &0xffffffff # CRC-32 checksum OverflowError: size does not fit in an int
//http://blog.csdn.net/sergeycao
这是由于python 2.7 脚本限制
参考/prebuilts/python/linux-x86/2.7.5/lib/python2.7/
ZIP64_LIMIT = (1 << 31) - 1 (31bits相当于2G)
python 3.0+ 已提供solution, 但目前Android 编译环境使用2.x 语法与 3.0不兼容
对此google提供一个workaround solution
参考以下网址有提供详细patch内容
https://android-review.googlesource.com/#/c/142984
(但此方法占时提高write size 到32bits相当于4G, 如果超过4G仍会出现问题)
另外还需修改一下脚本 build/tool/releasetools/
1、sign_target_files_apks
2、replace_img_from_target_files.py
3、ota_from_target_files
4、img_from_target_files.py
5 、img_from_target_files
6、common.py
7、add_img_to_target_files
针对所有zipfile.ZipFile 添加最后allowZip64=True 参数值
ex:
原始文件:
output_zip =zipfile.ZipFile(filename, "a", compression=zipfile.ZIP_DEFLATED)
修改为:
output_zip =zipfile.ZipFile(filename, "a", compression=zipfile.ZIP_DEFLATED,allowZip64=True)
跟踪源代码发现,
./build/tools/releasetools/add_img_to_target_files
def AddSystem(output_zip,prefix="IMAGES/", recovery_img=None, boot_img=None):
"""Turn the contents of SYSTEM into a system image andstore it in
output_zip."""
prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix,"system.img")
ifos.path.exists(prebuilt_path):
print "system.img already exists in %s, no need to rebuild..."% (prefix,)
return
defoutput_sink(fn, data):
ofile = open(os.path.join(OPTIONS.input_tmp,"SYSTEM",fn),"w")
ofile.write(data)
ofile.close()
ifOPTIONS.rebuild_recovery:
print("Building new recovery patch")
common.MakeRecoveryPatch(OPTIONS.input_tmp, output_sink, recovery_img,boot_img,
info_dict=OPTIONS.info_dict)
block_list = common.MakeTempFile(prefix="system-blocklist-",suffix=".map")
imgname = BuildSystem(OPTIONS.input_tmp, OPTIONS.info_dict,
block_list=block_list)
print"======================================================================================imgname:",imgname
# with open(imgname,"rb") as f:
# common.ZipWriteStr(output_zip, prefix + "system.img",f.read())
# withopen(block_list, "rb") as f:
# common.ZipWriteStr(output_zip, prefix + "system.map",f.read())
print"system", prefix +"system.img"
with open(imgname,"rb") as f:
output_zip.write(imgname, prefix + "system.img")
with open(block_list,"rb") as f:
output_zip.write(block_list, prefix + "system.map")
ZipWriteStr不能支持大于2G的文件, Write就没这种限制
./build/releasetools/common.py
def_WriteUpdate(self, script, output_zip):
partition = self.partition
# withopen(self.path + ".transfer.list", "rb") as f:
# ZipWriteStr(output_zip, partition + ".transfer.list",f.read())
# withopen(self.path + ".new.dat", "rb") as f:
# ZipWriteStr(output_zip, partition + ".new.dat", f.read())
# withopen(self.path + ".patch.dat", "rb") as f:
# ZipWriteStr(output_zip, partition + ".patch.dat", f.read(),
# compression=zipfile.ZIP_STORED)
with open(self.path+ ".transfer.list", "rb") as f:
output_zip.write(self.path +".transfer.list", partition + ".transfer.list")
with open(self.path+ ".new.dat", "rb") as f:
output_zip.write(self.path + ".new.dat", partition +".new.dat")
with open(self.path+ ".patch.dat", "rb") as f:
output_zip.write(self.path +".patch.dat", partition + ".patch.dat",
zipfile.ZIP_STORED)
call = (('block_image_update("%s", '
'package_extract_file("%s.transfer.list"), '
'"%s.new.dat", "%s.patch.dat");\n') %
(self.device, partition, partition, partition))
script.AppendExtra(script._WordWrap(call))