Search code examples
javaandroidprocessbuilder

Why isn't ProcessBuilder able to launch my executable when provided with an absolute filename?


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:

  • The executable was cross-compiled for ARMv6 using the NDK.
  • The binary does have the executable bit set.
  • I can run the executable from the 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?


Solution

  • 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.