【android】android真机测试方法

Date: 2018.9.30


本文转载自:https://blog.csdn.net/listener51/article/details/8286132

本文旨在介绍android真机测试方法,主要是用于测试自己开发的功能库在android真机运行。

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 服务端口被其他应用程序占用且无法释放,可采用以下方法:
      1、查看进程,然后kill相关进程
      2、使用 netstat -aoe | findstr "5037" 查找ID号  #列出的最后一项为占用5037端口的ID号,如ID号为2000;
      3、以对应的进程ID号查找:tasklist | findstr "2000" #根据实际ID号查找
      4 、taskkill /f /t /im adb.ext #杀死该ID号对应的进程号
 

参考网址: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

原文地址:https://www.cnblogs.com/SoaringLee/p/10532351.html