更新记录
1.0.4(2025-07-23)
新增获取远程设备的IMEI 新增拉取远程设备的截图
1.0.3(2025-07-10)
修复adb install
1.0.2(2025-07-05)
- 修复本机热点下无法获取局域网IP
- 修改adb connect是否连接成功逻辑
平台兼容性
云端兼容性
阿里云 | 腾讯云 | 支付宝云 |
---|---|---|
√ | √ | √ |
uni-app(4.71)
Vue2 | Vue2插件版本 | Vue3 | Vue2插件版本 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|---|---|
√ | 1.0.0 | √ | 1.0.0 | × | × | × | × | × | × | × |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | × | × | × | × | × |
uni-app x(4.71)
Chrome | Safari | Android | Android插件版本 | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|---|
× | × | 5.0 | 1.0.0 | × | × | × |
acwy-adb
注意事项
因三方库问题,需要在manifest.json
的源码里添加packagingOptions
详见[packagingOptions配置](https://doc.dcloud.net.cn/uni-app-x/collocation/manifest-android.html#packagingoptions)
"android": {
"packagingOptions": [
"exclude 'META-INF/LICENSE.md'",
"exclude 'META-INF/LICENSE-notice.md'"
]
}
引入
引入1: 每个页面都new一个实例,不共享连接状态
import { Adb } from '@/uni_modules/acwy-adb'
初始化:在 uvue data 里初始化一个 classAdb: new Adb()
引入2: 所有页面共享一个连接状态
在store/index.uts里new一个Adb(),所有页面引入就可以了,其中一个页面connect其他页面也共享此状态
// store/index.uts
import { Adb } from '@/uni_modules/acwy-adb'
export const classAdb = new Adb();
import { classAdb } from '@/store'
方法
getWifiIp
/**
* @description getWifiIp 获取本机IP,WIFI未连接返回''
* @returns Promise<string> ip
*/
classAdb.getWifiIp().then(ip=>{
// ip
}).catch(err=>{
// ''
})
scan
/**
* @description scan 扫描 IP:端口
* @param ip string ipv4
* @returns Promise<boolean> true/false
*/
classAdb.scan(ip, port=5555, timeout=1000).then((res: boolean)=>{
// true
}).catch(err=>{
// false
})
scanAll
/**
* @description scanAll 扫描指定IP所在网段1-255的IP:端口,无需处理IP
* @param ip string ipv4
* @returns Promise<string[]> 返回开放指定端口的所有IP
*/
classAdb.scanAll(ip : string, port : number = 5555, timeout : number = 300)
connect
/**
* @description connect 连接指定IP,后续命令必须先连接成功才能执行
* @param ip string ipv4
* @returns Promise<boolean> true/false
*/
classAdb.connect(ip : string)
exec
/**
* @description exec 对目标安卓设备执行adb shell命令
* @param command string shell命令,比如am pm和其他命令
* @returns Promise<string> 执行成功结果/错误信息
*/
classAdb.exec(command : string)
install
/**
* @description 安装指定路径的apk到目标安卓设备
* @param apkPath string apk真实路径,比如下载的res.tempFilePath或者UTSAndroid.convert2AbsFullPath()
* @param mode string adb安装模式,-r -g等,可自行搜索
* @returns Promise<string> true/false
*/
classAdb.install(apkPath: string, mode: string[]=['-r', '-g'])
uninstall
/**
* @description 卸载目标安卓设备APP
* @param packageName string apk包名
* @returns Promise<string> true/false
*/
uninstall(packageName: string)
classAdb.uninstall(packageName: string)
pushFile
/**
* @description 推送文件到目标设备
* @param localPath string 本机文件路径
* @param remotePath string 目标设备存放文件的路径
* @returns Promise<string> true/false
*/
classAdb.pushFile(localPath: string, remotePath: string)
pullFile
/**
* @description 拉取目标设备的文件(中文路径的文件无法拉取,求解决)
* @param remotePath string 目标设备存放文件的路径
* @param localPath string 拉取文件存放到本机的路径
* @returns Promise<string> true/false
*/
classAdb.pullFile(remotePath: string, localPath: string)
screen
/**
* @description ADB截图
* 本机保存目录和远程设备临时截图目录统一固定目录: /storage/emulated/0/download/acwy
* @returns Promise<string> 返回本机拉取的截图路径
*/
classAdb.screen()
getImei
/**
* @description ADB获取远程设备的IMEI
* @returns Promise<string> 远程设备的IMEI
*/
classAdb.getImei()