So here is what I want to do. I am having a third party native executable that is being spawned by my Activity. The Activity and the native executable communicate via TCP. The thing is - the third party application is using libusb and therefore requires root. So I thought it might be possible to actually write a wrapper libusb-java that has the same interface as the original libusb but instead uses Android USB Host API. Therefore I could just link the executable I am running with my libusb-java without changing it and it would use Android USB Host API. The problem is that if I want to write libusb-java, I need to be able to access the JVM from inside the library (which would be dynamically loaded as the third party executable starts), but since this is not going to be linked on the Java side, I have no way of accessing it. Is there an easy way to invoke some java code from a native executable that is not linked to an Activity (possibly reflection?). Any ideas?
For example: If my native binary calls *libusb_open()*, it would actually invoke *libusb_open()* from libusb-java which in turn should invoke openDevice() of android.hardware.usb.UsbManager rather than the original direct native implementation. (I'm oversimplifying but tha'ts the basic idea)
Simple answer: no, there isn't. You can start up your own Dalvik VM and potentially call into that, but it won't have standing in the Android system as an Activity, so it will be difficult to use many of the platform services.
You'd be better off trying to restructure the native code to run as a library loaded by a DVM in the normal Android fashion as an Activity- or Service- hosting process. Sometimes this can be nearly as simple as calling it's main() from a static jni subroutine, but do beware of potential inconsistency in process-level static data, since Android will often start a new entity in an old process.
Or you could proxy your simulated API calls through TCP, [with some trickery] Binder, or some other IPC mechanism.