Adb安装失败:INSTALL_CANCELED_BY_USER

115

我尝试通过adb安装应用程序,但出现错误:

$ ./adb -d install /Users/dimon/Projects/one-place/myprogram/platforms/android/build/outputs/apk/android-debug.apk -r -g
3704 KB/s (4595985 bytes in 1.211s)
    pkg: /data/local/tmp/android-debug.apk
Failure [INSTALL_CANCELED_BY_USER]

此时设备上没有任何操作。设备为小米MI5,MIUI版本为7.2.13,安卓版本为6.0。已启用开发者模式。如何解决?

运行“ionic run android”命令时出现相同的错误。

更新:

这是从‘adb logcat’命令中在程序安装时获取的日志记录:

06-06 10:04:20.051   788   903 I DisplayFeatureService: void android::update_watchlist(const prop_info*, void*): sys.boot_completed: 1
06-06 10:04:20.063   788   903 I DisplayFeatureService: void android::update_watchlist(const prop_info*, void*): sys.boot_completed: 1
06-06 10:04:20.078 13397 13397 E ANDR-PERF-MPCTL: Unable to create control service (stage=2, rc=-1)
06-06 10:04:20.082   788   903 I DisplayFeatureService: void android::update_watchlist(const prop_info*, void*): sys.boot_completed: 1
06-06 10:04:20.079 13396 13396 W iop     : type=1400 audit(0.0:527): avc: denied { write } for name="socket" dev="tmpfs" ino=14686 scontext=u:r:dumpstate:s0 tcontext=u:object_r:socket_device:s0 tclass=dir permissive=0
06-06 10:04:20.088   788   903 I DisplayFeatureService: void android::update_watchlist(const prop_info*, void*): sys.boot_completed: 1
06-06 10:04:20.926 13400 13400 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 2000 <<<<<<
06-06 10:04:20.930 13400 13400 D AndroidRuntime: CheckJNI is OFF
06-06 10:04:20.966 13400 13400 D ICU     : No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
06-06 10:04:20.995 13400 13400 I Radio-JNI: register_android_hardware_Radio DONE
06-06 10:04:21.004 13400 13400 E         : WFDWhiteListing : library initialized successfully
06-06 10:04:21.020 13400 13400 D AndroidRuntime: Calling main entry com.android.commands.pm.Pm
06-06 10:04:21.027 13400 13400 I Timeline: Timeline: Activity_launch_request time:973226
06-06 10:04:21.028  1497  2996 I ActivityManager: START u0 {act=android.intent.action.VIEW dat=file:///data/local/tmp/android-debug.apk typ=application/vnd.android.package-archive flg=0x18000000 cmp=com.miui.securitycenter/com.miui.permcenter.install.AdbInstallActivity (has extras)} from uid 2000 on display 0
06-06 10:04:21.033  1497  2996 E         : WFDMMServiceClient ctor Context = 0x0, Cb = 0x0
06-06 10:04:21.033  1497  2996 E         : getWFDMMServiceInstance get new Instance
06-06 10:04:21.033  1497  2996 E         : Service not available yet
06-06 10:04:21.034  1497  2996 E         : WFDMMServiceClient::~WFDMMServiceClient
06-06 10:04:21.037  1497  2996 E         : WFDMMServiceClient ctor Context = 0x0, Cb = 0x0
06-06 10:04:21.037  1497  2996 E         : getWFDMMServiceInstance get new Instance
06-06 10:04:21.037  1497  2996 E         : Service not available yet
06-06 10:04:21.037  1497  2996 E         : WFDMMServiceClient::~WFDMMServiceClient
06-06 10:04:21.050  2875  3077 D PowerKeeperEventLogManager: notifyForegroundCompomentChanged ComponentInfo{com.miui.securitycenter/com.miui.permcenter.install.AdbInstallActivity}
06-06 10:04:21.051  2875  3036 D PowerKeeperExecutor: notify state normal_state enter...
06-06 10:04:21.051  2875  3036 D PowerKeeperExecutor: foreground_change:
06-06 10:04:21.051  2875  3036 D PowerKeeperExecutor: set_cpu_powermode(middle)
06-06 10:04:21.051  2875  3036 I PowerKeeperExecutor: no local quick execution method for set_cpu_powermode
06-06 10:04:21.051  2875  3036 D PowerKeeperExecutor: set_lcd_mode(ui)
06-06 10:04:21.051  2875  3036 I PowerKeeperExecutor: no local quick execution method for set_lcd_mode
06-06 10:04:21.049  2887  2887 W EventReader: type=1400 audit(0.0:528): avc: denied { search } for name="756" dev="proc" ino=16099 scontext=u:r:system_app:s0 tcontext=u:r:zygote:s0 tclass=dir permissive=0
06-06 10:04:21.049  2887  2887 W EventReader: type=1400 audit(0.0:529): avc: denied { search } for name="756" dev="proc" ino=16099 scontext=u:r:system_app:s0 tcontext=u:r:zygote:s0 tclass=dir permissive=0
06-06 10:04:21.051  3247  4440 I octvm_power: power mode [normal] start 1465200261
06-06 10:04:21.051  3247  4440 I octvm_power: Action: set_cpu_powermode(middle) for [foreground_change]
06-06 10:04:21.051  3247  4440 I octvm_drv: common drv: platform_set_power_profile -> platform not support
06-06 10:04:21.051  2533  2887 I octvm   : task pid 2113 have been add to group sys_standby.
06-06 10:04:21.051  3247  4440 I octvm_power: Action: set_lcd_mode(ui) for [foreground_change]
06-06 10:04:21.051  3247  4440 I octvm_drv: common drv: platform_set_lcd_mode -> platform not support
06-06 10:04:21.051  2533  2887 I octvm   : task pid 2900 have been add to group sys_standby.
06-06 10:04:21.049  2887  2887 W EventReader: type=1400 audit(0.0:530): avc: denied { search } for name="756" dev="proc" ino=16099 scontext=u:r:system_app:s0 tcontext=u:r:zygote:s0 tclass=dir permissive=0
06-06 10:04:21.051  2533  2887 I octvm   : task pid 4553 have been add to group sys_standby.
06-06 10:04:21.051  2533  2887 I octvm   : [sys_standby]cgroup_add_tasks max single write time: 0ms
06-06 10:04:21.051  2533  2887 I octvm   : [sys_standby]cgroup_add_tasks total time consume: 0ms
06-06 10:04:21.051  3247  4440 I octvm_power: onPowerModeChanged[normal] called
06-06 10:04:21.052  2875  3093 I FirstNotificationController: handleUnlockState: stoped
06-06 10:04:21.055  1497  2996 I Timeline: Timeline: App_transition_ready time:973254
06-06 10:04:21.055  1976  1976 V PhoneStatusBarPolicy: updateManagedProfile: mManagedProfileFocused: false mKeyguardVisible: true
06-06 10:04:21.055  1497  2996 I Timeline: Timeline: App_transition_stopped time:973255
06-06 10:04:21.059  1497  2996 E ActivityManager: Invalid thumbnail dimensions: 0x0
06-06 10:04:21.059  4553  4553 W .securitycenter: type=1400 audit(0.0:531): avc: denied { search } for name="tmp" dev="dm-0" ino=28 scontext=u:r:system_app:s0 tcontext=u:object_r:shell_data_file:s0 tclass=dir permissive=0
06-06 10:04:21.066  4553  4553 W asset   : Asset path /data/local/tmp/android-debug.apk is neither a directory nor file (type=0).
06-06 10:04:21.066  4553  4553 D AdbInstallActivity:  parsePackage is null , path :/data/local/tmp/android-debug.apk
06-06 10:04:21.059  4553  4553 W .securitycenter: type=1400 audit(0.0:532): avc: denied { search } for name="tmp" dev="dm-0" ino=28 scontext=u:r:system_app:s0 tcontext=u:object_r:shell_data_file:s0 tclass=dir permissive=0
06-06 10:04:21.072  1497  2230 E         : WFDMMServiceClient ctor Context = 0x0, Cb = 0x0
06-06 10:04:21.072  1497  2230 E         : getWFDMMServiceInstance get new Instance
06-06 10:04:21.072  1497  2230 E         : Service not available yet
06-06 10:04:21.072  1497  2230 E         : WFDMMServiceClient::~WFDMMServiceClient
06-06 10:04:21.073  1497  2230 E         : WFDMMServiceClient ctor Context = 0x0, Cb = 0x0
06-06 10:04:21.073  1497  2230 E         : getWFDMMServiceInstance get new Instance
06-06 10:04:21.073  1497  2230 E         : Service not available yet
06-06 10:04:21.073  1497  2230 E         : WFDMMServiceClient::~WFDMMServiceClient
06-06 10:04:21.075  1497  2230 E ActivityManager: Invalid thumbnail dimensions: 0x0
06-06 10:04:21.076  2875  3077 D PowerKeeperEventLogManager: notifyForegroundCompomentChanged ComponentInfo{com.android.settings/com.android.settings.Settings$WifiSettingsActivity}
06-06 10:04:21.069  2887  2887 W EventReader: type=1400 audit(0.0:533): avc: denied { search } for name="756" dev="proc" ino=16099 scontext=u:r:system_app:s0 tcontext=u:r:zygote:s0 tclass=dir permissive=0
06-06 10:04:21.076  1497  2230 I Timeline: Timeline: App_transition_ready time:973275
06-06 10:04:21.076  1497  2230 I Timeline: Timeline: App_transition_stopped time:973275
06-06 10:04:21.076  2533  2887 I octvm   : task pid 2060 have been add to group sys_standby.
06-06 10:04:21.076  2533  2887 I octvm   : [sys_standby]cgroup_add_tasks max single write time: 0ms
06-06 10:04:21.076  2533  2887 I octvm   : [sys_standby]cgroup_add_tasks total time consume: 0ms
06-06 10:04:21.077  1976  1976 V PhoneStatusBarPolicy: updateManagedProfile: mManagedProfileFocused: false mKeyguardVisible: true
06-06 10:04:21.090 13400 13400 I art     : System.exit called, status: 1
06-06 10:04:21.090 13400 13400 I AndroidRuntime: VM exiting with result code 1.
06-06 10:04:21.100  2060  2130 V MI_STAT : disabled local event upload

我看到android-debug.apk被创建了,但我不明白为什么它没有安装。也许关键字符串是:

06-06 10:04:21.066  4553  4553 W asset   : Asset path /data/local/tmp/android-debug.apk is neither a directory nor file (type=0).
06-06 10:04:21.066  4553  4553 D AdbInstallActivity:  parsePackage is null , path :/data/local/tmp/android-debug.apk

但这不是错误字符串,只是警告和调试。 此外还有一行奇怪的代码:

06-06 10:04:21.059  1497  2996 E ActivityManager: Invalid thumbnail dimensions: 0x0

但我不知道这是否是一个问题。

此外,我还尝试通过adb安装一些其他应用程序,而不仅仅是自己编写的应用程序。但没有任何结果。


1
你的手机上已经安装了这个应用吗?如果是的话,请先卸载,然后再试一次。另一个选项是使用 adb install -r /path/to/apk/file.apk 命令,它会在应用已经存在的情况下覆盖安装。 - KhoPhi
我尝试卸载它,并尝试使用adb install -r,但这并没有帮助我。 - Dmitry Skryabin
你能解决这个问题吗? - gaurav jain
1
你好,Dmitry Skryabin,我有同样的手机,并且遇到了和你一样的问题。我无法在手机上进行adb安装。未知来源已经打开,我可以从存储中将应用程序安装到设备上,但是我无法从Android Studio或Xamarin调试应用程序。我感觉这是一个操作系统/小米Mi5的问题。我打算前往小米论坛询问同样的问题。 - Yudhistre
@Yudhistre,感谢您的评论。我已经暂时切换到iPhone模拟器上进行调试,这对我的目的来说已经足够了。 - Dmitry Skryabin
仍然不能证明我们没有在我们的新Mi5设备上部署和调试的能力。 - Yudhistre
23个回答

331

这个设备出现了同样的问题。

所以,这是小米手机的问题,以下是解决该问题的方法:

  1. 进入“安全”应用程序,点击右上角的“选项”

  2. 向下滚动到“功能设置”组,找到“权限”

  3. 在那里关闭“通过 USB 安装”选项,该选项管理通过 USB 安装应用程序并不允许它。

对于最新的红米设备

设置 > 其他设置 > 开发者选项 > 开发者选项: 勾选“通过 USB 安装”选项。


2
是的,它有效!其他用户提示:在俄语语言中(来自xiaomi.eu固件),此参数名为“Менеджер установки”。 - Dmitry Skryabin
11
安全应用程序的新版本不再有该选项。Victor Lopez 的答案对我有用。 - Ray
10
最近更新后,除非您登录小米帐户,否则无法通过 USB 安装软件。这太疯狂了!有没有办法绕过这个荒谬的功能? - NIPHIN
8
这确实有些令人惊讶,需要一张SIM卡才能启用这个功能。唉! - Sreekanth Karumanaghat
1
好好知道:千万别买红米! - Manuela
显示剩余7条评论

89

在小米设备中遇到同样的问题,并通过以下步骤解决:

1)进入设置

2)点击其他设置

3)点击开发者选项

4)打开通过 USB 安装的开关

问题将得到解决。

enter image description here


6
当我启动通过 USB 安装时,它会要求登录 MI 帐户。我该如何跳过这一步骤? - Chandrakanth
6
@Chandrakanth,您需要登录您的小米账户,很遗憾您无法跳过此步骤。 - Kapil Rajput
此菜单项在Note 4上不存在。 - Martin Erlic
5
当我尝试这样做时,它显示“此设备暂时受限制”,有什么建议吗? - Shailendra Madda
3
还有红米Note 4显示“插入SIM卡”,不知道为什么它需要SIM卡。 - Shashank Kumar
显示剩余3条评论

54

在MIUI 8中,前往开发人员选项并切换“通过USB安装”以启用它。


4
同时,它要求使用MIUI账户来启用“通过USB安装”设置。 - Shashanth
我已经启用了MIUI账户,但仍然无法启用“通过USB安装”。 - Innocent
1
解决方案:如果您在启用“通过USB安装”时遇到问题,只需断开与WiFi的连接并将其启用。它会正常工作! - Akira Kronic

30

对于红米和小米设备,请关闭MIUI优化。

设置 > 其他设置 > 开发者选项 > MIUI 优化


哇,我真的很讨厌MIUI操作系统,这是“善意的道路铺满了地狱”的一个例子。这个“MIUI优化”浪费了我太多的时间。谢谢。 - Rami Loiferman
如果您禁用了提到的选项,就不需要启用“通过USB安装应用程序”选项并登录小米帐户 - adb安装“只需运行”。非常感谢您的建议! - Mateusz Falkowski

15

针对小米设备的安装教程

1) 设置

2) 其他设置

3) 开发者选项

4) 通过 USB 安装:打开切换按钮

这个方法对我来说很有效。

注意:如果不行,可以尝试以下几个方法

1) 登录小米账户(不适用于所有设备)

2) 在设置->其他设置->开发者选项中禁用打开MIUI优化,这个选项在底部附近。

3) 必须启用开发者选项, 如何启用开发者选项:请参考此处说明

仍然无效?

-> 退出Mi帐户,然后创建新帐户并启用USB调试。

谢谢


2
禁用打开MIUI优化让我可以跳过登录小米帐户步骤,虽然我仍然无法启用通过USB安装设置,但这已经不再必要了,adb install就可以使用。谢谢! - Marchyello

10

问题似乎出在Instant Run功能上。前往"文件 -> 设置 -> 构建、执行、部署 -> Instant Run",然后将其禁用即可。

如果上述答案无效,则希望这个方法有效。


适用于我的小米 MI6。 - FunkSoulBrother

10

1 设置

2 其他设置

3 开发者选项

4 开发者选项:勾选“通过 USB 安装”选项。

在此输入图片描述


7

关闭开发者选项中的MIUI优化,然后重启手机。

我尝试了这种方法,可行。

设置 > 其他设置 > 开发者选项 > MIUI 优化


6
我之前也遇到过同样的问题,以下是我的解决方案:
  1. 打开设置 → 在系统中找到开发者选项并点击。
  2. 在调试部分打开通过 USB 安装
  3. 再次尝试在 Android Studio 中运行应用程序

4

我尝试了上述所有步骤,但都失败了。

比如,使用数据连接连接互联网关闭MIUI优化并重新启动、从安全设置中打开通过USB安装等。

然后我找到了一个解决方案。

步骤:

  • 安装PlexVPN
  • 设置中国-上海服务器
  • 尝试从开发人员选项中打开通过USB安装

就这样。


除非需要在应用程序中执行此操作。 - egorikem

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接