java.lang.UnsatisfiedLinkError : Native method not found: 错误

标签 java android c++ android-ndk java-native-interface

在调用编译在 .SO 文件中的 native 方法时,我不断收到此错误。 我不知道为什么会发生,因为一切似乎都设置正确 任何帮助将不胜感激

错误:

java.lang.UnsatisfiedLinkError: Native method not found: de.jurihock.voicesmith.dsp.Math.abs:(FF)F
at de.jurihock.voicesmith.dsp.Math.abs(Native Method)

cpp 文件:pastebin.com/aBHNz642

数学.java

 package de.jurihock.voicesmith.dsp;

public final class Math
{
     static
        {
        System.loadLibrary("Voicesmith");
        }

public static final float   PI  = (float) java.lang.Math.PI;

public static int round(float value)
{
    return java.lang.Math.round(value);
}

public static native float pow(float base, float exponent);

public static native float log10(float value);

public static native float min(float a, float b);

public static native float max(float a, float b);

public static native float floor(float value);

public static native float ceil(float value);

public static native float sin(float angle);

public static native float cos(float angle);

public static native float sqrt(float value);

public static native float atan2(float y, float x);

public  native float abs(float real, float imag);

public static native float arg(float real, float imag);

public static native float real(float abs, float arg);

public static native float imag(float abs, float arg);

public static native float random(float min, float max);

public static native float princarg(float phase);

public static native short mean(short[] buffer, int offset, int length);

public static native float rms(short[] buffer, int offset, int length);

public static native float rms(short[] buffer, int offset, int length, short mean);

public static native float rms2dbfs(float value, float min, float max);

安卓.mk

    LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

# Name of the library without prefix "lib" and file extension
LOCAL_MODULE := Voicesmith

# Optimization flags (see KissFFT makefile)
LOCAL_ARM_MODE := arm
LOCAL_CFLAGS := -Wall -O3 -ffast-math -funroll-loops -fomit-frame-pointer

# LogCat support
# LOCAL_LDLIBS := -llog

# Debugging flag
# LOCAL_CFLAGS += -g

# Include all .c/.cpp files to build
LOCAL_SRC_FILES := $(shell cd $(LOCAL_PATH); \
    find . -type f -name '*.c'; \
    find . -type f -name '*.cpp')

include $(BUILD_SHARED_LIBRARY)

最佳答案

您的 native 方法 abs 在其声明中缺少 static。您的构建应该已经捕获了错误,Android Studio 确实如此..

尝试将其更改为

public static native float abs(float real, float imag);

其他一些建议:

  • name Math.h 可能与 native 端的标准 math.h 冲突(如果您在 Windows 上尝试甚至无法编译,因为 Windows 文件系统就是这种情况不敏感...我不得不将您的 Math.h 更改为 Math2.h)。

  • 即使在 java 端,java.lang.Math 中也已经有具有类似功能的 Math 类(例如:java.lang.Math .abs),可能会使用 java.lang.Math.abs 自动完成,特别是对于上面的代码 fragment ,因为它在声明中缺少 static (``java. lang.Math.abs` 是与其匹配的静态 IDE)

关于java.lang.UnsatisfiedLinkError : Native method not found: 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26104489/

相关文章:

java - Tika 1.14 : getting java. PDFTextStripper 的 lang.NullPointerException

Java : new Filter(){} to kotlin

C++ 设置具有 const 成员的成员对象

C++ 查找指针错误

c++ - 为什么我的编辑控件会忽略应用的视觉样式?

java - while-else-循环

java - 我无法删除 sqlite 中的日期

android - SQLite 难以从游标中检索值

java - 如何将图片和音频设置为mp4 ffmpeg?

java - eclipse定制版