1. android platform-tools下载
1.1 下载路径
https://developer.android.com/studio/releases/platform-tools.html 如图:
解压后得到:
1.2 添加环境变量
打开“我的电脑”—》属性—》系统高级设置—》环境变量—》编辑Path变量,将Android platform-tools路径添加到系统环境变量里。
2. root 手机
步骤略;因为可执行文件需要运行在手机的系统目录,SD卡目录无可执行权限。
3. 可执行文件的测试
前提环境:
(1)电脑端安装对应手机的USB驱动。
(2)用USB连接andorid手机和电脑,并且打开手机的开发人员选项-》USB调试选项;
3.1 测试命令
(1) adb start-server #用于启动adb服务
(2) adb push c:/h264dec /mnt/sdcard/ #将pc端二进制可执行文件h264dec拷贝到手机/mnt/sdcard目录下,因为不能直接将文件拷贝到手机系统目录下,如/data, /cache等。
(3) adb push c:/libh264dec.so /mnt/sdcard/ #如果二进制可执行文件链接的是动态库,必须将.so库拷贝到/system/lib目录下。
(4) adb shell # 进入命令界面,相当于远程登录到连接的android手机上,此时操作类似Linux系统,可用cp等指令。
(5) adb su #获取root权限,进入root用户。
(6) cp /mnt/sdcard/h264dec /cache #可执行文件必须放到手机系统目录下才能修改权限
(7) cp /mnt/sdcard/libh264dec.so /system/lib #动态库只有拷贝到这个目录下才能被链接。
(8) cd /cache
(9) chmod +x ./h264dec #增加可执行权限
(10) ./h264dec -i xxx.264 -o /mnt/sdcard/xxx.yuv #运行可执行文件
(11) adb pull /mnt/sdcard/xxx.yuv c:/ #导出文件到pc端
备注:可在root权限下,使用mkdir创建新文件夹。
(12) adb kill-server #用于结束adb服务
3.2 adb相关经验
(1)adb 服务端口为 5037
(2)adb 服务端口被其他应用程序占用且无法释放,可采用以下方法:
2.1、查看进程,然后kill相关进程(以下命令是在windows的cmd窗口操作)
2.1.1 使用 netstat -aoe | findstr "5037" 查找ID号 #列出的最后一项为占用5037端口的ID号,如ID号为2000;
2.1.2 以对应的进程ID号查找:tasklist | findstr "2000" #根据实际ID号查找
2.1.3 taskkill /f /t /im adb.ext #杀死该ID号对应的进程号
(3) adb shell 进入手机后,执行ps就能显示手机里所有正在运行的进程:
3.1、 ps命令参数:-t -x,-p,-P,-c [pid|name]
-t显示进程下的线程列表
-x 显示进程耗费的用户时间和系统时间,单位s
-P 显示调度策略,通过是bg or fg ,当获取失败将会un和er比之前打印的内容多出了一列PCY,表示进程的调度等级
Android进程调度状态:
1.foreground process
2.visible process
3.Service process
4.background process
5.empty process
-p 显示进程的优先级和nice等级
-c 显示进程耗费的CPU时间
[PID]过滤指定进程PID,[name]过滤指定进程NAME
3.2、ps执行之后各列数据的含义:
PID:进程号
PPID:父进程号
VSIZE :进程的虚拟内存大小
RSS :进程分配到的屋里内存大小
WCHAN:程正在睡眠的内核函数名称;该函数的名称是从/root/system.map文件中获得的。
NAME :进程名
3.3、 查找具体程序如xxxxx所占的进程号
ps | grep "xxxxx"
3.4、 kill 掉某具体的进程号如xxxxID
kill -s 9 xxxxID
备注: gdb 设置源文件查找路径:dir 指令: https://wizardforcel.gitbooks.io/100-gdb-tips/content/directory.html
参考网址:https://stackoverflow.com/questions/15162276/android-executing-a-program-on-adb-shell
参考网址:https://developer.android.com/studio/command-line/adb?hl=zh-cn
参考网址:https://stackoverflow.com/questions/38495426/how-to-open-adb-shell-and-execute-commands-inside-shell-using-python
参考网址:https://stackoverflow.com/questions/17334336/how-to-open-adb-and-use-it-to-send-commands
参考网址:https://stackoverflow.com/questions/7860874/execute-a-pure-binary-file-on-android
参考网址:https://stackoverflow.com/questions/8761992/launch-a-script-as-root-through-adb
参考网址:https://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp/44460975
可用eclipse模拟:
参考网址:https://stackoverflow.com/questions/14435032/how-to-create-jni-android-project-in-eclipse
http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/ http://blog.51cto.com/liuxp0827/1438625