Android jni开发中的常见错误

时间:2020-12-02 03:15:33

错误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文件

Android jni开发中的常见错误

我们可以看到上面的编译过程中出现警告,可以在 Application.mk 指定:
APP_PLATFORM := android-8

Android jni开发中的常见错误