Implementation method of Android executing shell script in linux terminal to directly print the log of currently running app
- 2021-11-01 04:54:39
- OfStack
1. Problems
Most of the time, we need to print the log of currently running app on ubuntu terminal. Our common practice is
1), get the package name
Open the currently running app, and then type the following command, and then you can see the package name after TASK in line 1
adb shell dumpsys activity top
2) The pidcat. py script is installed on our terminal, and then the full log of app currently running can be printed by executing the following command.
pidcat.py packageName
3) Think, why do you need this repeated operation every time? 1 When it comes to repetition, we should immediately think about whether we can solve repetitive operation with scripts
2. Solutions
Get the package name by executing the script file, and then execute the
pidcat.py packageName
Command
3. Code implementation
1) Create a new pcat file
#!/bin/bash
dev="device"
devices=$(adb devices)
if [[ ${devices} == *$dev ]]
then
echo " The mobile phone has been connected to the terminal "
info=$(adb shell dumpsys activity top | awk -F " " '/TASK/ {print $2}')
echo " Current running app The package name of is :${info}"
pidcat.py --hw ${info}
else
echo " The mobile phone is not connected to the terminal "
fi
2) Copy the pcat file to the following directory
/usr/local/bin/
4. Test results
1) Open the app of the mobile phone "Game Center"
2) Enter pcat at the terminal
3) Operation result of that terminal
*****~$ pcat
The mobile phone has been connected to the terminal
Current running app The package name of is :com.huawei.gamebox
Zygote D CtrlSocket libc.so ctrl_sockets_set_addr pfunc is not exist!
Process com.huawei.gamebox created for activity com.huawei.gamebox/.GameBoxActivity
PID: 29758 UID: GIDs:
ActivityThread D ActivityThread,attachApplication
HwCust D Create obj success use class android.content.res.HwCustHwResourcesImpl
AnalyticUtils D experience = 1
StoreApplication D create application.
HwPolicyFactory V : success to get AllImpl object and return....
HwWidgetFactory V : successes to get AllImpl object and return....
ActivityThread V ActivityThread,callActivityOnCreate
5. Summary
Repeated operations we can use scripts to solve problems and improve development efficiency. Remember to make sure your terminal can run pidcat before using this
Summarize