Search code examples
javaandroidbinaryshellexecute

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


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?


Solution

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