APK打包文件到META-INF (打包证书等) 一键打包签名安装

准备工具

aapt版本:sdk\build-tools\29.0.0\aapt.exe
apksigner.jar版本: sdk\build-tools\29.0.0\lib\apksigner.jar

aapt工具使用方法

添加文件到apk

新建个META-INF文件夹把CER文件放入即可带路径打包
删除打包的文件: (如果已经存在则要先执行删除操作)
aapt r app-debug.apk META-INF\TEST.CER

添加打包的文件
注意:用反斜杠会导致无法解析成功

:: 正确的方法:(注意要用**顺斜杠**)
aapt r app-debug.apk META-INF/TEST.CER

一键打包证书

repackage.sh Linux版

***.jks : 签名文件
–ks-key-alias:签名别名
–ks-pass pass: 签名证书密码
–key-pass pass: 签名别名的密码 (例如keyname)
–out :签名后的apk输出路径
最后的参数为需要签名的apk

#!/bin/bash
if [ ! -d "build" ];then
	mkdir build
	else
	echo start copy apk and repackage ...
fi

cp  ../../PRO/app/build/outputs/apk/debug/app-debug.apk  ./build/app-debug_repacked.apk
# ./aapt r ./build/app-debug_repacked.apk META-INF/TEST.CER
./aapt a ./build/app-debug_repacked.apk META-INF/TEST.CER
java -jar apksigner.jar sign  --ks ***.jks  --ks-key-alias keyname  --ks-pass pass:***  --key-pass pass:***  --out ./build/app-debug_repacked_out.apk  ./build/app-debug_repacked.apk    
adb install ./build/app-debug_repacked_out.apk

repackage.bat windows版

:: 执行cmd的时候不打印命令
@echo off

SET BUILD_DIR=.\build

if not exist %BUILD_DIR% (
	mkdir %BUILD_DIR%
) else (
	REM  echo dir exist!
)

copy  ..\..\PRO\app\build\outputs\apk\debug\app-debug.apk  .\build\app-debug_cmd_repacked.apk
::.\aapt r .\build\app-debug_cmd_repacked.apk META-INF\TEST.CER
.\aapt a .\build\app-debug_cmd_repacked.apk META-INF/TEST.CER
java -jar apksigner.jar sign  --ks debug.jks  --ks-key-alias keyname  --ks-pass pass:******  --key-pass pass:******  --out .\build\app-debug_repacked_cmd_out.apk  .\build\app-debug_cmd_repacked.apk    
adb install .\build\app-debug_repacked_cmd_out.apk

aapt -h 帮助文档

 aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]
   Delete specified files from Zip-compatible archive.

 aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]
   Add specified files to Zip-compatible archive.

 aapt c[runch] [-v] -S resource-sources ... -C output-folder ...
   Do PNG preprocessing on one or several resource folders
   and store the results in the output folder.

 aapt s[ingleCrunch] [-v] -i input-file -o outputfile
   Do PNG preprocessing on a single file.

 aapt v[ersion]
   Print program version.
posted @ 2022-03-12 22:04  xiaomodecnblogs  阅读(276)  评论(0编辑  收藏  举报