Summary of the android ndk Development Process
1. Download The ndk Development Kit and decompress the configuration environment variable, which is similar to the SDK Configuration
: Http://developer.android.com/tools/sdk/ndk/index.html
2. Download The cygwin software and simulate the Linux compiler in windows.
: Http://www.cygwin.com/
Related Articles: http://blog.csdn.net/buildon/article/details/711536
Http://www.cnblogs.com/playing/archive/2011/07/14/2106727.html
Compile the. So class library
Related Articles: http://blog.csdn.net/android_panda/article/details/7607946
Http://blog.csdn.net/wangkuifeng0118/article/details/7311724
@ Overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // setcontentview (R. layout. activity_main); textview TV = new textview (this); TV. settext (stringfromjni (); setcontentview (TV);}/* a native method that is implemented by the * 'hello-JNI 'native library, which is packaged * with this application. */Public native string stringfromjni (); static {// remove the preceding lib system from the imported lib name. loadlibrary ("hello-JNI ");}
2. Build the project, open cmd, CD to the bin directory of the project,
D: \> Cd D: \ Android \ rayn \ testjni \ bin
D: \ Android \ rayn \ testjni \ bin> javah-JNI com. Stay. JNI. callnative
Then a. h file will appear in the bin directory. This is the declared header file.
3. What we need is the method declared in it. Just change the c file we want to write to the same method name.
4. Create a JNI directory in the project and copy the changed C file and MK file (copy one file at will, change the path and Lib name) to the directory.
Common Errors:
Error 1: no such file or Director occurs when CD & ndk is input.
Cause 1: the path of the ndk configured in. bash_profile under cygwin \ home \ Andy \ in the configuration directory is incorrect (
Correct format ndk =/cygdrive/D/adt-bundle-windows-x86/android-ndk-r8e
Export ndk)
Cause 2: The ndk is not configured in the system environment variable (the same as the SDK path configuration)
Error 2: Native method not found
Cause: the function name in. C or. cpp is inconsistent with the package name compiled by javah.
For more information about ndk, see this article.
Http://blog.chinaunix.net/uid-10008293-id-2972294.html
Http://blog.csdn.net/zhangjie201412/article/category/1086150