I have upgraded OS from Android 10 to Android 11, when I try to run adb push test.txt /mnt/sdcard/
, I am getting an error adb: error: stat failed when trying to push to /mnt/sdcard/test.txt: Permission denied.
In AndroidManisfest.xml I have given all below permissions:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:requestLegacyExternalStorage="true">
The reason for "permission denied" is because your Android machine has not been correctly rooted. Did you see $ after you started adb shell ? If you correctly rooted your machine, you would have seen # instead. If you see the $ , try entering Super User mode by typing su .
Try adb push test.txt /sdcard/
, this will work.
On Android 11, we cannot access /mnt by ADB. But use the symlink is ok, see this link for details.
I run ls
command on the Android 11 emulator, we can see sdcard -> ?
within /mnt
, and sdcard -> /storage/self/primary
within /
, which means softlink /mnt/sdcard
is not working on Android 11.
# symeonchen @ SBook in ~ [22:16:05]
$ adb shell ls -al / | grep sdcard
lrw-r--r-- 1 root root 21 2020-12-17 02:01 sdcard -> /storage/self/primary
# symeonchen @ SBook in ~ [22:16:14]
$ adb shell ls -al /mnt | grep sdcard
l????????? ? ? ? ? ? sdcard -> ?
Try;
adb root
This will switch the adb server as root.
According to android doc.
Apps that run on Android 11 but target Android 10 (API level 29) can still request the requestLegacyExternalStorage attribute.
So try to change your target API level. Recommended way would be to use ContentResolver or can say Scoped storage instead of Legacy deprecated storage APIs.
Check out this for more details. Scoped storage enforcement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With