在Android U(14)上,对通过adb安装应用做了限制。默认的情况下,当执行以下命令的时候
adb install XXX.apk
会提示执行异常
Performing Streamed Install
adb: failed to install XXX.apk:
Exception occurred while executing 'install':
java.lang.SecurityException: Caller has no access to session -1
at com.android.server.pm.PackageInstallerService.openSessionInternal(PackageInstallerService.java:1067)
at com.android.server.pm.PackageInstallerService.openSession(PackageInstallerService.java:1041)
at com.android.server.pm.PackageManagerShellCommand.doWriteSplit(PackageManagerShellCommand.java:3935)
at com.android.server.pm.PackageManagerShellCommand.doWriteSplits(PackageManagerShellCommand.
可执行
adb shell settings get system adb_install_enabled
来查adb_install_enabled字段的值,应该为0。说明此时系统禁止通过adb来安装应用。
有两种解决方法:
- 打开开发者选项(如果不会,请自行百度),然后在找到“USB安装” 开关并打开(如果没有登录账号,会跳转到登录界面进行登录)
- 第二种方法比较简单。直接执行adb命令修改adb_install_enabled字段的值
adb shell settings put system adb_install_enabled 1
由于第一种方法需要先登陆账号,比较繁琐。所以推荐第二种方法。