首页 > 代码库 > Android jni开发有哪些常见的错误

Android jni开发有哪些常见的错误

我们在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开发有哪些常见的错误