创建 adb_backup.sh 并放到适当的位置
#!/bin/bash
echo 开始备份打开的应用 $1
adb shell dumpsys window | grep mCurrentFocus > current_apkinfo.txt
while read -r line
do
if [[ $line =~ Window ]];
then
class_name=${line##*/};
class_name=${class_name%\}}
package_name=${line##*u0 };
package_name=${package_name%/*}
fi
done < current_apkinfo.txt
rm -f current_apkinfo.txt
echo 包名: $package_name
echo 类名: $class_name
adb shell screencap -p /sdcard/screenshot.png
adb pull /sdcard/screenshot.png
adb shell rm /sdcard/screenshot.png
screenshot_png_name=$1_$class_name\_`date +%Y%m%d%H%M%S`.png
mv screenshot.png $screenshot_png_name
echo -e "\033[2A"
echo -e "\033[K"
echo -e "\033[2A"
echo 当前页面已截图:$screenshot_png_name
apk_path=`adb shell pm path $package_name`
apk_path=${apk_path##*:}
adb pull $apk_path
apkname=$1_$package_name.apk
mv base.apk $apkname
echo -e "\033[2A"
echo -e "\033[K"
echo -e "\033[2A"
echo 备份完成: $apkname
open ./$apkname -R
添加命令别名 alias
alias adb_backup='~/adb_backup.sh'
输入 adb_backup 应用名
会执行这个 shell 脚本
备份apk名:应用名_包名.apk
查看所有命令别名
alias
删除命令别名
unalias adb_backup
网友评论