1 . 多部手机的问题
开发时电脑连着测试机和自己的手机,输入 adb 命令 ➜adb get-serialno
会报错
➜adb get-serialno
error: more than one device/emulator
这时可以 需要 用 adb devices
查看有哪些设备,最后接入的设备在最前面。
➜adb devices
List of devices attached
375013eb device
TA004031ND device
要在某部手机上执行命令 需要指定 设备号 比如
➜ adb -s 375013eb get-serialno
375013eb
我有时候分不清设备的序列号,或者会连其他人的手机进行操作,就写了下面的命令,在最后接入的手机的设备执行命令。
➜ adb -s `adb devices |sed -n "2,1p" |awk '{print $1}'` get-serialno
375013eb
也是输出 375013eb
,把另外一部手机拔了再插,输出 TA004031ND
2 . 显示最前面的界面是哪一个 activity
有时产品或者运营会拿着手机来问某个界面的事情,如果是新接触一个项目,并不能记得住每一个界面对应哪个 activity 。其实接手很久了也不一定记得住,哈哈 。通过代码去找太费时间,而且不同的账号可能会跳不同的Activity ,逻辑太多,也容易找错。用下面的命令就可以直接找到当前界面对应哪一个 activity 了。
adb shell dumpsys activity activities | sed -En -e '/Running activities/,/Run #0/p'
➜ adb -s `adb devices |sed -n "2,1p" |awk '{print $1}'` shell dumpsys activity activities | sed -En -e '/Running activities/,/Run #0/p'
Running activities (most recent first):
TaskRecord{d96bc0b #10580 A=com.medium.reader U=0 sz=2}
Run #5: ActivityRecord{b7f4a69 u0 com.medium.reader/com.medium.android.donkey.read.ReadPostActivity t10580}
Run #4: ActivityRecord{9bb9dbf u0 com.medium.reader/com.medium.android.donkey.read.HomeActivity3 t10580}
TaskRecord{f4035c9 #10582 A=com.quora.android U=0 sz=1}
Run #3: ActivityRecord{7991203 u0 com.quora.android/.QuoraActivity t10582}
TaskRecord{8c3d501 #10579 I=com.google.android.googlequicksearchbox/com.google.android.apps.gsa.searchnow.SearchNowActivity U=0 sz=1}
Run #2: ActivityRecord{6773550 u0 com.google.android.googlequicksearchbox/com.google.android.apps.gsa.searchnow.SearchNowActivity t10579}
TaskRecord{6f30de7 #10577 A=com.android.vending U=0 sz=1}
Run #1: ActivityRecord{41eaf9d u0 com.android.vending/com.google.android.finsky.activities.MainActivity t10577}
TaskRecord{4e10e9d #10225 A=com.android.incallui U=0 sz=1}
Run #0: ActivityRecord{8c3ad50 u0 com.android.incallui/.InCallActivity t10225}
Running activities (most recent first):
TaskRecord{d656b36 #10152 A=com.android.systemui U=0 sz=1}
Run #1: ActivityRecord{9187c94 u0 com.android.systemui/.recents.RecentsActivity t10152}
TaskRecord{157e7f8 #10143 A=com.oneplus.hydrogen.launcher U=0 sz=1}
Run #0: ActivityRecord{bfe1ca0 u0 com.oneplus.hydrogen.launcher/.Launcher t10143}
上传文件到手机
adb push charles-ssl-proxying-certificate111.pem /sdcard/下载文件到电脑
adb pull /sdcard/charles-ssl-proxying-certificate111.pem ./cert/查看应用的线程
➜ adb shell ps -t |grep com.stack
u0_a107 10253 715 1850940 105484 SyS_epoll_ 0000000000 S com.stackexchange.marvin
➜ adb shell ps -t |grep u0_a107
u0_a107 10253 715 1859196 106940 SyS_epoll_ 0000000000 S com.stackexchange.marvin
u0_a107 10259 10253 1859196 106940 futex_wait 0000000000 S Jit thread pool
u0_a107 10260 10253 1859196 106940 do_sigtime 0000000000 S Signal Catcher
u0_a107 10261 10253 1859196 106940 futex_wait 0000000000 S ReferenceQueueD
u0_a107 10262 10253 1859196 106940 futex_wait 0000000000 S FinalizerDaemon
u0_a107 10263 10253 1859196 106940 futex_wait 0000000000 S FinalizerWatchd
u0_a107 10264 10253 1859196 106940 futex_wait 0000000000 S HeapTaskDaemon
u0_a107 10265 10253 1859196 106940 binder_thr 0000000000 S Binder:10253_1
u0_a107 10266 10253 1859196 106940 binder_thr 0000000000 S Binder:10253_2
u0_a107 10269 10253 1859196 106940 futex_wait 0000000000 S Profile Saver
u0_a107 10272 10253 1859196 106940 futex_wait 0000000000 S GAThread
u0_a107 10274 10253 1859196 106940 futex_wait 0000000000 S GAC_Executor[0]
u0_a107 10275 10253 1859196 106940 futex_wait 0000000000 S Queue
u0_a107 10276 10253 1859196 106940 futex_wait 0000000000 S Queue
u0_a107 10277 10253 1859196 106940 futex_wait 0000000000 S Queue
u0_a107 10278 10253 1859196 106940 futex_wait 0000000000 S Queue
u0_a107 10279 10253 1859196 106940 futex_wait 0000000000 S Queue
u0_a107 10281 10253 1859196 106940 binder_thr 0000000000 S Binder:10253_3
u0_a107 10285 10253 1859196 106940 futex_wait 0000000000 S Crashlytics Exc
u0_a107 10287 10253 1859196 106940 unix_strea 0000000000 S TcmReceiver
u0_a107 10289 10253 1859196 106940 SyS_epoll_ 0000000000 S websocket-threa
u0_a107 10290 10253 1859196 106940 poll_sched 0000000000 S Thread-8
u0_a107 10293 10253 1859196 106940 futex_wait 0000000000 S AsyncTask #1
u0_a107 10295 10253 1859196 106940 futex_wait 0000000000 S GAC_Executor[1]
u0_a107 10296 10253 1859196 106940 futex_wait 0000000000 S AsyncTask #2
u0_a107 10297 10253 1859196 106940 SyS_epoll_ 0000000000 S RenderThread
u0_a107 10298 10253 1859196 106940 futex_wait 0000000000 S pool-1-thread-1
u0_a107 10301 10253 1859196 106940 futex_wait 0000000000 S AsyncTask #3
u0_a107 10302 10253 1859196 106940 futex_wait 0000000000 S OkHttp Connecti
u0_a107 10303 10253 1859196 106940 futex_wait 0000000000 S pool-4-thread-1
u0_a107 10305 10253 1859196 106940 futex_wait 0000000000 S Crashlytics Tra
u0_a107 10311 10253 1859196 106940 futex_wait 0000000000 S OkHttp Connecti
u0_a107 10314 10253 1859196 106940 futex_wait 0000000000 S pool-1-thread-2
u0_a107 10318 10253 1859196 106940 futex_wait 0000000000 S RxComputationTh
u0_a107 10319 10253 1859196 106940 futex_wait 0000000000 S RxComputationTh
u0_a107 10320 10253 1859196 106940 futex_wait 0000000000 S Retrofit-Idle
u0_a107 10323 10253 1859196 106940 SyS_epoll_ 0000000000 S Picasso-Stats
u0_a107 10324 10253 1859196 106940 SyS_epoll_ 0000000000 S Picasso-Dispatc
u0_a107 10325 10253 1859196 106940 futex_wait 0000000000 S Picasso-refQueu
u0_a107 10326 10253 1859196 106940 futex_wait 0000000000 S Picasso-Idle
u0_a107 10327 10253 1859196 106940 futex_wait 0000000000 S Picasso-Idle
u0_a107 10329 10253 1859196 106940 futex_wait 0000000000 S Picasso-Idle
u0_a107 10331 10253 1859196 106940 futex_wait 0000000000 S hwuiTask1
u0_a107 10332 10253 1859196 106940 futex_wait 0000000000 S pool-1-thread-3
u0_a107 10335 10253 1859196 106940 poll_sched 0000000000 S ackexchange.com
u0_a107 10336 10253 1859196 106940 futex_wait 0000000000 S Okio Watchdog
u0_a107 10337 10253 1859196 106940 futex_wait 0000000000 S OkHttp SpdyConn
u0_a107 10338 10253 1859196 106940 futex_wait 0000000000 S pool-1-thread-4
u0_a107 10340 10253 1859196 106940 futex_wait 0000000000 S disconnect chec
u0_a107 10345 10253 1859196 106940 poll_sched 0000000000 S ww.gravatar.com
u0_a107 10352 10253 1859196 106940 futex_wait 0000000000 S hwuiTask2
u0_a107 10354 10253 1859196 106940 poll_sched 0000000000 S cdn.sstatic.net
u0_a107 10356 10253 1859196 106940 futex_wait 0000000000 S Timer-0
u0_a107 10357 10253 1859196 106940 futex_wait 0000000000 S Timer-1
u0_a107 10358 10253 1859196 106940 futex_wait 0000000000 S Timer-2
u0_a107 10359 10253 1859196 106940 futex_wait 0000000000 S Timer-3
一共开启了 51 个线程
➜ adb shell ps -t |grep u0_a107|wc -l
51