I am working on an Android app that controls various UNIX daemons that need root access to work properly. Originally, I started with some scripts that had all sorts of little tricks to get su integrated in for controlling the root access. Then there was a file that contained a bunch of environment variables that needed to be set.
In my foolhardiness, I decided that the environment variables needed to be set in the java Runtime.exec() call, since it lets you do that. Since the original information to create these variable came from Java, it seemed the logical thing to do. After many struggles where it just didn’t work, su just hung with no warning or reason. It turns out that when running command line programs in Android, the environment is essential. Environment variables like LD_LIBRARY_PATH are essential for programs to find the shared libraries they need, since Android does not implement rpath in binaries for finding .so files.
So all I needed to do was first get the environment from Android, then add my stuff to it, then use that whole thing when calling Runtime.exec(). Here’s the commit. Seems so simple now, if only I could get all that time I spent banging my head against this back…