Android jni開發有哪些常見的錯誤

來源:互聯網
上載者:User

標籤:

我們在Android jni開發中,特別是對於剛入門學習Android jni開發的同學來說,往往會遇到很多錯誤,這裡總結了我們經常遇見的錯誤。這些錯誤,你是否經常遇到。

 

錯誤1:java.lang.UnsatisfiedLinkError: Native method not found: 本地方法沒有找到

1、本地函數名寫錯

2、忘記載入.so檔案 沒有調用System.loadlibrary

錯誤2:findLibrary returned null

1、System.loadLibrary("libhello"); 載入動態連結程式庫時 動態連結程式庫名字寫錯

2、平台類型錯誤 把只支援arm平台的.so檔案部署到了 x86cpu的裝置上

查看協助文檔:

APP_ABI

By default, the NDK build system will generate machine code for the ’armeabi’ ABI. This corresponds to an ARMv5TE based CPU with software floating point operations. You can use APP_ABI to select a different ABI.

For example, to support hardware FPU instructions on ARMv7 based devices, use:

APP_ABI := armeabi-v7a

Or to support the IA-32 instruction set, use:

APP_ABI := x86

Or to support the MIPS instruction set, use:

APP_ABI := mips

Or to support all at the same time, use:

APP_ABI := armeabi armeabi-v7a x86 mips

Or even better, since NDK r7, you can also use the special value ’all’ which means "all ABIs supported by this NDK release":

APP_ABI := all

For the list of all supported ABIs and details about their usage and limitations, please read CPU-ARCH-ABIS.

在jni目錄下建立 Application.mk 在裡面指定

APP_ABI := armeabi x86

重新編譯後可以看到分成兩個平台編譯,產生2個.so檔案

我們可以看到上面的編譯過程中出現警告,可以在 Application.mk 指定:
APP_PLATFORM := android-8

文章來自:部落格園/wuyudong

Android jni開發有哪些常見的錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.