背景
工作中经常使用到adb,简单分享下常用的。
获取应用apk
adb shell pm path 包名
得到apk的路径
adb pull xxx就能拿到apk了
然后pull到电脑就ok
sh脚本
#Copyright [2021] [Quibbler.cn]
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
if [[ ! -n "$1" ]]; then
#current focused App, output: mCurrentFocus=Window{c053bb9 u0 com.ss.android.ugc.aweme/com.ss.android.ugc.aweme.splash.SplashActivity}
focus=`adb shell dumpsys window | findStr mCurrentFocus`
#extract out {package/class}, output: com.ss.android.ugc.aweme/com.ss.android.ugc.aweme.splash.SplashActivity
classpath=`echo ${focus#*{} | awk '{print $3}'`
#crop string extract package name, output: com.ss.android.ugc.aweme
package=`echo ${classpath%/*}`
else
#use input args as package name
package=$1
echo "pull $1 package "
fi
#figure out this package install path, output: package:/data/app/com.ss.android.ugc.aweme-bWD-6eHGY_JWxoiHreHc5A==/base.apk
path=`adb shell pm path $package`
#sub path from pm output's, output: data/app/com.ss.android.ugc.aweme-bWD-6eHGY_JWxoiHreHc5A==/base.apk
path=`echo ${path#*/}`
#and replace '/' with '//' if path include '/base.apk',E.g: data/app/com.vivo.easyshare-Q46ic5yVLxvgkiPRkB318Q==//base.apk
if [[ $path =~ /base.apk ]]; then
path=`echo ${path///base.apk///base.apk}`
fi
#pull apk out renanme with package name
adb pull $path $package.apk
其他常用命令
// 卸载系统app(屏蔽)
adb shell pm uninstall -k --user 0 pkg
安装/强制安装
adb install [package_path]
adb install -r -d [package_path
卸载
adb uninstall [package]
清理
adb shell pm clear [package]
连接
adb connect [ip]
断开
adb disconnect [ip]
启动
adb shell am start [package]+[Activity path]
关闭
adb shell am force-stop [package]
//查看运行app的进程id
adb shell pidof pkg
apk信息
还有查看apk信息,包含一些target,min,权限,启动入口等等信息。
首先进入Android SDK中,进入build-tools,随便进入一个版本,比如30.0.3
到了这个位置之后
./aapt dump badging apkFile
launchable-activity: name='com.susion.rabbit.demo.MainActivity'
就是app的入口
截图
环境Mac、Linux 首先配置你的.bashrc文件 配置好你的adb环境
//截图且拉到本地
首先配置别名pp,截图保存到手机
alias pp='adb shell /system/bin/screencap -p /sdcard/android-cap.png'
别名gg,就是拉取刚刚截图的位置到当前运行命令目录
alias gg='adb pull /sdcard/android-cap.png'
把2个别名组合起来,叫get,回车,就能拿到截图了。
alias get='pp;gg'
win环境的同理,但是写的是bat
在Mac、Linux中可以配置别名,然后组合别名方式来连续做某事。只需要敲一敲就能完成一些列功能了。
我记得之前发布编译博客系统,也是用组合命令完成的。
重启adb
alias kadb='adb kill-server'
alias adbr='adb start-server'
查看当前Activity信息
alias ff='adb shell dumpsys activity | grep -i run'
等我想起来就继续更新吧
有道笔记地址:https://note.youdao.com/s/HuG1iUqo