您现在的位置是:首页 > 编程 > 

android shell 安装 apk,使用 adb shell 和 pm 安装 apk 包到安卓手机

2025-07-17 23:36:49
使用 adb shell 和 pm 安装 apk 包到安卓手机安装好 Android Studio 之后,adb 一般是在 /Users/exchen/Library/Android/sdk/platform-tools 目录设置好环境变量或者切换到 adb 所在的目录,执行 adb devices 查看本机连接的设备,命令如下:./adb

使用 adb shell 和 pm 安装 apk 包到安卓手机

安装好 Android Studio 之后,adb 一般是在 /Users/exchen/Library/Android/sdk/platform-tools 目录

设置好环境变量或者切换到 adb 所在的目录,执行 adb devices 查看本机连接的设备,命令如下:

./adb devices

List of devices attached

012456789ABCDEF device

emulator-5554 device

1

2

4

5

./adbdevices

Listofdevicesattached

012456789ABCDEFdevice

emulator-5554device

可以看到上面的信息显示连接了两台设备,一个是真机,一个是模拟器,由于有两台设备执行操作时需要指定目标设备,比如安装 apk,命令如下:

./adb -s 012456789ABCDEF install ~/Downloads/test.apk

Performing Push Install

adb: error: failed to copy /Users/exchen/Downloads/test.apk to /data/local/tmp/test.apk : couldn t read from device

/Users/momo/Downloads/test.apk: 0 files pushed. 92.5 MB/s (11056 bytes in 0.001s)

1

2

4

5

./adb-s012456789ABCDEFinstall~/Downloads/test.apk

PerformingPushInstall

adb:error:failedtocopy /Users/exchen/Downloads/test.apk to /data/local/tmp/test.apk :couldn treadfromdevice

/Users/momo/Downloads/test.apk:0filespushed.92.5MB/s(11056bytesin0.001s)

此时我们看到安装失败,原因是上传 apk 包到 /data/local/tmp/ 目录失败,执行 adb shell,尝试执行 chmod 赋予权限,但是提示拒绝访问,信息如下:

./adb -s 012456789ABCDEF shell

shell@Coolpad567:/ $ chmod -R 755 data

Unable to chmod data: Permission denied

1

2

4

./adb-s012456789ABCDEFshell

shell@Coolpad567:/$chmod-R755data

Unabletochmoddata:Permissiondenied

没办法,看样子这个目录是没权限读写,尝试将 test.apk 推送到 SD 卡,命令如下:

./adb -s 012456789ABCDEF push ~/Downloads/test.apk /sdcard

1

2

./adb-s012456789ABCDEFpush~/Downloads/test.apk/sdcard

推送成功,SD 卡是有读写权限的,在手机上尝试用文件管理点击安装,但是安装的按钮是灰的,不能点击。最后尝试使用 pm 命令进行安装,命令如下:

./adb shell

shell@Coolpad567:/ chmod 755 /sdcard/test.apk

shell@Coolpad567:/ $ pm install -f /sdcard/test.apk

pkg: /sdcard/test.apk

Success

1

2

4

5

6

./adbshell

shell@Coolpad567:/chmod755/sdcard/test.apk

shell@Coolpad567:/$pminstall-f/sdcard/test.apk

pkg:/sdcard/test.apk

Success

终于成功。

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/biancheng/1109901.html

相关标签:无
上传时间: 2025-07-16 18:32:28
留言与评论(共有 13 条评论)
本站网友 择泰
22分钟前 发表
Permission denied124./adb-s012456789ABCDEFshellshell@Coolpad567
本站网友 农业物联网
4分钟前 发表
/ $ chmod -R 755 dataUnable to chmod data
本站网友 智商105
17分钟前 发表
couldn treadfromdevice/Users/momo/Downloads/test.apk
本站网友 统计用区划代码
18分钟前 发表
0 files pushed. 92.5 MB/s (11056 bytes in 0.001s)1245./adb-s012456789ABCDEFinstall~/Downloads/test.apkPerformingPushInstalladb
本站网友 封闭减肥夏令营
15分钟前 发表
使用 adb shell 和 pm 安装 apk 包到安卓手机安装好 Android Studio 之后,adb 一般是在 /Users/exchen/Library/Android/sdk/platform-tools 目录设置好环境变量或者切换到 adb 所在的目录,执行 adb devices 查看本机连接的设备,命令如下:./adb devicesList of devices attached012456789ABCDEF deviceemulator-5554 device1245./adbdevicesListofdevicesattached012456789ABCDEFdeviceemulator-5554device可以看到上面的信息显示连接了两台设备,一个是真机,一个是模拟器,由于有两台设备执行操作时需要指定目标设备,比如安装 apk,命令如下:./adb -s 012456789ABCDEF install ~/Downloads/test.apkPerforming Push Installadb
本站网友 苹果园小区
11分钟前 发表
0 files pushed. 92.5 MB/s (11056 bytes in 0.001s)1245./adb-s012456789ABCDEFinstall~/Downloads/test.apkPerformingPushInstalladb
本站网友 歌丽姿
23分钟前 发表
/$chmod-R755dataUnabletochmoddata
本站网友 许家印座驾
28分钟前 发表
error
本站网友 聊破
3分钟前 发表
/$chmod-R755dataUnabletochmoddata
本站网友 气海
7分钟前 发表
/$chmod-R755dataUnabletochmoddata
本站网友 南京人才市场招聘会
10分钟前 发表
/$pminstall-f/sdcard/test.apkpkg
本站网友 广州最新楼盘
16分钟前 发表
/ chmod 755 /sdcard/test.apkshell@Coolpad567