ADB常用命令

ADB(Android Debug Bridge),连接电脑和手机的桥梁=.=,位于SDK目录下的platform-tools下

ADB常用命令_第1张图片

1. 安装APK程序

 
  
  1. DavidtekiMacBook-Air:EverydayStudy du$ adb install -r /Users/du/AndroidProjectForGerrit/EverydayStudy/app/build/outputs/apk/app_huawei_ver1.0.apk  

  2. Success  

2. 查看系统盘符

 
  
  1. DavidtekiMacBook-Air:EverydayStudy du$ adb shell df  

  2. Filesystem                            1K-blocks     Used Available Use% Mounted on  

  3. tmpfs                                   1429040      600   1428440   1% /dev  

  4. none                                    1429040        0   1429040   0% /var  

  5. tmpfs                                   1429040        0   1429040   0% /mnt  

  6. none                                    1429040        0   1429040   0% /sys/fs/cgroup  

  7. /dev/block/dm-0                         2999516  2411904    571228  81% /system  

  8. /dev/block/bootdevice/by-name/cust       507848   324796    172568  66% /cust  

  9. /dev/block/bootdevice/by-name/cache      253920     2264    246416   1% /cache  

  10. /dev/block/bootdevice/by-name/persist     28144      548     26944   2% /persist  

  11. /dev/block/bootdevice/by-name/dsp         12016     3740      7952  32% /dsp  

  12. /dev/block/bootdevice/by-name/modem      106448    75392     31056  71% /firmware  

  13. /dev/block/dm-1                        25537840 23695364   1695020  94% /data  

  14. /dev/fuse                              25537840 23695364   1695020  94% /storage/emulated  

  15. /dev/fuse                              15553280  3570624  11982656  23% /storage/3377-15F2  

  16. /data/user/10                          25537840 23695364   1695020  94% /data/user/10  

3. 查看所有已经安装的应用

 
  
  1. DavidtekiMacBook-Air:EverydayStudy du$ adb shell pm list packages -f  

  2. package:/system/app/MiuiScreenRecorder/MiuiScreenRecorder.apk=com.miui.screenrecorder  

  3. package:/system/priv-app/CtsShimPrivPrebuilt/CtsShimPrivPrebuilt.apk=com.android.cts.priv.ctsshim  

  4. package:/system/app/SampleExtAuthService/SampleExtAuthService.apk=com.qualcomm.qti.auth.sampleextauthservice  

  5. package:/system/priv-app/ContentExtension/ContentExtension.apk=com.miui.contentextension  

  6. package:/system/priv-app/TelephonyProvider/TelephonyProvider.apk=com.android.providers.telephony  

  7. package:/system/app/PowerKeeper/PowerKeeper.apk=com.miui.powerkeeper  

  8. package:/system/app/SecureSampleAuthServicev1/SecureSampleAuthServicev1.apk=com.qualcomm.qti.auth.securesampleauthservicev1  

  9. package:/system/app/FM/FM.apk=com.miui.fm  

  10. ......  

4. 使用adb shell,连接到手机终端

 
  
  1. DavidtekiMacBook-Air:EverydayStudy du$ adb shell  

  2. hydrogen:/ $  

5. 回到cmd模式,使用control+D(可连按多次)

 
  
  1. DavidtekiMacBook-Air:EverydayStudy du$ adb shell  

  2. hydrogen:/ $ ^D  

  3. DavidtekiMacBook-Air:EverydayStudy du$  

6. 在shell模式下使用logcat

 
  
  1. DavidtekiMacBook-Air:EverydayStudy du$ adb shell  

  2. hydrogen:/ $ logcat | grep "abc"  

  3. 09-12 18:32:09.587  3358  3358 D StatusBar: addNotificationViews(key=android.os.Binder@db4abc7, notification=StatusBarNotification(pkg=com.tencent.qqlive user=UserHandle{0} id=1047483640 tag=null key=0|com.tencent.qqlive|1047483640|null|10635: Notification(pri=2 contentView=com.tencent.qqlive/0x7f0301aa vibrate=null sound=default tick defaults=0x1 flags=0x10 color=0x00000000 vis=PRIVATE))  

  4. 09-12 19:11:15.407  3358  3358 D StatusBar: removeNotificationViews(key=android.os.Binder@db4abc7)  

  5. 09-12 19:11:15.407  3358  3358 W StatusBar: removeNotification for unknown key: android.os.Binder@db4abc7  

  6. 09-12 19:11:15.407  3358  3358 D PhoneStatusBar: removeNotification key=android.os.Binder@db4abc7 keyCode=229944263 old=null  

7. 在shell模式下查看盘符,与在cmd中使用adb shell df效果相同。其他命令类似,可先进入shell模式,再分别使用单独的命令。

 
  
  1. DavidtekiMacBook-Air:EverydayStudy du$ adb shell  

  2. hydrogen:/ $ df  

  3. Filesystem                            1K-blocks     Used Available Use% Mounted on  

  4. tmpfs                                   1429040      600   1428440   1% /dev  

  5. none                                    1429040        0   1429040   0% /var  

  6. tmpfs                                   1429040        0   1429040   0% /mnt  

  7. none                                    1429040        0   1429040   0% /sys/fs/cgroup  

  8. /dev/block/dm-0                         2999516  2411904    571228  81% /system  

  9. /dev/block/bootdevice/by-name/cust       507848   324796    172568  66% /cust  

  10. /dev/block/bootdevice/by-name/cache      253920     2264    246416   1% /cache  

  11. /dev/block/bootdevice/by-name/persist     28144      548     26944   2% /persist  

  12. /dev/block/bootdevice/by-name/dsp         12016     3740      7952  32% /dsp  

  13. /dev/block/bootdevice/by-name/modem      106448    75392     31056  71% /firmware  

  14. /dev/block/dm-1                        25537840 23695576   1694808  94% /data  

  15. /dev/fuse                              25537840 23695576   1694808  94% /storage/emulated  

  16. /dev/fuse                              15553280  3570624  11982656  23% /storage/3377-15F2  

  17. /data/user/10                          25537840 23695576   1694808  94% /data/user/10  

8. ADB重新启动(事实上我的手机重启了系统=.=)

 
  
  1. DavidtekiMacBook-Air:EverydayStudy du$ adb reboot  

  2. DavidtekiMacBook-Air:EverydayStudy du$  

9. 无线调试(通过TCP端口连接),即不通过USB进行手机软件的调试,只需要手机与电脑在同一局域网中即可。

首先,在手机中找到设备的IP地址,一般在设置->关于手机->状态信息里头,我这儿是10.0.1.173,输入adb connect

 
  
  1. DavidtekiMacBook-Air:~ du$ adb connect 10.0.1.173:5555  

  2. connected to 10.0.1.173:5555  

断开连接

 
  
  1. DavidtekiMacBook-Air:~ du$ adb disconnect 10.0.1.173:5555  

  2. disconnected 10.0.1.173:5555  

这里有一个问题,就是可能会连接不上,如下unable to connect to ...: Connection refused

 
  
  1. DavidtekiMacBook-Air:~ du$ adb connect 10.0.1.173  

  2. unable to connect to 10.0.1.173:5555: Connection refused  

查了一些方法后,只需要进行以下步骤即可连接成功:参考链接:https://stackoverflow.com/questions/33462720/adb-unable-to-connect-to-192-168-1-105555

①手机插上USB,连接到电脑,然后执行下面的命令

 
  
  1. DavidtekiMacBook-Air:~ du$ adb usb  

  2. restarting in USB mode  

  3. DavidtekiMacBook-Air:~ du$ adb tcpip 5555  

  4. restarting in TCP mode port: 5555  

  5. DavidtekiMacBook-Air:~ du$ adb connect 10.0.1.173:5555  

  6. connected to 10.0.1.173:5555  

②拔掉USB,断开手机与电脑的连接,执行下面的断开连接的命令

 
  
  1. DavidtekiMacBook-Air:~ du$ adb disconnect 10.0.1.173:5555  

  2. disconnected 10.0.1.173:5555  

此时再次尝试连接命令和断开命令,应该会成功。

良心的公众号,更多精品文章,不要忘记关注哈

《Android和Java技术驿站》


你可能感兴趣的:(Android进阶之旅)