python脚本运行aapt解析apk文件获取信息
将解析文件夹的下所有APK文件并保存各APP的版本至文件内,
使用:bash jiexi.sh "apkA,apkB,apkB,apkD,"
#!/bin/bash usage() { echo "Please input app name" exit 1 } if [[ -z "$1" ]]; then usage fi echo "---------------start read apk version execution----------------------" CODE_ROOT_PATH=`pwd` cd ../../ PROJECT_ROOT_PATH=`pwd` echo "CODE_ROOT_PATH= $CODE_ROOT_PATH" #AAPT_TOOL_PATH=/usr/local/bin/aapt //如果未设置AAPT的环境变量,则需要指定aapt文件的路径,可能SDK的版本高低差异问题,AAPT工具使用不了,可使用AAPT2 APK_FILE_PATH=$PROJECT_ROOT_PATH/apps/ apks=(${1//,/ }) function read_apk_version() { echo "####App versioncode ##############" > $CODE_ROOT_PATH/version.mk echo "" >> $CODE_ROOT_PATH/version.mk for apk in ${apks[@]} do echo "apk file name = ${apk}" result=$(aapt2 dump badging ${APK_FILE_PATH}/${apk}/${apk}.apk |grep 'version'|awk -F"'" '{ print $4}') if [ ${apk} == "apkA" ];then echo "PRODUCT_PROPERTY_OVERRIDES += aaa=$result" >> $CODE_ROOT_PATH/version.mk elif [ ${apk} == "apkB" ];then echo "PRODUCT_PROPERTY_OVERRIDES += bbb=$result" >> $CODE_ROOT_PATH/version.mk elif [ ${apk} == "apkC" ];then echo "PRODUCT_PROPERTY_OVERRIDES += ccc=$result" >> $CODE_ROOT_PATH/version.mk elif [ ${apk} == "apkD" ];then echo "PRODUCT_PROPERTY_OVERRIDES += ddd=$result" >> $CODE_ROOT_PATH/version.mk fi done cd $CODE_ROOT_PATH } read_apk_version
版权声明:如无特殊标注,文章均为本站原创,转载时请以链接形式注明文章出处。
评论