JNI開發示例

安裝:eclipse(http://www.eclipse.org/)、CDT(C/C++ Development Tooling)、ADT(Android Development Tools)php

https://dl-ssl.google.com/android/eclipse/ html

 

能夠先從官方下載jar,而後本地安裝:http://www.eclipse.org/cdt/downloads.php java

 

下載Android NDK (Native Development Kit)http://developer.android.com/tools/sdk/ndk/index.html android

JNI的使用方法 git

使用javah創建C/C++的頭文件(*.h) github

切換到src目錄,而後輸入命令(注意編碼): eclipse

將.h複製到jni目錄下 svn

若是運行出錯,參考這裏下載資源:http://blog.csdn.net/wjr2012/article/details/16359113 post

Image(13)

 

在C++中調用Java方法設置文本的內容 google

最後咱們經過Android的點擊事件來調用C++,該C++方法調用Java方法來彈出一個對話框

效果以下圖

 

源代碼已經上傳至github https://github.com/zhangyi/AndroidJNIProject

 

 

最後附上一些JNI的參考連接:


https://en.wikipedia.org/wiki/Java_Native_Interface

https://newcircle.com/s/post/1292/jni_reference_example

http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/index.html

 

返回值爲jintArray、jbyteArray、jlong、jobjectArray、jint、jboolean、jobjectArray、void的示例代碼
https://joinup.ec.europa.eu/svn/mocca/osx-pcsc-jni/trunk/openjdk7/pcsc.c 

Java Programming Tutorial Java Native Interface(JNI)
https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html
 
Call Java functions from C++ in cocos2d-x
http://stnguyen.com/cocos2d-x/call-java-functions-from-cpp.html

Call C++ functions from Java in cocos2d-x
http://stnguyen.com/cocos2d-x/call-cpp-functions-from-java.html

Java programming with JNI
http://www.ibm.com/developerworks/java/tutorials/j-jni/j-jni.html
 
Image 
 
相關文章
相關標籤/搜索