大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

adb命令详解

本文的内容来自于网络的整理,引用的URL:

创新互联公司是少有的网站设计制作、网站设计、营销型企业网站、微信小程序定制开发、手机APP,开发、制作、设计、买链接、推广优化一站式服务网络公司,2013年开创至今,坚持透明化,价格低,无套路经营理念。让网页惊喜每一位访客多年来深受用户好评

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

Adb的工作原理

android的adb采用的是server+client的方式,所以adb是支持多个设备同时连接的。通过adb devices命令可以看到所有连接的android设备,而多个设备都连上adb server,如果你想针对某一个设备执行adb命令,可以在adb命令后面加上-s ,例如adb –s 12345678 push c:/a.txt /data/。adb的设计可以参考 http://blog.csdn.net/wbw1985/archive/2010/04/02/5443910.aspx。


常用命令


adb shell

有两个比较好用的命令是adb shell amadb shell pm,这两个命令在frameworks/base/cmds下面。am命令主要用于管理Activity,例如启动,停止Activity(eclipse在运行Activity就使用了这个命令),发送intent;pm命令则主要用于管理应用package的管理,有点像控制面板的添加和删除程序。

am命令的具体用法如下:

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

am start -D INTENT 

am broadcast INTENT 

am instrument [-r] [-e ] [-p

[-w]  

am profile [start |stop] 

INTENT is described with: 

[-a ] [-d ] [-t

[-c [-c ] ...] 

[-e|--es ...] 

[--ez ...] 

[-e|--ei ...] 

[-n ] [-f ] [

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下面还有一个别的命令,如下 

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  

       input keyevent


ADB高级应用

一、利用无线来查看adb shell

> adb tcpip 5555


连接:

> adb connect IP:5555


见后文《调试注意事项》


二、模拟按键

 > adb shell input keyevent "value"


部分常见按键对应值:

Key  | Constant Value

Back 4

Power 26

Menu 82

Home 3

Search 84


方向键:

上 19

下 20

左 21

右 22

确认(类似单击):23


三、adb shell下查看系统盘符

 > adb shell df

 


四、adb shell下挂载系统

> adb shell

> busybox mount -o remount,rw /system



五、adb shell 下移除USB设备

> adb shell

> vdc unshare /mnt/sdcard ums



六、adb shell 下查看内核信息

> cat /proc/kmsg &


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

> adb shell getprop | grep heap


八、通过sendevent 模拟按键以及鼠标


直接用input实现:

> adb shell input keyevent 3

> adb shell input tap 250 250

> adb shell input swipe 250 250 300 300



九、查看屏幕显示的fps

开启系统属性:debug.sf.fps=1
然后直接logcat -s SurfaceFlinger -v time
(看SurfaceFlinger里面打印出来时多少)


十、查看当前运行程序栈


> dumpsys window windows | busybox grep "Window #" 



十一、查看当前设备DDR运行频率

> 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


优先级(PRIORITY)分为以下几种:

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


范例:

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

> adb logcat -s "TAG"    过滤TAG


十三:查看设备是否拥有su权限(4.2及之前版本)

> adb shell
> ps
# 会列出系统进程
# 选一个u开头的 表示普通程序
> su u0_a8
#切换到u0_a8下 #号变 >
> su
#如果可以执行,>号为#号,则表示有su权限,如果提示权限问题,就没有su权限


十四:查看应用引用

adb 查看Android应用所有引用

 

> adb shell

> ps  (查看PID号)

> cd /proc/PID号/fd

> busybox ls -l

 

也将文件拷贝出来

> cat xxx > /sdcard/xxx


十五:获取运行内存/CPU信息

> adb shell

> cat /proc/meminfo

> cat /proc/cpuinfo


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

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


十七:查看Android(手机\平板\开发板等)设备信息

> adb shell dumpsys package > package.xml

       (此命令可显示手机(平板)可供应用查询到的library和feature)


十八、输出所有已经安装的应用

> adb shell pm list packages -f


十九、查看预安apk

> adb shell pm list packages -3


二十:清除logcat缓冲区

(用这个命令来清除一些重复出现的过时的日志)
> adb logcat -c


二十一、目前认为最牛的adb命令:截取屏幕图片

截图直接保存到电脑

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

执行adb shell 将\n转换\r\n, 因此需要用sed删除多余的\r

如果直接当命令用还可以用 alias 包裝装起來

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

以后就可以方便的用and-screencap > 直接将截图保存到电脑上了


其他入门级但也比较常见的adb命令

1、查看所有已经连接上的设备

adb devices 

如果有多个设备连接到电脑,可以通过 adb -s DEVICE_ID 来指定用哪一个


2、挂载system分区(当然需要设备支持)

adb remount


3、安装与卸载应用

adb install
adb install -r      通过install命令来安装apk文件,-r参数可以重新安装某个应用并保留应用数据

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

卸载应用:
adb uninstall <软件名>

adb uninstall -k <软件名>         如果加 -k 参数,为卸载软件但是保留配置和缓存文件
#举例
adb uninstall com.android.chrome


4、启动一个Activity

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


5、登录设备shell

adb shell  --这个命令将登录设备的shell.
adb shell       后面加将是直接运行设备命令, 相当于执行远程命令


6. 从电脑上发送文件到设备

         --用push命令可以把本机电脑上的文件或者文件夹复制到设备(手机)

adb remount     ## remount '/system'分区 as read-write

adb push <本地路径> <远程路径>


7. 从设备上下载文件到电脑

         --用pull命令可以把设备(手机)上的文件或者文件夹复制到本机电脑

adb pull <远程路径> <本地路径> 


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. 发送鼠标事件(Touch):

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


情况1:在某坐标点上touch

如在屏幕的x坐标为40,y坐标为210的点上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软件进行试验)

如下例是在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


调试注意事项

当调试那些使用了USB外设和主机特性的应用时,你很有可能把你的USB硬件连接到你的Android设备上,这将阻止你通过USB建立adb到Android设备的连接。你通过网络仍可以访问adb。通过网络连接adb:

  1. 通过USB将Android设备连接到电脑。

  2. 从SDK 的 platform-tools 目录,在命令行输入adb tcpip 5555

  3. 输入:adb connect <设备的IP地址>:5555 ,你现在将被连接到Android设备并能像adb logcat一样发出通用的adb命令。

  4. 要设置你的设备监听USB,输入adb usb 。

ADB很强大,记住一些ADB命令有助于提高工作效率。

  1. 获取序列号:

    adb get-serialno
  2. 查看连接计算机的设备:

    adb devices
  3. 重启机器:

    adb reboot
  4. 重启到bootloader,即刷机模式:

    adb reboot bootloader
  5. 重启到recovery,即恢复模式:

    adb reboot recovery
  6. 查看log:

    adb logcat
  7. 终止adb服务进程:

    adb kill-server
  8. 重启adb服务进程:

    adb start-server
  9. 获取机器MAC地址:

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

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

    adb install  //比如:adb install baidu.apk
  12. 保留数据和缓存文件,重新安装apk:

    adb install -r  //比如:adb install -r baidu.apk
  13. 安装apk到sd卡:

    adb install -s  // 比如:adb install -s baidu.apk
  14. 卸载APK:

    adb uninstall  //比如:adb uninstall com.baidu.search
  15. 卸载app但保留数据和缓存文件:

    adb uninstall -k  //比如:adb uninstall -k com.baidu.search
  16. 启动应用:

    adb shell am start -n /.
  17. 查看设备cpu和内存占用情况:

    adb shell top
  18. 查看占用内存前6的app:

    adb shell top -m 6
  19. 刷新一次内存信息,然后返回:

    adb shell top -n 1
  20. 查询各进程内存使用情况:

    adb shell procrank
  21. 杀死一个进程:

    adb shell kill [pid]
  22. 查看进程列表:

    adb shell ps
  23. 查看指定进程状态:

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

    adb shell service list
  25. 查看当前内存占用:

    adb shell cat /proc/meminfo
  26. 查看IO内存分区:

    adb shell cat /proc/iomem
  27. 将system分区重新挂载为可读写分区:

    adb remount
  28. 从本地复制文件到设备:

    adb push  
  29. 从设备复制文件到本地:

    adb pull  
  30. 列出目录下的文件和文件夹,等同于dos中的dir命令:

    adb shell ls
  31. 进入文件夹,等同于dos中的cd 命令:

    adb shell cd 
  32. 重命名文件:

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

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

    adb shell rm -r 
  35. 移动文件:

    adb shell mv path/file newpath/file
  36. 设置文件权限:

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

    adb shell mkdir path/foldelname
  38. 查看文件内容:

    adb shell cat 
  39. 查看wifi密码:

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

    adb logcat -c
  41. 查看bug报告:

    adb bugreport
  42. 获取设备名称:

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

    adb help
  44. 跑monkey:

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

新闻名称:adb命令详解
文章来源:http://dzwzjz.com/article/ggjeoo.html
在线咨询
服务热线
服务热线:028-86922220
TOP