I'm making software (for Android) to read out meter values from sensors. The software is expected to receive updates very often in order to support more sensors. The functionality to read out the meter data voor these sensors is implemented in native libraries that are downloaded on runtime by the app.
I've got a list of shared objects and an entry function that should be called (the return value is saved):
libprintf.so,hookPrintf
libharx.so,hookHarx
Each library is loaded at runtime: System.loadLibrary("printf");
The signature of each function would look like this:
public native int hookPrintf();
public native int hookHarx();
The problem is that I don't know beforehand (at compile time) which shared objects will have to be loaded, and thus I can not add these signatures in the java source.
I tried using Reflection to call the methods dynamically as follows:
Method entryMethod = Expat.class.getMethod(hookMethod);
Object test = entryMethod.invoke(this);
System.out.writeln(test.toString());
However, if the signature is not present, this will still fail with a NoSuchMethodException. Is there another way to be able to call native methods without needing to have them defined beforehand?
Edit: Using the RegisterNatives function, I can register my functions dynamically from the shared object, but that still requires the method signature to be defined in the class. What does the registerNatives() method do?