I have an Android app that needs to run a custom binary app I wrote. I already built the binary using ndk and packaged it in the apk under res/raw
I did something like t
There's a nasty hacky way to trick Android into doing this for you (which I do, successfully).
When the application is installed, Android will copy the appropriate libraries for your architecture out of libs/$ARCH/libfoo.so
into /data/data/$PACKAGE/libs
for you. The tricky bit is that it will only copy files of the form lib$SOMETHING.so
. It'll even preserve the execute permissions.
So, if you rename your su
executable to libsu.so
, Android will do all the work for you. You can then find it using the paths available from Activity.
However, beware! Android is not designed to run standalone apps and Zygote really doesn't get on well with being forked. I've found that Runtime.exec()
has race conditions and can crash. The only reliable technique I've found is to use JNI to implement a little library that does a fork and exec without touching any other data between the fork and the exec. I did have a question here about this with all the details, but I can't find it.
I don't have access to any of the code right now, but if you want I can find some of it for you on Monday.