ADB(Android Debug Bridge),连接电脑和手机的桥梁=.=,位于SDK目录下的platform-tools下
1. 安装APK程序
DavidtekiMacBook-Air:EverydayStudy du$ adb install -r /Users/du/AndroidProjectForGerrit/EverydayStudy/app/build/outputs/apk/app_huawei_ver1.0.apk
Success
2. 查看系统盘符
DavidtekiMacBook-Air:EverydayStudy du$ adb shell df
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 1429040 600 1428440 1% /dev
none 1429040 0 1429040 0% /var
tmpfs 1429040 0 1429040 0% /mnt
none 1429040 0 1429040 0% /sys/fs/cgroup
/dev/block/dm-0 2999516 2411904 571228 81% /system
/dev/block/bootdevice/by-name/cust 507848 324796 172568 66% /cust
/dev/block/bootdevice/by-name/cache 253920 2264 246416 1% /cache
/dev/block/bootdevice/by-name/persist 28144 548 26944 2% /persist
/dev/block/bootdevice/by-name/dsp 12016 3740 7952 32% /dsp
/dev/block/bootdevice/by-name/modem 106448 75392 31056 71% /firmware
/dev/block/dm-1 25537840 23695364 1695020 94% /data
/dev/fuse 25537840 23695364 1695020 94% /storage/emulated
/dev/fuse 15553280 3570624 11982656 23% /storage/3377-15F2
/data/user/10 25537840 23695364 1695020 94% /data/user/10
3. 查看所有已经安装的应用
DavidtekiMacBook-Air:EverydayStudy du$ adb shell pm list packages -f
package:/system/app/MiuiScreenRecorder/MiuiScreenRecorder.apk=com.miui.screenrecorder
package:/system/priv-app/CtsShimPrivPrebuilt/CtsShimPrivPrebuilt.apk=com.android.cts.priv.ctsshim
package:/system/app/SampleExtAuthService/SampleExtAuthService.apk=com.qualcomm.qti.auth.sampleextauthservice
package:/system/priv-app/ContentExtension/ContentExtension.apk=com.miui.contentextension
package:/system/priv-app/TelephonyProvider/TelephonyProvider.apk=com.android.providers.telephony
package:/system/app/PowerKeeper/PowerKeeper.apk=com.miui.powerkeeper
package:/system/app/SecureSampleAuthServicev1/SecureSampleAuthServicev1.apk=com.qualcomm.qti.auth.securesampleauthservicev1
package:/system/app/FM/FM.apk=com.miui.fm
......
4. 使用adb shell,连接到手机终端
DavidtekiMacBook-Air:EverydayStudy du$ adb shell
hydrogen:/ $
5. 回到cmd模式,使用control+D(可连按多次)
DavidtekiMacBook-Air:EverydayStudy du$ adb shell
hydrogen:/ $ ^D
DavidtekiMacBook-Air:EverydayStudy du$
6. 在shell模式下使用logcat
DavidtekiMacBook-Air:EverydayStudy du$ adb shell
hydrogen:/ $ logcat | grep "abc"
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))
09-12 19:11:15.407 3358 3358 D StatusBar: removeNotificationViews(key=android.os.Binder@db4abc7)
09-12 19:11:15.407 3358 3358 W StatusBar: removeNotification for unknown key: android.os.Binder@db4abc7
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模式,再分别使用单独的命令。
DavidtekiMacBook-Air:EverydayStudy du$ adb shell
hydrogen:/ $ df
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 1429040 600 1428440 1% /dev
none 1429040 0 1429040 0% /var
tmpfs 1429040 0 1429040 0% /mnt
none 1429040 0 1429040 0% /sys/fs/cgroup
/dev/block/dm-0 2999516 2411904 571228 81% /system
/dev/block/bootdevice/by-name/cust 507848 324796 172568 66% /cust
/dev/block/bootdevice/by-name/cache 253920 2264 246416 1% /cache
/dev/block/bootdevice/by-name/persist 28144 548 26944 2% /persist
/dev/block/bootdevice/by-name/dsp 12016 3740 7952 32% /dsp
/dev/block/bootdevice/by-name/modem 106448 75392 31056 71% /firmware
/dev/block/dm-1 25537840 23695576 1694808 94% /data
/dev/fuse 25537840 23695576 1694808 94% /storage/emulated
/dev/fuse 15553280 3570624 11982656 23% /storage/3377-15F2
/data/user/10 25537840 23695576 1694808 94% /data/user/10
8. ADB重新启动(事实上我的手机重启了系统=.=)
DavidtekiMacBook-Air:EverydayStudy du$ adb reboot
DavidtekiMacBook-Air:EverydayStudy du$
9. 无线调试(通过TCP端口连接),即不通过USB进行手机软件的调试,只需要手机与电脑在同一局域网中即可。
首先,在手机中找到设备的IP地址,一般在设置->关于手机->状态信息里头,我这儿是10.0.1.173,输入adb connect
DavidtekiMacBook-Air:~ du$ adb connect 10.0.1.173:5555
connected to 10.0.1.173:5555
断开连接
DavidtekiMacBook-Air:~ du$ adb disconnect 10.0.1.173:5555
disconnected 10.0.1.173:5555
这里有一个问题,就是可能会连接不上,如下unable to connect to ...: Connection refused
DavidtekiMacBook-Air:~ du$ adb connect 10.0.1.173
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,连接到电脑,然后执行下面的命令
DavidtekiMacBook-Air:~ du$ adb usb
restarting in USB mode
DavidtekiMacBook-Air:~ du$ adb tcpip 5555
restarting in TCP mode port: 5555
DavidtekiMacBook-Air:~ du$ adb connect 10.0.1.173:5555
connected to 10.0.1.173:5555
②拔掉USB,断开手机与电脑的连接,执行下面的断开连接的命令
DavidtekiMacBook-Air:~ du$ adb disconnect 10.0.1.173:5555
disconnected 10.0.1.173:5555
此时再次尝试连接命令和断开命令,应该会成功。
良心的公众号,更多精品文章,不要忘记关注哈
《Android和Java技术驿站》