AOSP中编译完Apk,push到手机的脚本
程序员文章站
2024-01-13 17:48:52
...
#!/usr/bin/env bash
if [[ -z ${TARGET_PRODUCT} ]]; then
echo "没有lunch"
exit 1;
fi
LOCAL_PACKAGE_NAME=$1
APP_PACKAGE_NAME=$2
MAIN_ACTIVITY=$3
if [[ -z ${LOCAL_PACKAGE_NAME} || -z ${APP_PACKAGE_NAME} || -z ${MAIN_ACTIVITY} ]]; then
echo "缺少参数:push_notes.sh {LOCAL_PACKAGE_NAME} {APP_PACKAGE_NAME}"
echo "LOCAL_PACKAGE_NAME ,通常定义在 Android.mk 中."
echo "APP_PACKAGE_NAME ,指的是APP的包名."
echo "MAIN_ACTIVITY ,指的是启动Activity"
echo "用法举例:bash push NotesSmartisan com.smartisanos.notes com.smartisanos.notes.NotesActivity"
exit 1;
fi
currentPath=$(pwd);
#echo "当前目录:"${currentPath}
files=$(ls)
#echo ${files}
# 判断两个字符串是不是包含关系
function contains() {
if [[ $1 == *$2* ]]
then
echo 1
else
echo 0
fi
}
#echo $(contains "${files}" "out")
while [[ $(contains "${files}" "out") -eq 0 ]]
do
currentPath=$(cd ${currentPath} && cd .. && pwd);
# echo ${currentPath}
files=$(ls ${currentPath})
done
apk=${currentPath}"/out/target/product/"${TARGET_PRODUCT}"/system/app/"${LOCAL_PACKAGE_NAME}
push_result=$(adb push ${apk} "/system/app/"${LOCAL_PACKAGE_NAME})
readOnly="Read-only file system"
disableVerity="Remount FAILED. Verity is not disabled!"
userBuild="adbd cannot run as root in production builds"
unauthorized="failed to get feature set: device unauthorized."
if [[ ${push_result} == *${unauthorized}* ]]; then
echo "请先在手机上同意 USB 调试授权。"
exit 1
fi
if [[ ${push_result} == *${readOnly}* ]]
then
adb_root_remount=$(adb root && adb remount)
echo "adb root && adb remount: "${adb_root_remount}
if [[ ${adb_root_remount} == *${userBuild}* ]]; then
echo "手机是User版本,无法Push。"
exit 1
fi
if [[ ${adb_root_remount} == *${disableVerity}* ]]
then
adb_disable_verity=$(adb disable-verity)
echo "adb disable-verity: "${adb_disable_verity}
adb_root_remount=$(adb root && adb remount)
push_result=$(adb push ${apk} "/system/app/"${LOCAL_PACKAGE_NAME})
echo ${push_result}
else
echo "出现异常,Push失败"
exit 1
fi
else
echo ${push_result}
fi
#adb shell dumpsys window windows | grep Current
force_stop=$(adb shell am force-stop ${APP_PACKAGE_NAME} && adb shell am start -n ${APP_PACKAGE_NAME}/${MAIN_ACTIVITY})
echo "Push成功:" ${force_stop}
转载于:https://www.jianshu.com/p/c0d24222a409