Android Targeting R+ requires the resources.arsc of installed APKs to be stored uncompressed and al

一、问题描述:

最近Apk适配了Android 11版本,在使用完乐固线上加固后,通过adb命令安装测试,安装失败,报出如下错误:

Failure [-124: Failed parse during installPackageLI: Targeting R+ (version 30 and above) requires the resources.arsc of installed APKs to be stored uncompressed and aligned on a 4-byte boundary]

看下官方的说明如下:

Apps that target Android 11 (API level 30) or higher can’t be installed if they contain a compressed resources.arsc file or if this file is not aligned on a 4-byte boundary. This file cannot by memory-mapped by the system if either of these conditions is present. Resources tables that cannot be memory-mapped must be read into a buffer in RAM resulting in unnecessary memory pressure on the system and greatly increased device RAM usage.

翻译一下:

如果以 Android 11(API 级别 30)或更高版本为目标平台的应用包含压缩的 resources.arsc 文件或者如果此文件未按 4 字节边界对齐,应用将无法安装。如果存在其中任意一种情况,系统将无法对此文件进行内存映射。无法进行内存映射的资源表必须读入 RAM 中的缓冲区,从而给系统造成不必要的内存压力,并大大增加设备的 RAM 使用量。
 

二、解决方案

1.降级target版本到30以下

2.使用Windows上的软件加固,测试没问题

3.先使用Sdk\build-tools下的zipalign工具做对齐操作,再使用apksigner重签名

这里详细说一下第三种解决方案:

a.取出加固后的apk包(input.apk),使用Sdk\build-tools下的zipalign工具做对齐操作进行

先进入Sdk\build-tools\30.0.3目录下,如: cd C:\Sdk\build-tools\30.0.3

//对齐操作命令,4代表对齐为4个字节

 zipalign -p -f -v 4 input.apk output_unsigned.apk

//确认对齐结果命令,按需使用

 zipalign -c -v 4 output_unsigned.apk

//操作或验证成功后会看到 Verification succesful

b.使用apksigner对上面的apk进行重签名

//签名命令,需输入密码,无提示成功

//kotlinDemoKey.jks,output_unsigned.apk为待签名apk

//最后生成的签名apk会直接替换原来的这个apk

apksigner sign --ks kotlinDemoKey.jks output_unsigned.apk

/ /验证签名结果命令,,按需使用,操作结果如下

apksigner verify -v --print-certs output_unsigned.apk

 c.安装新生成的apk

adb install -r output_unsigned.apk

三、参考学习

解决过程中主要学习了一下 apksigner 和 zipalign的使用,链接如下

apksigner官方使用文档

zipalign官方使用文档

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值