adb命令詳解-創(chuàng)新互聯(lián)

本文的內(nèi)容來自于網(wǎng)絡(luò)的整理,引用的URL:

成都創(chuàng)新互聯(lián)是一家以網(wǎng)站建設(shè)公司、網(wǎng)頁設(shè)計(jì)、品牌設(shè)計(jì)、軟件運(yùn)維、成都網(wǎng)站營銷、小程序App開發(fā)等移動開發(fā)為一體互聯(lián)網(wǎng)公司。已累計(jì)為茶樓設(shè)計(jì)等眾行業(yè)中小客戶提供優(yōu)質(zhì)的互聯(lián)網(wǎng)建站和軟件開發(fā)服務(wù)。

http://blog.csdn.net/chief1985/article/details/5553022

Adb的工作原理

android的adb采用的是server+client的方式,所以adb是支持多個(gè)設(shè)備同時(shí)連接的。通過adb devices命令可以看到所有連接的android設(shè)備,而多個(gè)設(shè)備都連上adb server,如果你想針對某一個(gè)設(shè)備執(zhí)行adb命令,可以在adb命令后面加上-s <serial number>,例如adb –s 12345678 push c:/a.txt /data/。adb的設(shè)計(jì)可以參考 http://blog.csdn.net/wbw1985/archive/2010/04/02/5443910.aspx。

常用命令

adb shell

有兩個(gè)比較好用的命令是adb shell amadb shell pm,這兩個(gè)命令在frameworks/base/cmds下面。am命令主要用于管理Activity,例如啟動,停止Activity(eclipse在運(yùn)行Activity就使用了這個(gè)命令),發(fā)送intent;pm命令則主要用于管理應(yīng)用package的管理,有點(diǎn)像控制面板的添加和刪除程序。

am命令的具體用法如下:

usage: am [start|broadcast|instrument|profile]

am start -D INTENT

am broadcast INTENT

am instrument [-r] [-e <ARG_NAME> <ARG_VALUE>] [-p <PROF_FILE>]

[-w] <COMPONENT>

am profile <PROCESS> [start <PROF_FILE>|stop]

INTENT is described with:

[-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]

[-c <CATEGORY> [-c <CATEGORY>] ...]

[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]

[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]

[-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]

[-n <COMPONENT>] [-f <FLAGS>] [<URI>]

The start command starts activity. Use -D option to make 'DebugOption' true.

The broadcast command sends broadcast.

The instrument command starts instrumentation.

Use -r option to make 'rawMode' true.

Use -e option to add the pair of ARG_NAME and ARG_VALUE into Bundle.

Use -p option to specify profileFile.

Use -w option to make 'wait' true in order to new an instance of InstrumentationWatcher.

Use COMPONENT to specify the name of the instrumentation component.

The profile command turn on/off profiling in a particular process specified by PROCESS.

Use start option to turn on and stop to turn off.Use PROF_FILE to specify the file path of profile.

Use -a to set action specified by ACTION to be performed.

Use -d to create a Uri(data) which parses the given encoded URI string DATA_URI.

Use -t to specify the type specified by MIME_TYPE. Use -c to add a new category specified by

CATEGORY to the intent.

Use -e or --es to add extended data to the intent.EXTRA_KEY specifies the name of the extra data and

EXTRA_STRING_VALUE specifies the string data value.

Use --ez to add extended data to the intent. EXTRA_KEY specifies the name of the extra data and

EXTRA_BOOLEAN_VALUE specifies the serializable data value.

Use -e or --ei to add extended data to the intent. EXTRA_KEY specifies the name of the extra data and

EXTRA_INT_VALUE specifies the serializable data value.

Use -n to explicitly set the component specified by COMPONENT to handle the intent.

Use -f to set special flags controlling how this intent is handled.FLAGS specifies the desired flags.

Use URI to create an intent from a URI.

pm命令的具體用法如下:

usage: pm [list|path|install|uninstall]

    pm list packages [-f]

    pm list permission-groups

    pm list permissions [-g] [-f] [-d] [-u] [GROUP]

    pm list instrumentation [-f] [TARGET-PACKAGE]

    pm path PACKAGE

    pm install [-l] [-r] PATH

    pm uninstall [-k] PACKAGE

    pm enable PACKAGE_OR_COMPONENT

    pm disable PACKAGE_OR_COMPONENT

The list packages command prints all packages.  Use

the -f option to see their associated file.

The list permission-groups command prints all known

permission groups.

The list permissions command prints all known

permissions, optionally only those in GROUP.  Use

the -g option to organize by group.  Use

the -f option to print all information.  Use

the -s option for a short summary.  Use

the -d option to only list dangerous permissions.  Use

the -u option to list only the permissions users will see.

The list instrumentation command prints all instrumentations,

or only those that target a specified package.  Use the -f option

to see their associated file.

The path command prints the path to the .apk of a package.

The install command installs a package to the system.  Use

the -l option to install the package with FORWARD_LOCK. Use

the -r option to reinstall an exisiting app, keeping its data.

The uninstall command removes a package from the system. Use

the -k option to keep the data and cache directories around

after the package removal.

The enable and disable commands change the enabled state of

a given package or component (written as "package/class").

frameworks/base/cmds下面還有一個(gè)別的命令,如下

dumpstate

dumpsys

ime

input

installd

runtime

service

servicemanager

surfaceflinger

svc

system_server

下面是上述命令的一些輸出:

C:/Users/xufan>adb shell dumpstate

========================================================

== dumpstate

========================================================

------ MEMORY INFO ------

MemTotal:     94348 kB

MemFree:      9912 kB

Buffers:       0 kB

Cached:      47876 kB

SwapCached:      0 kB

Active:      47016 kB

Inactive:     29980 kB

SwapTotal:      0 kB

SwapFree:       0 kB

Dirty:        0 kB

Writeback:      0 kB

AnonPages:    29156 kB

Mapped:      22948 kB

Slab:       2992 kB

SReclaimable:    796 kB

SUnreclaim:    2196 kB

PageTables:    2180 kB

NFS_Unstable:     0 kB

Bounce:        0 kB

WritebackTmp:     0 kB

CommitLimit:   47172 kB

Committed_AS:  658548 kB

VmallocTotal:  876544 kB

VmallocUsed:    8380 kB

VmallocChunk:  859132 kB

------ CPU INFO ------

User 7%, System 23%, IOW 0%, IRQ 0%

User 11 + Nice 0 + Sys 33 + Idle 98 + IOW 0 + IRQ 0 + SIRQ 0 = 142

 PID  TID CPU% S   VSS   RSS UID    Thread      Proc

 743  743  26% R   928K   384K shell   top       top

 565  581  1% S 177876K  25384K system  er.ServerThread system_server

 565  570  0% S 177876K  25384K system  Binder Thread # system_server

 565  571  0% S 177876K  25384K system  Binder Thread # system_server

 605  605  0% S 105820K  17540K radio   app_process   com.android.phone

 565  619  0% S 177876K  25384K system  er$SensorThread system_server

 565  585  0% S 177876K  25384K system  PackageManager  system_server

 565  586  0% S 177876K  25384K system  FileObserver   system_server

 565  589  0% S 177876K  25384K system  SyncHandlerThre system_server

 565  590  0% S 177876K  25384K system  UEventObserver  system_server

 565  591  0% S 177876K  25384K system  PowerManagerSer system_server

 565  592  0% S 177876K  25384K system  AlarmManager   system_server

 565  593  0% S 177876K  25384K system  WindowManager  system_server

 565  594  0% S 177876K  25384K system  InputDeviceRead system_server

 565  595  0% S 177876K  25384K system  WindowManagerPo system_server

 565  596  0% S 177876K  25384K system  InputDispatcher system_server

 565  597  0% S 177876K  25384K system  ConnectivityThr system_server

 565  598  0% S 177876K  25384K system  WifiService   system_server

 565  599  0% S 177876K  25384K system  WifiWatchdogThr system_server

 565  600  0% S 177876K  25384K system  er.ServerThread system_server

 565  601  0% S 177876K  25384K system  GpsEventThread  system_server

 565  602  0% S 177876K  25384K system  AudioService   system_server

 565  603  0% S 177876K  25384K system  android:unnamed system_server

 565  604  0% S 177876K  25384K system  android:unnamed system_server

 565  609  0% S 177876K  25384K system  watchdog     system_server

 565  640  0% S 177876K  25384K system  r.MountListener system_server

 565  651  0% S 177876K  25384K system  Binder Thread # system_server

 565  678  0% S 177876K  25384K system  Binder Thread # system_server

 605  606  0% S 105820K  17540K radio   HeapWorker    com.android.phone

 605  607  0% S 105820K  17540K radio   Signal Catcher  com.android.phone

------ PROCRANK ------

C:/Users/xufan>adb shell dumpsys

 Provider mms-sms

  ContentProviderRecord{436a0040 com.android.providers.telephony.MmsSmsProvide

r}

  package=com.android.providers.telephony process=com.android.phone

  app=Proce***ecord{43638990 605:com.android.phone/1001}

  launchingApp=null

  provider=android.content.ContentProviderProxy@436c8c88

  name=mms-sms

  isSyncable=false

  multiprocess=true initOrder=0 uid=1001

  clients=[]

  externals=0

 Published content providers (by class):

 Provider android.content.SyncProvider

  ContentProviderRecord{435bceb8 android.content.SyncProvider}

  package=android process=system

  app=Proce***ecord{436236b8 565:system/1000}

  launchingApp=null

  provider=android.content.ContentProvider$Transport@43634c48

  name=sync

  isSyncable=false

  multiprocess=false initOrder=0 uid=1000

  clients=[]

  externals=0

 Provider com.android.providers.telephony.MmsSmsProvider

  ContentProviderRecord{436a0040 com.android.providers.telephony.MmsSmsProvide

r}

  package=com.android.providers.telephony process=com.android.phone

  app=Proce***ecord{43638990 605:com.android.phone/1001}

  launchingApp=null

  provider=android.content.ContentProviderProxy@436c8c88

  name=mms-sms

  isSyncable=false

  multiprocess=true initOrder=0 uid=1001

  clients=[]

  externals=0

 Provider com.android.providers.settings.SettingsProvider

  ContentProviderRecord{435bda90 com.android.providers.settings.SettingsProvid

er}

  package=com.android.providers.settings process=system

  app=Proce***ecord{436236b8 565:system/1000}

  launchingApp=null

  provider=android.content.ContentProvider$Transport@435a2b58

  name=settings

  isSyncable=false

  multiprocess=false initOrder=100 uid=1000

  clients=[Proce***ecord{4371bad0 655:com.android.alarmclock/10000}, Proce***e

cord{43638990 605:com.android.phone/1001}]

  externals=0

 Provider com.android.providers.userdictionary.UserDictionaryProvider

  ContentProviderRecord{436a2398 com.android.providers.userdictionary.UserDict

ionaryProvider}

  package=com.android.providers.userdictionary process=android.process.acore

  app=Proce***ecord{43645bc0 608:android.process.acore/10004}

  launchingApp=null

  provider=android.content.ContentProviderProxy@436ccca0

  name=user_dictionary

  isSyncable=false

  multiprocess=false initOrder=0 uid=10004

  clients=[]

  externals=0

 Provider com.android.providers.contacts.ContactsProvider

  ContentProviderRecord{436a25e8 com.android.providers.contacts.ContactsProvid

er}

  package=com.android.providers.contacts process=android.process.acore

  app=Proce***ecord{43645bc0 608:android.process.acore/10004}

  launchingApp=null

  provider=android.content.ContentProviderProxy@436cd910

  name=contacts;call_log

  isSyncable=false

  multiprocess=false initOrder=0 uid=10004

  clients=[]

  externals=0

 Provider com.android.providers.drm.DrmProvider

  ContentProviderRecord{4361c528 com.android.providers.drm.DrmProvider}

  package=com.android.providers.drm process=android.process.media

  app=Proce***ecord{436e89e8 644:android.process.media/10003}

  launchingApp=null

  provider=android.content.ContentProviderProxy@435ffed0

  name=drm

  isSyncable=false

  multiprocess=false initOrder=0 uid=10003

  clients=[]

  externals=0

 Provider com.android.launcher.LauncherProvider

  ContentProviderRecord{436a2710 com.android.launcher.LauncherProvider}

  package=com.android.launcher process=android.process.acore

  app=Proce***ecord{43645bc0 608:android.process.acore/10004}

  launchingApp=null

  provider=android.content.ContentProviderProxy@436cdff0

  name=com.android.launcher.settings

  isSyncable=false

  multiprocess=false initOrder=0 uid=10004

  clients=[]

  externals=0

 Provider com.android.providers.media.MediaProvider

  ContentProviderRecord{436e8728 com.android.providers.media.MediaProvider}

  package=com.android.providers.media process=android.process.media

  app=Proce***ecord{436e89e8 644:android.process.media/10003}

  launchingApp=Proce***ecord{436e89e8 644:android.process.media/10003}

  provider=android.content.ContentProviderProxy@435ff638

  name=media

  isSyncable=false

  multiprocess=false initOrder=0 uid=10003

  clients=[]

  externals=0

 Provider com.android.providers.downloads.DownloadProvider

  ContentProviderRecord{4369e808 com.android.providers.downloads.DownloadProvi

der}

  package=com.android.providers.downloads process=android.process.media

  app=Proce***ecord{436e89e8 644:android.process.media/10003}

  launchingApp=null

  provider=android.content.ContentProviderProxy@43600a50

  name=downloads

  isSyncable=false

  multiprocess=false initOrder=0 uid=10003

  clients=[]

  externals=0

 Provider com.android.providers.telephony.MmsProvider

  ContentProviderRecord{436a0f28 com.android.providers.telephony.MmsProvider}

  package=com.android.providers.telephony process=com.android.phone

  app=Proce***ecord{43638990 605:com.android.phone/1001}

  launchingApp=null

  provider=android.content.ContentProviderProxy@436c93a8

  name=mms

  isSyncable=false

  multiprocess=true initOrder=0 uid=1001

  clients=[]

  externals=0

 Provider com.android.googlesearch.SuggestionProvider

  ContentProviderRecord{436a24c0 com.android.googlesearch.SuggestionProvider}

  package=com.android.googlesearch process=android.process.acore

  app=Proce***ecord{43645bc0 608:android.process.acore/10004}

  launchingApp=null

  provider=android.content.ContentProviderProxy@436cd288

  name=com.android.googlesearch.SuggestionProvider

  isSyncable=false

  multiprocess=false initOrder=0 uid=10004

  clients=[]

  externals=0

 Provider com.android.providers.telephony.TelephonyProvider

  ContentProviderRecord{436a1030 com.android.providers.telephony.TelephonyProv

ider}

  package=com.android.providers.telephony process=com.android.phone

  app=Proce***ecord{43638990 605:com.android.phone/1001}

  launchingApp=null

  provider=android.content.ContentProviderProxy@436c9988

  name=telephony

  isSyncable=false

  multiprocess=true initOrder=0 uid=1001

  clients=[]

  externals=0

 Provider com.android.providers.telephony.SmsProvider

  ContentProviderRecord{436a1138 com.android.providers.telephony.SmsProvider}

  package=com.android.providers.telephony process=com.android.phone

  app=Proce***ecord{43638990 605:com.android.phone/1001}

  launchingApp=null

  provider=android.content.ContentProviderProxy@436ca038

  name=sms

  isSyncable=false

  multiprocess=true initOrder=0 uid=1001

  clients=[]

  externals=0

 Provider com.android.phone.SimProvider

  ContentProviderRecord{436a1240 com.android.phone.SimProvider}

  package=com.android.phone process=com.android.phone

  app=Proce***ecord{43638990 605:com.android.phone/1001}

  launchingApp=null

  provider=android.content.ContentProviderProxy@436ca648

  name=sim

  isSyncable=false

  multiprocess=true initOrder=0 uid=1001

  clients=[]

  externals=0

 Provider com.android.alarmclock.AlarmProvider

  ContentProviderRecord{4371d520 com.android.alarmclock.AlarmProvider}

  package=com.android.alarmclock process=com.android.alarmclock

  app=Proce***ecord{4371bad0 655:com.android.alarmclock/10000}

  launchingApp=null

  provider=android.content.ContentProviderProxy@435e2c10

  name=com.android.alarmclock

  isSyncable=false

  multiprocess=false initOrder=0 uid=10000

  clients=[]

  externals=0

Granted Uri Permissions:

-------------------------------------------------------------------------------

DUMP OF SERVICE activity.senders:

Intent Senders in Current Activity Manager State:

 IntentSender IntentSenderRecord{435bb968 android broadcastIntent}

  packageName=android type=broadcastIntent flags=0x0

  activity=null who=null

  requestCode=0 requestResolvedType=null

  requestIntent=Intent { action=android.content.syncmanager.SYNC_ALARM }

  sent=false canceled=false

 IntentSender IntentSenderRecord{4359f4e0 android broadcastIntent}

  packageName=android type=broadcastIntent flags=0x0

  activity=null who=null

  requestCode=0 requestResolvedType=null

  requestIntent=Intent { action=android.intent.action.DATE_CHANGED }

  sent=false canceled=false

 IntentSender IntentSenderRecord{43638b10 android broadcastIntent}

  packageName=android type=broadcastIntent flags=0x0

  activity=null who=null

  requestCode=0 requestResolvedType=null

  requestIntent=Intent { action=com.android.service.Watchdog.REBOOT }

  sent=false canceled=false

 IntentSender IntentSenderRecord{436714c0 android broadcastIntent}

  packageName=android type=broadcastIntent flags=0x0

  activity=null who=null

  requestCode=0 requestResolvedType=null

  requestIntent=Intent { action=com.android.server.WifiManager.action.DEVICE_I

DLE }

  sent=false canceled=false

 IntentSender IntentSenderRecord{435e56d8 android broadcastIntent}

  packageName=android type=broadcastIntent flags=0x0

  activity=null who=null

  requestCode=0 requestResolvedType=null

  requestIntent=Intent { action=android.intent.action.TIME_TICK flags=0x400000

00 }

  sent=true canceled=false

 IntentSender IntentSenderRecord{435adb08 android broadcastIntent}

  packageName=android type=broadcastIntent flags=0x0

  activity=null who=null

  requestCode=0 requestResolvedType=null

  requestIntent=Intent { action=android.content.syncmanager.SYNC_POLL_ALARM }

  sent=true canceled=false

 IntentSender IntentSenderRecord{4359edf0 android broadcastIntent}

  packageName=android type=broadcastIntent flags=0x0

  activity=null who=null

  requestCode=0 requestResolvedType=null

  requestIntent=Intent { action=com.android.service.Watchdog.CHECKUP }

  sent=false canceled=false

 IntentSender IntentSenderRecord{436e3198 android broadcastIntent}

  packageName=android type=broadcastIntent flags=0x0

  activity=null who=null

  requestCode=0 requestResolvedType=null

  requestIntent=Intent { }

  sent=false canceled=false

-------------------------------------------------------------------------------

DUMP OF SERVICE activity.services:

Services in Current Activity Manager State:

-------------------------------------------------------------------------------

DUMP OF SERVICE alarm:

Current Alarm Manager state:

 Realtime alarms that are scheduled:

 RTC #1:

  Alarm{436358a0 type 1 android}

  type=1 when=1272931200000 repeatInterval=0 count=0

  operation=PendingIntent{43617020 target IntentSenderRecord{4359f4e0 android

broadcastIntent}}

 RTC #0:

  Alarm{43695080 type 1 android}

  type=1 when=1272884280000 repeatInterval=0 count=0

  operation=PendingIntent{4358e9d8 target IntentSenderRecord{435e56d8 android

broadcastIntent}}

 Elapsed realtime wakeup alarms that are scheduled:

 ELAPSED_REALTIME_WAKEUP #0:

  Alarm{4361e8e8 type 2 android}

  type=2 when=90877805 repeatInterval=0 count=0

  operation=PendingIntent{435adc60 target IntentSenderRecord{435adb08 android

broadcastIntent}}

 Broadcast ref count: 0

 Alarm Stats:

 android

  4729ms running, 1 wakeups

  1 alarms: Intent { action=android.content.syncmanager.SYNC_POLL_ALARM flags=

0x4 (has extras) }

  28 alarms: Intent { action=android.intent.action.TIME_TICK flags=0x40000004

(has extras) }

-------------------------------------------------------------------------------

DUMP OF SERVICE appwidget:

Providers: (size=3)

 [0] provder=ComponentInfo{com.android.alarmclock/com.android.alarmclock.Analog

AppWidgetProvider} min=(146x146) updatePeriodMillis=0 initialLayout=2130903043 z

ombie=false

 [1] provder=ComponentInfo{com.android.camera/com.android.camera.PhotoAppWidget

Provider} min=(146x146) updatePeriodMillis=0 initialLayout=2130903052 zombie=fal

se

 [2] provder=ComponentInfo{com.android.music/com.android.music.MediaAppWidgetPr

ovider} min=(294x72) updatePeriodMillis=0 initialLayout=2130903040 zombie=false

AppWidgetIds: (size=1)

 [0] appWidgetId=1 host=1024/com.android.launcher provider=ComponentInfo{com.an

droid.alarmclock/com.android.alarmclock.AnalogAppWidgetProvider} host.callbacks=

com.android.internal.appwidget.IAppWidgetHost$Stub$Proxy@4363f610 views=android.

widget.RemoteViews@43731e90

Hosts: (size=1)

 [0] packageName=com.android.launcher uid=10004 hostId=1024 callbacks=com.andro

id.internal.appwidget.IAppWidgetHost$Stub$Proxy@4363f610 instances.size=1 zombie

=false

-------------------------------------------------------------------------------

DUMP OF SERVICE audio:

C:/Users/xufan>adb shell ime list

com.android.inputmethod.latin/.LatinIME:

 mId=com.android.inputmethod.latin/.LatinIME mSettingsActivityName=com.android.

inputmethod.latin.LatinIMESettings

 mIsDefaultResId=0x7f060001

 Service:

  Filter: null

  priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false

  labelRes=0x0 nonLocalizedLabel=null icon=0x0

  ServiceInfo:

com.android.inputmethod.pinyin/.PinyinIME:

 mId=com.android.inputmethod.pinyin/.PinyinIME mSettingsActivityName=com.androi

d.inputmethod.pinyin.SettingsActivity

 mIsDefaultResId=0x7f060000

 Service:

  Filter: null

  priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false

  labelRes=0x0 nonLocalizedLabel=null icon=0x0

  ServiceInfo:

C:/Users/xufan>adb shell input

usage: input [text|keyevent]

    input text <string>

    input keyevent <event_code>

ADB高級應(yīng)用

一、利用無線來查看adb shell

> adb tcpip 5555


連接:

> adb connect IP:5555


見后文《調(diào)試注意事項(xiàng)》


二、模擬按鍵

 > adb shell input keyevent "value"


部分常見按鍵對應(yīng)值:

Key  | Constant Value

Back 4

Power 26

Menu 82

Home 3

Search 84


方向鍵:

上 19

下 20

左 21

右 22

確認(rèn)(類似單擊):23


三、adb shell下查看系統(tǒng)盤符

 > adb shell df


四、adb shell下掛載系統(tǒng)

> adb shell

> busybox mount -o remount,rw /system



五、adb shell 下移除USB設(shè)備

> adb shell

> vdc unshare /mnt/sdcard ums



六、adb shell 下查看內(nèi)核信息

> cat /proc/kmsg &


七、查看build配置的值(以heap為例)

> adb shell getprop | grep heap


八、通過sendevent 模擬按鍵以及鼠標(biāo)


直接用input實(shí)現(xiàn):

> adb shell input keyevent 3

> adb shell input tap 250 250

> adb shell input swipe 250 250 300 300



九、查看屏幕顯示的fps

開啟系統(tǒng)屬性:debug.sf.fps=1
然后直接logcat -s SurfaceFlinger -v time
(看SurfaceFlinger里面打印出來時(shí)多少)


十、查看當(dāng)前運(yùn)行程序棧


> dumpsys window windows | busybox grep "Window #"



十一、查看當(dāng)前設(shè)備DDR運(yùn)行頻率

> cat /proc/clocks | busybox grep "ddr"


十二:ADB logcat過濾

adb logcat -s TAG_NAME
adb logcat -s TAG_NAME_1 TAG_NAME_2

adb logcat “*:PRIORITY”

adb logcat -s TAG_NAME:PRIORITY
adb logcat -s TAG_NAME_1:PRIORITY_1 TAG_NAME_2:PRIORITY


優(yōu)先級(PRIORITY)分為以下幾種:

V – Verbose
D – Debug
I – Info
W – Warning
E – Error
F – Fatal
S – Silent


范例:

> adb logcat *:E 查看異常信息

> adb logcat -s "TAG"  過濾TAG


十三:查看設(shè)備是否擁有su權(quán)限(4.2及之前版本)

> adb shell
> ps
# 會列出系統(tǒng)進(jìn)程
# 選一個(gè)u開頭的 表示普通程序
> su u0_a8
#切換到u0_a8下 #號變 >
> su
#如果可以執(zhí)行,>號為#號,則表示有su權(quán)限,如果提示權(quán)限問題,就沒有su權(quán)限


十四:查看應(yīng)用引用

adb 查看Android應(yīng)用所有引用

> adb shell

> ps  (查看PID號)

> cd /proc/PID號/fd

> busybox ls -l

也將文件拷貝出來

> cat xxx > /sdcard/xxx


十五:獲取運(yùn)行內(nèi)存/CPU信息

> adb shell

> cat /proc/meminfo

> cat /proc/cpuinfo


十六:抓取Logcat信息及kmsg信息

 # cat proc/kmsg >/data/kmsg.txt & 
 # logcat -v time >/data/logcat.txt &


十七:查看Android(手機(jī)\平板\開發(fā)板等)設(shè)備信息

> adb shell dumpsys package > package.xml

     (此命令可顯示手機(jī)(平板)可供應(yīng)用查詢到的library和feature)


十八、輸出所有已經(jīng)安裝的應(yīng)用

> adb shell pm list packages -f


十九、查看預(yù)安apk

> adb shell pm list packages -3


二十:清除logcat緩沖區(qū)

(用這個(gè)命令來清除一些重復(fù)出現(xiàn)的過時(shí)的日志)
> adb logcat -c


二十一、目前認(rèn)為最牛的adb命令:截取屏幕圖片

截圖直接保存到電腦

$ adb shell screencap -p | sed 's/\r$//' > screen.png

執(zhí)行adb shell 將\n轉(zhuǎn)換\r\n, 因此需要用sed刪除多余的\r

如果直接當(dāng)命令用還可以用 alias 包裝裝起來

$ alias and-screencap="adb shell screencap -p | sed 's/\r$//'"
$ and-screencap > screen.png

以后就可以方便的用and-screencap > 直接將截圖保存到電腦上了


其他入門級但也比較常見的adb命令

1、查看所有已經(jīng)連接上的設(shè)備

adb devices

如果有多個(gè)設(shè)備連接到電腦,可以通過 adb -s DEVICE_ID 來指定用哪一個(gè)


2、掛載system分區(qū)(當(dāng)然需要設(shè)備支持)

adb remount


3、安裝與卸載應(yīng)用

adb install <apk文件路徑>
adb install -r <apk文件路徑>    通過install命令來安裝apk文件,-r參數(shù)可以重新安裝某個(gè)應(yīng)用并保留應(yīng)用數(shù)據(jù)

#舉例
adb install -r ~/chrome.apk

卸載應(yīng)用:
adb uninstall <軟件名>

adb uninstall -k <軟件名>        如果加 -k 參數(shù),為卸載軟件但是保留配置和緩存文件
#舉例
adb uninstall com.android.chrome


4、啟動一個(gè)Activity

adb shell am start 包名/.類名
adb shell am start 包名/類的全名


5、登錄設(shè)備shell

adb shell --這個(gè)命令將登錄設(shè)備的shell.
adb shell <command命令>     后面加<command命令>將是直接運(yùn)行設(shè)備命令, 相當(dāng)于執(zhí)行遠(yuǎn)程命令


6. 從電腦上發(fā)送文件到設(shè)備

       --用push命令可以把本機(jī)電腦上的文件或者文件夾復(fù)制到設(shè)備(手機(jī))

adb remount    ## remount '/system'分區(qū) as read-write

adb push <本地路徑> <遠(yuǎn)程路徑>


7. 從設(shè)備上下載文件到電腦

       --用pull命令可以把設(shè)備(手機(jī))上的文件或者文件夾復(fù)制到本機(jī)電腦

adb pull <遠(yuǎn)程路徑> <本地路徑>


8. 顯示幫助信息(包括各種命令用法與含義) 

adb help


引用:

http://www.growingwiththeweb.com/2014/01/handy-adb-commands-for-android.html

http://blog.csdn.net/wirelessqa/article/details/29187339

http://blog.csdn.net/centralperk/article/details/7644725

其他引用:

1.模擬功能按鍵

命令格式:adb shell sendevent [device] [type] [code] [value]

如: adb shell sendevent /dev/input/event0 1 229 1 代表按下按下menu鍵

adb shell sendevent /dev/input/event0 1 229 0 代表按下松開menu鍵

說明:上述的命令需組合使用

另外所知道的命令如下:

Key Name CODE

MENU 229

HOME 102

BACK (back button) 158

CALL (call button) 231

END (end call button) 107


2. 發(fā)送鼠標(biāo)事件(Touch):

命令格式:adb shell sendevent [device] [type] [code] [value]


情況1:在某坐標(biāo)點(diǎn)上touch

如在屏幕的x坐標(biāo)為40,y坐標(biāo)為210的點(diǎn)上touch一下,命令如下

adb shell sendevent /dev/input/event0 3 0 40

adb shell sendevent /dev/input/event0 3 1 210

adb shell sendevent /dev/input/event0 1 330 1 //touch

adb shell sendevent /dev/input/event0 0 0 0 //it must have

adb shell sendevent /dev/input/event0 1 330 0 //untouch

adb shell sendevent /dev/input/event0 0 0 0 //it must have

注:以上六組命令必須配合使用,缺一不可


情況2:模擬滑動軌跡(可下載并采用aPaint軟件進(jìn)行試驗(yàn))

如下例是在aPaint軟件上畫出一條開始于(100,200),止于(108,200)的水平直線

adb shell sendevent /dev/input/event0 3 0 100 //start from point (100,200)

adb shell sendevent /dev/input/event0 3 1 200

adb shell sendevent /dev/input/event0 1 330 1 //touch

adb shell sendevent /dev/input/event0 0 0 0

adb shell sendevent /dev/input/event0 3 0 101 //step to point (101,200)

adb shell sendevent /dev/input/event0 0 0 0

…………………… //must list each step, here just skip

adb shell sendevent /dev/input/event0 3 0 108 //end point(108,200)

adb shell sendevent /dev/input/event0 0 0 0

adb shell sendevent /dev/input/event0 1 330 0 //untouch

adb shell sendevent /dev/input/event0 0 0 0


調(diào)試注意事項(xiàng)

當(dāng)調(diào)試那些使用了USB外設(shè)和主機(jī)特性的應(yīng)用時(shí),你很有可能把你的USB硬件連接到你的Android設(shè)備上,這將阻止你通過USB建立adb到Android設(shè)備的連接。你通過網(wǎng)絡(luò)仍可以訪問adb。通過網(wǎng)絡(luò)連接adb:

  1. 通過USB將Android設(shè)備連接到電腦。

  2. 從SDK 的 platform-tools 目錄,在命令行輸入adb tcpip 5555

  3. 輸入:adb connect <設(shè)備的IP地址>:5555 ,你現(xiàn)在將被連接到Android設(shè)備并能像adb logcat一樣發(fā)出通用的adb命令。

  4. 要設(shè)置你的設(shè)備監(jiān)聽USB,輸入adb usb 。

ADB很強(qiáng)大,記住一些ADB命令有助于提高工作效率。

  1. 獲取序列號:

    adb get-serialno
  2. 查看連接計(jì)算機(jī)的設(shè)備:

    adb devices
  3. 重啟機(jī)器:

    adb reboot
  4. 重啟到bootloader,即刷機(jī)模式:

    adb reboot bootloader
  5. 重啟到recovery,即恢復(fù)模式:

    adb reboot recovery
  6. 查看log:

    adb logcat
  7. 終止adb服務(wù)進(jìn)程:

    adb kill-server
  8. 重啟adb服務(wù)進(jìn)程:

    adb start-server
  9. 獲取機(jī)器MAC地址:

    adb shell  cat /sys/class/net/wlan0/address
  10. 獲取CPU序列號:

    adb shell cat /proc/cpuinfo
  11. 安裝APK:

    adb install <apkfile> //比如:adb install baidu.apk
  12. 保留數(shù)據(jù)和緩存文件,重新安裝apk:

    adb install -r <apkfile> //比如:adb install -r baidu.apk
  13. 安裝apk到sd卡:

    adb install -s <apkfile> // 比如:adb install -s baidu.apk
  14. 卸載APK:

    adb uninstall <package> //比如:adb uninstall com.baidu.search
  15. 卸載app但保留數(shù)據(jù)和緩存文件:

    adb uninstall -k <package> //比如:adb uninstall -k com.baidu.search
  16. 啟動應(yīng)用:

    adb shell am start -n <package_name>/.<activity_class_name>
  17. 查看設(shè)備cpu和內(nèi)存占用情況:

    adb shell top
  18. 查看占用內(nèi)存前6的app:

    adb shell top -m 6
  19. 刷新一次內(nèi)存信息,然后返回:

    adb shell top -n 1
  20. 查詢各進(jìn)程內(nèi)存使用情況:

    adb shell procrank
  21. 殺死一個(gè)進(jìn)程:

    adb shell kill [pid]
  22. 查看進(jìn)程列表:

    adb shell ps
  23. 查看指定進(jìn)程狀態(tài):

    adb shell ps -x [PID]
  24. 查看后臺services信息:

    adb shell service list
  25. 查看當(dāng)前內(nèi)存占用:

    adb shell cat /proc/meminfo
  26. 查看IO內(nèi)存分區(qū):

    adb shell cat /proc/iomem
  27. 將system分區(qū)重新掛載為可讀寫分區(qū):

    adb remount
  28. 從本地復(fù)制文件到設(shè)備:

    adb push <local> <remote>
  29. 從設(shè)備復(fù)制文件到本地:

    adb pull <remote> <local>
  30. 列出目錄下的文件和文件夾,等同于dos中的dir命令:

    adb shell ls
  31. 進(jìn)入文件夾,等同于dos中的cd 命令:

    adb shell cd <folder>
  32. 重命名文件:

    adb shell rename path/oldfilename path/newfilename
  33. 刪除system/avi.apk:

    adb shell rm /system/avi.apk
  34. 刪除文件夾及其下面所有文件:

    adb shell rm -r <folder>
  35. 移動文件:

    adb shell mv path/file newpath/file
  36. 設(shè)置文件權(quán)限:

    adb shell chmod 777 /system/fonts/DroidSansFallback.ttf
  37. 新建文件夾:

    adb shell mkdir path/foldelname
  38. 查看文件內(nèi)容:

    adb shell cat <file>
  39. 查看wifi密碼:

    adb shell cat /data/misc/wifi/*.conf
  40. 清除log緩存:

    adb logcat -c
  41. 查看bug報(bào)告:

    adb bugreport
  42. 獲取設(shè)備名稱:

    adb shell cat /system/build.prop
  43. 查看ADB幫助:

    adb help
  44. 跑monkey:

    adb shell monkey -v -p your.package.name 500

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

名稱欄目:adb命令詳解-創(chuàng)新互聯(lián)
文章出自:http://muchs.cn/article46/egdhg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、外貿(mào)網(wǎng)站建設(shè)網(wǎng)站設(shè)計(jì)、手機(jī)網(wǎng)站建設(shè)、全網(wǎng)營銷推廣、動態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化