1

When I use

adb shell "run-as com.example.myapplication push C:\\Users\\x00879271\\Desktop\\ttest /data/data/com.example.myapplication"

I get

run-as: exec failed for push: Permission denied.

And I can drag the 'ttest' folder to /data/data/com.example.myapplication using Android Studio.

So the question is:

  • How does the Android Studio transfer a folder to the device?
  • Or how should I transfer a folder to /data/data/com.example.myapplication without using root?
0

1 Answer 1

3

Let's take a close look onto the command you have executed:

adb shell "run-as com.example.myapplication push C:\\Users\\x00879271\\Desktop\\ttest /data/data/com.example.myapplication"

The main problem is the adb shell part at the beginning. With this command you open up a shell on the Android device. Everything after adb shell is executed on your Android device. Therefore specifying a path like C:\\Users\\x00879271\\Desktop\\ttest which refers to a file on your PC won't work because it is executed on Android which doesn't have access to files on your PC.

If you want to push a file and use run-as you can not do this in one command. Split it into multiple commands:

  1. Push the file to a common directory: adb push C:\\Users\\x00879271\\Desktop\\ttest /sdcard/

  2. Copy the file to into the app directory adb shell run-as com.example.app sh -c 'cp /sdcard/ttest /data/data/com.example.myapplication/'

The above command requires the cp command to be present on your device. On older devices it is missing which requires you to use a workaround using cat: 'cat /sdcard/ttest > /data/data/com.example.myapplication/ttest' for the last part of the command.

If you are interested what commands Android Studio performs when uploading an file e.g. in Device Explorer please see my answer here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .