[英]java.lang.UnsatisfiedLinkError: Native method not found:
調用在.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)
您的本機方法abs
在其聲明中缺少static
。 您的版本應該已經捕獲了錯誤,Android Studio確實如此。
嘗試將其更改為
public static native float abs(float real, float imag);
其他一些建議:
名稱Math.h
可能與本機端的標准math.h
沖突(如果在Windows上嘗試,甚至都不會編譯,因為Windows文件系統不區分大小寫...我必須將Math.h更改為Math2.h)。
即使在Java方面, java.lang.Math
上已經存在具有類似功能的Math
類(例如: java.lang.Math.abs
),可以使用java.lang.Math.abs
自動完成,特別是對於上面的代碼段而言聲明中缺少static
(``java.lang.Math.abs`是與之匹配的靜態IDE)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.