Can we override native methods in android? Apart from extending a class/interface and implementing its methods.
Can we use .so file to override native methods?
For eg. If there is methodA() in native code, shall we override that in .so file. so that everytime when we call methodA() from android application, it will call methodA() in our .so file?
Can we override native methods in android? Apart from extending a class/interface and implementing
Share
No. Dalvik VM is not compatible enough for JNI DefineClass() call. Therefore, any override you want to load must be available in dex format to begin with.
Also, there is no way to “inject’ native lib into an app without the app’s knowledge.
But, there are lots of sophisticated things you can do through reflection – either from Java or from C. If this code gets a handle to your Activity, it could find the field of class SharedPreferences and replace it with a new field of class ExtendedSharedPreferences.