java.lang.UnsatisfiedLinkError:找不到本机方法:

时间:2014-09-29 16:24:26

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

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

错误:

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

Math.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);

}

android.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)

1 个答案:

答案 0 :(得分:1)

您的原生方法abs在其声明中缺少static。您的构建应该已经捕获了错误,Android Studio会...

尝试将其更改为

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

其他一些建议:

  • 名称Math.h可能与本机标准math.h发生冲突(如果您尝试使用Windows,甚至不会编译,因为Windows文件系统不区分大小写...我必须更改您的数学.h到Math2.h)。

  • 即使在java方面,Math已经java.lang.Math类具有类似的功能(例如:java.lang.Math.abs),也可以使用java.lang.Math.abs自动完成,特别是static上面的代码片段,因为它在声明中遗漏了{{1}}(````java.lang.Math.abs`是静态IDE匹配它)