12

I need a specific command line tool and I have made a C program in my Linux shell. I have compiled the program with an ARM cross-compiler. I have then moved the program into the Android file system and tried to run it.

The output is permission denied.

What do I have to do, in order to run my own compiled programs in Android file system?

14

I assume that you used adb push for uploading your executable to the sd-card. Unfortunately the sd-card is always mounted with "noexec" which means that you can't execute anything from here.

Therefore you have to copy the executable to the local filesystem, e.g. to /data/local. In case the device is not rooted or you don't have BusyBox installed there will be no "cp" command. You can simply use cat: cat /sdcard/myprog > /data/local/myprog.

Then you have to set the executable permission on the executable. Chmod on android usually does not support the "u+x" syntax. Therefore you have to call chmod 555 /data/local/myprog.

Afterwards you can execute your executable: /data/local/myprog.

  • Thx for your reply. In fact the problem was on the binary generation. It was not being generated correctely! ;) – Nuno Santos May 27 '13 at 9:43
  • I have busybox on my device, but this command: shell@n200C:/ $ busybox cp /storage/external_storage/sda1/ffmpeg /data/ ------ show error= cp: can't create '/data/ffmpeg': Permission denied – Dr.jacky Nov 16 '15 at 13:58
  • tmp-mksh: /data/local/workspace/clang+llvm-5.0.0-aarch64-linux-gnu/bin/clang++: No such file or directory though the file is present – Necktwi Mar 8 '18 at 15:59
7

First, you have to push it into a directory, such as /data/local/tmp. Then, you have to set permission for that using chmod 755 executable. After that, you can run it as ./executable.

Complete steps are as follows:

adb push executable /data/local/tmp
adb shell
cd /data/local/tmp
chmod 755 executable
./executable

Alternatively, if you want to run it from your asset folder, you have to copy the file to your data folder /data/data/packagename/. Then using File class, set the setExecutable flag to true for the file and run it by the Process class or third party packages like Root Tools .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.