Adb commands commonly used in Android development

Adb commands are still important in Android development, and mastering some adb commands will provide great convenience for our development. If you encounter it during development, please record it here,,,,, I hope it will help you, and it is also convenient for you to forget to copy directly in the future, hehe! Come on, show...

Scenario 1: Screenshot

Product: You take a few pictures of xxx function, I want to show the result to lead.
You: Little case, wait a moment, mmp, where's the screenshot function of the phone? I usually use apple, how do I take screenshots of this Android? wc,,, finally found it after a long time. . .
You: How do you send it to the product? Next WeChat, and then send it to yourself on the PC side via WeChat. The final email is sent to the product.
Product: emmm, you are really slow to cut a picture. . . .
The 5-year boss opposite the seat: Learn to learn adb, thief chicken nuggets. . .
You: Make up quickly. . .

// 截图,保存图片到sdcard
adb shell /system/bin/screencap -p /sdcard/screenshot.png
// 吧图片从sdcard copy到电脑d盘
adb pull /sdcard/screenshot.png d:/screenshot.png(保存到电脑)
Scenario 2: View the information of the four major components

Your boss: Give you a task. The uri of content://test/a/b is an app of the system. I want to know the package name (applicationid) of this app. You can investigate it.
You: Okay, emmm
you: mmp , I really have no idea. . . .
Diagonally opposite Framwork boss: This is simple, adb can handle it directly.
You: Hurry up and ask for advice. . .

查看四大组件信息:adb shell dumpsys activity [a,b,s,prov]
activity 代表AMS相关信息
a代表产看activity
b代表产看广播
s代表查看service
prov代表查看contentProvider

例如:查看activity信息
adb shell dumpsys activity a

Extension: You can find the package name and go to the corresponding package name folder to get the db file. When you use this uri to add and delete data across processes through the contentProvider, you can view the db file to verify your own operations.
View db file strongly recommended: AndroidStudio3.0+ save and view SQLite database file

3. Installation and uninstallation of apk

(1) Installation

adb install [-r -t -d -g]包名(即applicationid)

-r代表替换存在的apk
-t允许测试安装
-d允许降级安装(比如手机上有个2.0.0的你准备安装1.0.0的)

(2) Uninstall

adb uninstall 包名
4. Watch the system log

Sometimes we need to analyze the system log. At this time, we need the adb logcat command, which can print the system log. Save it locally.

//1:打印默认日志数据
adb logcat 

//2:打印日志详细数据(time 打印日志时附加打印当前时间,v也是默认打印日志级别)
adb logcat -v time

//3:打印级别为Error的信息
adb logcat *:E\

//4:将日志保存到电脑固定的位置,比如F:\log.txt
adb logcat -v time >F:\log.txt

//5、清除log.txt文件日志(一般打印之前清除下,方便观看。减少无关日志影响)
 adb logcat -c

The log levels are as follows:
v:Verbose (the lowest level, the most output log)
d:Debug
i: Info
w:Warning
e:Error
f: Fatal
s:Silent (the highest level, nothing is output)

5. Enter the mobile terminal

Since the bottom layer of Android is based on the linux kernel, we can also access the phone's system files and other operations like using linux commands.

(1) View mobile phone system files

adb root  获得root 权限,否则有些文件没权限
adb shell 进入shell
ls   产看所有根目录下的文件

Insert picture description here

Note:
1. The sign after root is # and the sign without root is $, see the figure above.
2. After entering the shell, use linux drive letter/don’t use windows\

(2) Replace system pre-installed apps

Some Android engineers who do development in mobile phone manufacturers may often do this. The system app version is upgraded, so replace the old system with a new version. At this time, the operations can be as follows.

adb root // 获取root权限

adb remount // 重新挂载

adb shell mount -o rw,remount /   //授权所有文件可读可写

adb push E:\\a\test.apk system/app/MyTest  //e盘文件推到系统指定目录

adb reboot  // 使生效,重启adb
6, directly open the specified activity page
 adb shell am start -n applicationID/pkgname.actyvity  (栗子如下)
 adb shell am start -n com.calculator.pro/com.easy.diary.pro.activity.EditNoteActivity)
7. Quickly transfer files between mobile phone and computer

(1) adb pull copies files from mobile phones to computers. The chestnuts are as follows.

// 吧图片从sdcard copy到电脑d盘
adb pull /sdcard/screenshot.png d:/screenshot.png(保存到电脑)

(2) adb push copy chestnut from the computer network mobile phone as follows

adb push E:\\a\test.apk system/app/MyTest  //e盘文件推到手机系统指定目录
8. View the top activity on the current phone screen
adb shell "dumpsys windowlgrep mCurrentEocus"
9. Check the apk installation path
adb shell pm path applicationld
summary

Let's summarize the common ones. Under normal circumstances, these can be competent for basic tasks. In the future, specific scenes will be added in addition.

reference

ADB operation command detailed explanation and usage encyclopedia can be used as a dictionary

Guess you like

Origin blog.csdn.net/qq_38350635/article/details/107773515