一些背景信息:我的手机使用的是android 9,并且是根目录的。
我正在尝试构建一个flutter android应用程序。当我执行flutter run
时,它失败了,错误如下:
❯ flutter run
adb shell failed to write the SHA hash: ProcessException: Process "/home/wscp/Android/Sdk/platform-tools/adb" exited abnormally:
/system/bin/sh: can't create /data/local/tmp/sky.com.example.test_app.sha1: Permission denied
Command: /home/wscp/Android/Sdk/platform-tools/adb -s da0d543 shell echo -n 75cf727e0e3b43efd656faf8cb2e4c779755b261 >
/data/local/tmp/sky.com.example.test_app.sha1.
Error launching application on Redmi Note 7.
当我尝试独立运行adb shell时,我发现无法访问/data/local/tmp
。
我能够执行以下操作,因为我已经在我的手机上扎根:
❯ adb shell
lavender:/ $ whoami
shell
lavender:/ $ ls -la /data/local/tmp
ls: /data/local/tmp: Permission denied
1|lavender:/ $ su
lavender:/ # ls -la /data/local/tmp
total 24
drwxrwxrwx 2 shell shell 4096 2019-10-25 10:23 . <====== !!!
drwxr-x--x 4 root root 4096 2019-10-12 16:29 ..
-rw-rw-rw- 1 root root 9726 2019-10-12 16:29 build.prop
-rw-rw-rw- 1 root root 968 2019-10-12 16:29 cmdline
目录/data/local/tmp
似乎属于shell,但shell本身无法访问该目录!
我还尝试使用scrcpy
工具,我已经在我的另一台设备上成功地使用了它,但它导致了类似的错误:
❯ scrcpy
INFO: scrcpy 1.11 <https://github.com/Genymobile/scrcpy>
adb: error: failed to copy '/usr/local/share/scrcpy/scrcpy-server' to '/data/local/tmp/scrcpy-server': remote couldn't create file: Permission denied
/usr/local/share/scrcpy/scrcpy-server: 0 files pushed. 2.0 MB/s (25454 bytes in 0.012s)
ERROR: "adb push" returned with value 1
为什么会发生这种情况,有什么解决办法吗?
发布于 2020-09-05 14:47:22
结果是一个selinux问题。我在flutter和scrcpy上也遇到了类似的问题。因此,我在网上四处寻找解决方案,并最终得到了这个要点,https://gist.github.com/AwaisKing/009a64d92d476da33036efd61c961a7a
诀窍是将selinux上下文从system_data_file重命名为shell_data_file,您将需要一个带根的android设备。对我有效的命令是,
chcon -R u:object_r:shell_data_file:s0 /data/local/tmp
https://stackoverflow.com/questions/59046671
复制相似问题