对新版本出现打包签名的一系列总结:打包 对齐 签名。
问题一、Androidstudio打包apk使用加固工具进行加固,报错“apk没有签名”
分析:as新版本没有v1 v2勾选项,当minSdkVersion>21时就出出现这个问题。
解决:修改minSdkVersion小于21 或 手动重新签名
问题二、加固后手动重新签名报错,信息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]
分析:当apk在Android系统版本11+以上安装是会出现该问题,
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
解决:
1.targetSdk版本小于30
2.手动4k对齐,相关命令:
检查是否4k对齐
./zipalign -c -v 4 my.apk
4k 对齐
./zipalign -f -v 4 my.apk my_4k.apk
问题三、targetsdk30+以上安装apk失败、解析包安装失败提示Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Scanning Failed.: No signature found in package of version 2 or newer for package <package_name>]
分析:Android11+以上需要v2签名的apk才能安装
解决:
1.修改targetsdk30+
2.使用adb命令进行v2签名(window环境):
v2签名
.\apksigner.bat sign --ks 《signer.jks》 --ks-key-alias 《别名》 --ks-pass pass:《签名jks密码》 --key-pass pass:《别名密码》 --out 《输出apk路径》《需要v2签名apk路径》
v2签名验证
.\apksigner.bat verify -v 需要v2签名apk路径》
注:zipalign apksigner需要在sdk/build-tool 版本目录下使用(window环境)