I have an Android application that is trying (and failing) to launch a native process using ProcessBuilder
. Here is what I have:
String[] args = {"/data/data/com.me.myapp/files/myexec", "param1", "param2"};
Process process = new ProcessBuilder(args)
.directory(new File("/data/data/com.me.myapp/files/somedir"))
.start();
process.waitFor();
(Note: I've hardcoded the paths for the purpose of this example. A real app should use Context.getFilesDir()
.)
A few things to note here:
adb
shell.However, when running the code above, I get an exception:
Error running exec(). Command: [/data/data/com.me.myapp/files/myexec, param1, param2] Working Directory: /data/data/com.me.myapp/files/somedir ...
Why can't my app exec
the executable?
Wow - it only took about 2 minutes after asking the question before I discovered what I was doing wrong.
The problem was simply that the working directory didn't exist before running exec
.