Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 11 adb push Permission denied

Tags:

android

adb

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">
like image 691
Shiv Buyya Avatar asked Jan 23 '21 05:01

Shiv Buyya


People also ask

How do I fix denied permission on ADB?

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 .


3 Answers

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 -> ?
like image 157
Symeon Chen Avatar answered Oct 19 '22 16:10

Symeon Chen


Try;

adb root

This will switch the adb server as root.

like image 26
Humpity Avatar answered Oct 19 '22 16:10

Humpity


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

like image 1
Afsar edrisy Avatar answered Oct 19 '22 15:10

Afsar edrisy