// Example of a call to a native method TextViewtv= binding.sampleText; tv.setText(stringFromJNI()); }
/** * A native method that is implemented by the 'ndkdemo' native library, * which is packaged with this application. */ publicnative String stringFromJNI(); }
1 2 3 4 5 6 7 8 9 10
#include<jni.h> #include<string>
extern"C"JNIEXPORT jstring JNICALL Java_com_example_ndkdemo_MainActivity_stringFromJNI( JNIEnv* env, jobject /* this */){ std::string hello = "Hello from C++"; return env->NewStringUTF(hello.c_str()); }
操作
1.adb push
1 2 3 4 5 6
adb push android_server /data/local/tmp adb shell su cd /data/local/tmp chmod 777 android_server64 ./android_server