標籤:
我們在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開發有哪些常見的錯誤