android ndk開發

來源:互聯網
上載者:User

總結一下android ndk開發流程

1,需要下載ndk開發包,解壓配置環境變數,和sdk配置差不多

:http://developer.android.com/tools/sdk/ndk/index.html

2,下載cygwin軟體在windows下類比Linux環境編譯器

:http://www.cygwin.com/

相關文章:http://blog.csdn.net/buildon/article/details/711536

http://www.cnblogs.com/playing/archive/2011/07/14/2106727.html

編譯.so類庫

相關文章: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 {//匯入的lib名去掉前面的lib        System.loadLibrary("hello-jni");    }

2.build下項目,開啟cmd,cd到該工程bin目錄下,
D:\>cd D:\android\rayn\TestJni\bin

D:\android\rayn\TestJni\bin>javah -jni com.stay.jni.CallNative

然後在bin目錄下會出現一個.h檔案這是聲明的標頭檔

3.我們要的是裡面聲明的方法,把我們要寫的c檔案改成相同的方法名就可以了。

4.在工程裡建個jni目錄,將改好的c檔案和mk檔案(隨便copy一個,改下路徑和lib名就好啦)copy進去


常見錯誤:

錯誤1:當輸入cd &NDK時出現no such file or Director時

原因1:在配置目錄下cygwin\home\Andy\下的.bash_profile時配置的ndk所在路徑有錯誤(

正確格式NDK=/cygdrive/d/adt-bundle-windows-x86/android-ndk-r8e

export NDK)

原因2:沒有在系統內容變數中配置ndk(與sdk路徑配置一樣)


錯誤2:native method not found

原因:.c或.cpp內的函數名與Javah 編譯產生包名不一致所導致


關於ndk詳細介紹,可參考這篇文章

http://blog.chinaunix.net/uid-10008293-id-2972294.html

http://blog.csdn.net/zhangjie201412/article/category/1086150



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.