Android adb命令

收集整理一些adb用到的命令:


常用命令

  1. 列出目标设备上的activity栈(back stack)和任务(task)的信息, 还有其他组件的一些信息和一些关于进程的信息
    adb shell dumpsys activity

    ACTIVITY MANAGER RECENT TASKS (dumpsys activity recents)
      Recent tasks:
      * Recent #0: TaskRecord{2ee4be93 #231 A=com.jiang.android.rxjavaapp U=0 sz=2}
      * Recent #1: TaskRecord{246189d8 #154 A=com.meizu.flyme.launcher U=0 sz=1}
    
    ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
    Display #0 (activities from top to bottom):
      Stack #1:
        Task id #231
          TaskRecord{2ee4be93 #231 A=com.jiang.android.rxjavaapp U=0 sz=2}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.jiang.android.rxjavaapp/.activity.LauncherActivity }
    
            Hist #1: ActivityRecord{3d84d850 u0 com.jiang.android.rxjavaapp/.base.BaseWebActivity t231}
              Intent { cmp=com.jiang.android.rxjavaapp/.base.BaseWebActivity (has extras) }
              ProcessRecord{22281ed0 29630:com.jiang.android.rxjavaapp/u0a134}
            Hist #0: ActivityRecord{1869fd4b u0 com.jiang.android.rxjavaapp/.activity.MainActivity t231}
              Intent { cmp=com.jiang.android.rxjavaapp/.activity.MainActivity }
              ProcessRecord{22281ed0 29630:com.jiang.android.rxjavaapp/u0a134}
    
        Running activities (most recent first):
          TaskRecord{2ee4be93 #231 A=com.jiang.android.rxjavaapp U=0 sz=2}
            Run #1: ActivityRecord{3d84d850 u0 com.jiang.android.rxjavaapp/.base.BaseWebActivity t231}
            Run #0: ActivityRecord{1869fd4b u0 com.jiang.android.rxjavaapp/.activity.MainActivity t231}
    
        mResumedActivity: ActivityRecord{3d84d850 u0 com.jiang.android.rxjavaapp/.base.BaseWebActivity t231}
    
      Stack #0:
        Task id #154
          TaskRecord{246189d8 #154 A=com.meizu.flyme.launcher U=0 sz=1}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME]
     flg=0x10000000 cmp=com.meizu.flyme.launcher/.Launcher }
            Hist #0: ActivityRecord{5a81032 u0 com.meizu.flyme.launcher/.Launcher t154}
              Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.meizu.flyme.launcher/.Launcher }
              ProcessRecord{308e5dfc 2043:com.meizu.flyme.launcher/u0a13}
    
        Running activities (most recent first):
          TaskRecord{246189d8 #154 A=com.meizu.flyme.launcher U=0 sz=1}
            Run #0: ActivityRecord{5a81032 u0 com.meizu.flyme.launcher/.Launcher t154}
    
      mFocusedActivity: ActivityRecord{3d84d850 u0 com.jiang.android.rxjavaapp/.base.BaseWebActivity t231}
      mFocusedStack=ActivityStack{1d091723 stackId=1, 22 tasks} mLastFocusedStack=ActivityStack{1d091723 stackId=1, 22 tasks}
      mSleepTimeout=false
      mCurTaskId=231
      mUserStackInFront={}
      mActivityContainers={0=ActivtyContainer{0}A, 1=ActivtyContainer{1}A}
    
  2. 安装A.apk(路径为盘根目录)
    adb install E:\A.apk

  3. 卸载A.apk(包名:com.example)
    adb uninstall com.example

  4. A.apk设备中已经存在,重新安装(其实就是先卸载,再安装)
    adb install -r E:\A.apk

  5. test.apk在设备已经存在,需要保留缓存数据后卸载应用程序
    adb uninstall -k com.example

  6. 连接多个设备时,只选择某一个设备安装A.apk(其中一个设备名字:A1CEBNB22UFM)
    adb -s A1CEBNB22UFM install E:\A.apk

  7. 列出一些系统信息和所有应用的信息。这个命令的输出很庞大,这些信息 都非常详细,包括Features,Activity Resolver Table等。
    adb shell dumpsys packages

  8. 清除APP数据(package:com.example)(常用)
    adb shell pm clear com.example

  9. 使用命令行打印log,并使用Tag进行过滤(常用)
    adb logcat -s TAG

  10. 命令行窗口中使用LOG级别来过滤log(常用)
    adb logcat *:E

  11. 查看手机芯片型号:cat /proc/cpuinfo

    // 华为P9
    HWEVA:/ $ cat /proc/cpuinfo
    Processor       : AArch64 Processor rev 4 (aarch64)  //cpu架构
    processor       : 0
    BogoMIPS        : 3.84
    Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
    CPU implementer : 0x41
    CPU architecture: 8
    CPU variant     : 0x0
    CPU part        : 0xd03
    CPU revision    : 4
    
    ...省略1-6核处理器...
    
    processor       : 7
    BogoMIPS        : 3.84
    Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
    CPU implementer : 0x41
    CPU architecture: 8
    CPU variant     : 0x0
    CPU part        : 0xd08
    CPU revision    : 0
    

    两种主要执行状态:
    AArch64 - 64 位执行状态,包括该状态的异常模型、内存模型、程序员模型和指令集支持
    AArch32 - 32 位执行状态,包括该状态的异常模型、内存模型、程序员模型和指令集支持

  12. 查看指定应用包名下下的Service信息: dumpsys activity services PackageName
    在adb shell中输入(dumpsys activity services com.example.elson)

    注: Demo中集成了极光推送(PushService),百度鹰眼(LBSTraceService),自己的Service(TraceService)

    ACTIVITY MANAGER SERVICES (dumpsys activity services)
      User 0 active services:
      * ServiceRecord {1e54260b u0 com.example.elson/cn.jpush.android.service.PushService}
        intent={cmp=com.example.elson/cn.jpush.android.service.PushService}
        packageName=com.example.elson
        processName=com.example.elson:mult
        baseDir=/data/app/com.example.elson-2/base.apk
        dataDir=/data/data/com.example.elson
        app=ProcessRecord{3855bf94 29149:com.example.elson:mult/u0a94}
        createTime=-2m41s551ms startingBgTimeout=--
        lastActivity=-34s741ms restartTime=-2m41s498ms createdFromFg=true
        startRequested=true delayedStop=false stopIfKilled=false callStart=true lastStartId=6
        Bindings:
        * IntentBindRecord{145e65a2 CREATE}:
          intent={cmp=com.example.elson/cn.jpush.android.service.PushService}
          binder=android.os.BinderProxy@2c74d233
          requested=true received=true hasBound=true doRebind=false
          * Client AppBindRecord{c3b39f0 ProcessRecord{26ceb390 30976:com.example.elson:remote/u0a94}}
            Per-process Connections:
              ConnectionRecord{17c85c8e u0 CR com.example.elson/cn.jpush.android.service.PushService:@32188489}
          * Client AppBindRecord{7efb69 ProcessRecord{28c2ccfc 29108:com.example.elson/u0a94}}
            Per-process Connections:
              ConnectionRecord{2a89c1da u0 CR com.example.elson/cn.jpush.android.service.PushService:@3c4e3f85}
          * Client AppBindRecord{2e139ee ProcessRecord{3855bf94 29149:com.example.elson:mult/u0a94}}
            Per-process Connections:
              ConnectionRecord{27eeb232 u0 CR com.example.elson/cn.jpush.android.service.PushService:@1d59da3d}
        All Connections:
          ConnectionRecord{27eeb232 u0 CR com.example.elson/cn.jpush.android.service.PushService:@1d59da3d}
          ConnectionRecord{17c85c8e u0 CR com.example.elson/cn.jpush.android.service.PushService:@32188489}
          ConnectionRecord{2a89c1da u0 CR com.example.elson/cn.jpush.android.service.PushService:@3c4e3f85}
    
      * ServiceRecord {2007ad78 u0 com.example.elson/.service.TraceService}
        intent={cmp=com.example.elson/.service.TraceService}
        packageName=com.example.elson
        processName=com.example.elson
        baseDir=/data/app/com.example.elson-2/base.apk
        dataDir=/data/data/com.example.elson
        app=ProcessRecord{28c2ccfc 29108:com.example.elson/u0a94}
        createTime=-34s978ms startingBgTimeout=--
        lastActivity=-34s978ms restartTime=-34s978ms createdFromFg=true
        Bindings:
        * IntentBindRecord{15a05e8f CREATE}:
          intent={cmp=com.example.elson/.service.TraceService}
          binder=android.os.BinderProxy@3b2051c
          requested=true received=true hasBound=true doRebind=false
          * Client AppBindRecord{2002e525 ProcessRecord{28c2ccfc 29108:com.example.elson/u0a94}}
            Per-process Connections:
              ConnectionRecord{17743edb u0 CR com.example.elson/.service.TraceService:@394a7bea}
        All Connections:
          ConnectionRecord{17743edb u0 CR com.example.elson/.service.TraceService:@394a7bea}
    
      * ServiceRecord {236dedb7 u0 com.example.elson/com.baidu.trace.LBSTraceService}
        intent={cmp=com.example.elson/com.baidu.trace.LBSTraceService}
        packageName=com.example.elson
        processName=com.example.elson:remote
        baseDir=/data/app/com.example.elson-2/base.apk
        dataDir=/data/data/com.example.elson
        app=ProcessRecord{26ceb390 30976:com.example.elson:remote/u0a94}
        createTime=-35s7ms startingBgTimeout=--
        lastActivity=-34s954ms restartTime=-34s954ms createdFromFg=true
        startRequested=true delayedStop=false stopIfKilled=false callStart=true lastStartId=2
        Bindings:
        * IntentBindRecord{22ab06fa CREATE}:
          intent={cmp=com.example.elson/com.baidu.trace.LBSTraceService}
          binder=android.os.BinderProxy@3e4e54ab
          requested=true received=true hasBound=true doRebind=false
          * Client AppBindRecord{c685708 ProcessRecord{28c2ccfc 29108:com.example.elson/u0a94}}
            Per-process Connections:
              ConnectionRecord{eb457d5 u0 CR com.example.elson/com.baidu.trace.LBSTraceService:@140b05bf}
              ConnectionRecord{152bd48c u0 CR com.example.elson/com.baidu.trace.LBSTraceService:@140b05bf}
        All Connections:
          ConnectionRecord{152bd48c u0 CR com.example.elson/com.baidu.trace.LBSTraceService:@140b05bf}
          ConnectionRecord{eb457d5 u0 CR com.example.elson/com.baidu.trace.LBSTraceService:@140b05bf}
    
      Connection bindings to services:
      * ConnectionRecord{152bd48c u0 CR com.example.elson/com.baidu.trace.LBSTraceService:@140b05bf}
        binding=AppBindRecord{c685708 com.example.elson/com.baidu.trace.LBSTraceService:com.example.elson}
        conn=android.os.BinderProxy@140b05bf flags=0x1
      * ConnectionRecord{eb457d5 u0 CR com.example.elson/com.baidu.trace.LBSTraceService:@140b05bf}
        binding=AppBindRecord{c685708 com.example.elson/com.baidu.trace.LBSTraceService:com.example.elson}
        conn=android.os.BinderProxy@140b05bf flags=0x1
      * ConnectionRecord{27eeb232 u0 CR com.example.elson/cn.jpush.android.service.PushService:@1d59da3d}
        binding=AppBindRecord{2e139ee com.example.elson/cn.jpush.android.service.PushService:com.example.elson:mult}
        conn=android.os.BinderProxy@1d59da3d flags=0x1
      * ConnectionRecord{17c85c8e u0 CR com.example.elson/cn.jpush.android.service.PushService:@32188489}
        binding=AppBindRecord{c3b39f0 com.example.elson/cn.jpush.android.service.PushService:com.example.elson:remote}
        conn=android.os.BinderProxy@32188489 flags=0x1
      * ConnectionRecord{17743edb u0 CR com.example.elson/.service.TraceService:@394a7bea}
        binding=AppBindRecord{2002e525 com.example.elson/.service.TraceService:com.example.elson}
        activity=ActivityRecord{10f6021d u0 com.example.elson/.ui.home.TraceActivity t577}
        conn=android.os.BinderProxy@394a7bea flags=0x1
      * ConnectionRecord{2a89c1da u0 CR com.example.elson/cn.jpush.android.service.PushService:@3c4e3f85}
        binding=AppBindRecord{7efb69 com.example.elson/cn.jpush.android.service.PushService:com.example.elson}
        conn=android.os.BinderProxy@3c4e3f85 flags=0x1
    
  13. 获取你指定的进程信息:ps | grep PackageName

  14. 查看优先级:cat /proc/进程ID/oom_adj(步骤3,4合用)

不太常用的命令

  1. 获取手机磁盘空间
    adb shell df
  2. 获取手机系统版本
    adb shell getprop ro.build.version.release
  3. Memory Use Over Time
    adb shell dumpsys procstats
  4. Graphics State
    adb shell dumpsys gfxinfo
  5. 查看adb版本
    adb version
  6. 进入adb帮助界面
    adb help

参考

  1. ADB Shell Commands(官方文档)
  2. Reading and Writing Logs(官方文档)
  3. Activity的正确打开方式
  4. 那些必须知道的ADB命令
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值