Error running exec(). Command: Working Directory: null Environment: null - how to execute a binary in Android correctly on a non-rooted device?

user2212461 picture user2212461 · Feb 21, 2015 · Viewed 9.5k times · Source

I want to run an executable on a non-rooted android device.

Using the following commands in java

Runtime.getRuntime().exec("/bin/chmod 744 /data/data/com.example.myapp/myBin");
Runtime.getRuntime().exec("/data/data/com.example.myapp/myBin");

results in

Error running exec(). Command: [/data/data/com.example.myapp/myBin] 
    Working Directory: null Environment: null

I found alot of questions on this but no answer that worked in my case. How can I execute the binary file correctly?

Answer

Shashank Singla picture Shashank Singla · Mar 2, 2015

If you are running this from a service (and not a app activity), you will have to set the permissions as 777.