Android adb 命令

Android adb About 2,305 words

adb 官方网站

https://developer.android.google.cn/studio/command-line/adb.html

连接错误

adb shell error: no devices/emulators found

确定是否打开USB调试模式,kill后再启动。

adb kill-server
adb start-server

安装 apk 错误

adb install 报 Failure [INSTALL_FAILED_TEST_ONLY]

解决方法一

gradle.properties配置

android.injected.testOnly=false

解决方法二

adb install -t demo.apk

adb shell dumpsys

  • 显示设备序列号
adb devices
  • 多设备连接时,使用-s选择进入哪台设备
adb -s 2b321gj shell
  • 在真机调试时进入data/data/目录下,可查看databasesfilesp等文件夹,但是tab键不能提示
adb shell run-as com.example.addressdb
  • 把数据库从真机中pull出来
adb exec-out run-as com.example.addressdb cat databases/num.db > D:/number.db
  • 在真机调试时进入data/data/目录下,可查看databasesfilesp等文件夹,tab键能提示
adb shell

run-as com.example.addressdb
  • number.db变成-rwxrwxrwx
chmod 777 number.db
  • 列出详细信息
ls -l
  • cmd中查看log日志
adb logcat
  • 将日志重定向到电脑D盘目录下的log.txt文件
adb logcat > D:/log.txt
  • 获得设备分辨率
adb shell wm size
  • 获取手机CUP架构的指令
adb shell getprop ro.product.cpu.abi
  • cmd中查看进程
netstat -ano | findstr "5037"   

我的 第一行
显示PID  4280 

tasklist /fi "pid eq 4280"

taskkill /pid 4280
  • 查看手机信息
adb shell getprop
  • 应用程序中执行shell命令,可执行管道
//private static String[] cmd = new String[] {"sh", "-c" , "getprop | grep imei" };
private static String[] cmd = new String[] {"/system/bin/sh", "-c" , "" };
BufferedReader reader = null;
String content = "";
try {
    Process process = Runtime.getRuntime().exec(cmd);
    reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    StringBuffer output = new StringBuffer();
    int read;
    char[] buffer = new char[4096* 4096];
    while ((read = reader.read(buffer)) > 0) {
        output.append(buffer, 0, read);
    }
    reader.close();
    content = output.toString();
//Log.d("zbj", "onCreate: process.exitValue(): " + process.exitValue());
//Log.d("zbj", "onCreate: process.waitFor(): " + process.waitFor());
    Log.d("zbj", "onCreate: content: " + content);
} catch (Exception e) {
    Log.d("zbj", "onCreate: e: " + e.getMessage());
    e.printStackTrace();
}

//adb shell dumpsys iphonesubinfo 5.0一下查看imei
//service call iphonesubinfo 1 
  • 获取手机存储信息
adb shell df
adb shell df /data
adb shell df /sdcard
  • 获取手机mac地址
adb shell cat /sys/class/net/wlan0/address
  • 获取手机设备型号
adb -d shell getprop ro.product.model
  • 获取栈顶Activity
adb shell dumpsys activity | grep "mFocusedActivity"
Views: 5,498 · Posted: 2019-04-08

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh