我有一个基于博览会的反应本机应用程序,当我手机上只有个人资料时,它运行得很好。最近我还在我的三星 S20 上连接了“工作配置文件”,现在我无法开发我的个人应用程序。
我正在运行一个典型的博览会构建:
"scripts": {
"android": "expo run:android",
我设法通过运行以某种方式重现问题:
$ adb shell pm list packages
Exception occurred while executing 'list':
java.lang.SecurityException: Shell does not have permission to access user 10
com.android.server.am.ActivityManagerService.handleIncomingUser:14872 android.app.ActivityManager.handleIncomingUser:4802 com.android.server.pm.PackageManagerShellCommand.translateUserId:3499
at com.android.server.am.UserController.handleIncomingUser(UserController.java:2672)
确实 - 我现在有更多用户了:
Users:
UserInfo{0:MyUsername:c13} running
UserInfo{10:Work profile:1030} running
UserInfo{150:Secure Folder:10021030} running
然后我找到了解决方案
adb shell pm list packages --user 0
但我不知道如何向博览会构建提供此参数。请指教。
在命令行上假设您运行:
adb shell pm list users
其中列出了手机上的用户/个人资料... 我认为主用户是 0,但工作配置文件是另一个 #,它位于“Shell 无权访问用户 ###”错误消息中。
我在 github 问题上看到,您可以强制 adb shell 使用 0 零作为临时修复进行修复(直到 expo 修复其 cli 来处理工作配置文件): “在您的项目中,打开文件node_modules/@expo/cli/build/src/start/platforms/android/adb.js,并将 adbArgs 函数替换为:
function adbArgs(pid, ...options) {
const args = [];
if (pid) {
args.push("-s", pid);
}
// Add the --user param whenever Expo tries to call `adb shell pm list packages`
options = options.map(option => {
if (option === "packages") {
return "packages --user 0";
}
return option;
});
return args.concat(options);
}