I. Java reflection mechanism
understand the principle of the Java reflection mechanism first
Example online a lot, reflection is very flexible
two. Tune Java at the JNI layer
use:Java layer reverse is relatively easy, increase the reverse threshold, the call is written to the JNI layer, so that the Java layer has no call relationship
Note:C and C + + are different, use C + + as an example here
1. First provide a showlog function in the code private void showmsg () { Log. D ("_bing_", "showmsg");}
2. Add code to the last add example jniexport jint jnicall java_org_bing_testjni_mainactivity_add (jnienv *env, jobject obj, jint a, jint b){While (true) { //Reflection call Java code jclass cls = env-findclass("Org/bing/testjni/mainactivi Ty "); If (cls = = NULL) {Break ; } jmethodid showmsg = env-getmethodid(CLS, "ShowMsg", "() V") ); if (showmsg = = NULL) {Break ; } //Call construct initialization //Jmethodid init = Env->getmethodid (CLS, "<init>", "() V");//Jobject obj1 = Env->newobject (CLS, init); env-callvoidmethod(obj, showmsg);Break ; } return a + b;}
3. How to get the function signature information aboveEnter the command in the Project Bin/classes directory: javap-p-S org.bing.testjni.MainActivity
Javap-p-S package name. Class Name
It is also possible to make scripts for generating headers and queries easy to use
3. Output Results
From for notes (Wiz)
Ndk learns 18:jni's c&c++ call Java