我已经搜索了堆栈溢出,它们都没有真正解决我的问题。
我能够为我的库构建.so文件,并将其加载到jniLibs目录中。当我运行这个应用程序时,我得到了这个
未找到java.lang.UnsatisfiedLinkError:本地方法: soundtouch.ST.setup:(IIIIFF)V at soundtouch.ST.setup(本地方法)
我花了两天时间,仍然找不出问题。请有人指导我解决这个问题。
我在这里错过了什么?
谢谢!我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.examples.anu.soundtouchexamplewithseekbar"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
ndk {
moduleName "soundtouch-jni"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jniLibs.srcDir 'src/main' //set .so files location to libs
jni.srcDirs = [] //disable automatic ndk-build call
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = project.plugins.findPlugin('com.android.application').getNdkFolder()
commandLine "$ndkDir/ndk-build",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
'NDK_APPLICATION_MK=src/main/jni/Application.mk'
}
}
dependencies
{
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'src/main/jniLibs')
compile 'com.android.support:appcompat-v7:21.0.3'
}我的Android.mk:
LOCAL_PATH := $(call my-dir)
APP_STL := stlport_shared
include $(CLEAR_VARS)
MY_SOURCE_DIR:=soundtouch
LOCAL_MODULE:=soundtouch-jni
LOCAL_C_INCLUDES:=$(LOCAL_PATH)/soundtouch/include
LOCAL_SRC_FILES:= soundtouch_ST.cpp\
soundtouch-jni.cpp\
$(MY_SOURCE_DIR)/source/SoundTouch/AAFilter.cpp\
LOCAL_ARM_MODE:=arm
LOCAL_LDLIBS+=-lz -llog
LOCAL_CFLAGS += -Wall -fvisibility=hidden -I soundtouch/source/../include -D ST_NO_EXCEPTION_HANDLING -fdata-sections -ffunction-sections
include $(BUILD_SHARED_LIBRARY)========部分地添加了我的java和JNI签名:
import android.util.Log;
public class ST implements AudioProcessor
{
private static final int DEFAULT_BUFFER_SIZE = 2048;
private static synchronized native final void putBytes(int track,
byte[] input, int length);
private static synchronized native final void setup(int track,
int channels, int samplingRate, int bytesPerSample, float tempo,float pitchSemi);==========我的自动生成:.h文件: /*不编辑这个文件-它是机器生成的/# soundtouch_ST */ Header类
#ifndef _Included_soundtouch_ST
#define _Included_soundtouch_ST
#ifdef __cplusplus
extern "C" {
#endif
#undef soundtouch_ST_DEFAULT_BUFFER_SIZE
#define soundtouch_ST_DEFAULT_BUFFER_SIZE 2048L
/*
* Class: soundtouch_ST
* Method: clearBytes
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_soundtouch_ST_clearBytes
(JNIEnv *, jclass, jint);
/*
* Class: soundtouch_ST
* Method: finish
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_soundtouch_ST_finish
(JNIEnv *, jclass, jint, jint);
/*
* Class: soundtouch_ST
* Method: getBytes
* Signature: (I[BI)I
*/
JNIEXPORT jint JNICALL Java_soundtouch_ST_getBytes
(JNIEnv *, jclass, jint, jbyteArray, jint);
/*
* Class: soundtouch_ST
* Method: putBytes
* Signature: (I[BI)V
*/
JNIEXPORT void JNICALL Java_soundtouch_ST_putBytes
(JNIEnv *, jclass, jint, jbyteArray, jint);
/*
* Class: soundtouch_ST
* Method: setup
* Signature: (IIIIFF)V
*/
JNIEXPORT void JNICALL Java_soundtouch_ST_setup
(JNIEnv *, jclass, jint, jint, jint, jint, jfloat, jfloat);====== My实现: soundtouch_ST.cpp
#include "soundtouch_ST.h"
#include "soundtouch-jni.h"
/* cpp for class soundtouch_ST */
#ifndef _Included_soundtouch_ST
#define _Included_soundtouch_ST
#ifdef __cplusplus
extern "C" {
SoundTouchStream sts = new SoundTouchStream();
#endif
/ *
* Class: soundtouch_ST
* Method: clearBytes
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_soundtouch_ST_clearBytes
(JNIEnv *env, jclass obj, jint track) {
sts->clearBytes(env,obj,track);
}
/*
* Class: soundtouch_ST
* Method: finish
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_soundtouch_ST_finish
(JNIEnv *, jclass obj, jint track, jint length){
sts->finish(env,obj,track,length);
}
/*
* Class: soundtouch_ST
* Method: getBytes
* Signature: (I[BI)I
*/
JNIEXPORT jint JNICALL Java_soundtouch_ST_getBytes
(JNIEnv *env, jclass obj, jint a, jbyteArray x, jint b) {
(*env)->sts->getBytes(env,obj,a,x,b);
}
/*
* Class: soundtouch_ST
* Method: putBytes
* Signature: (I[BI)V
*/
JNIEXPORT void JNICALL Java_soundtouch_ST_putBytes
(JNIEnv *env, jclass obj, jint a, jbyteArray x, jint b) {
sts->putBytes(env,obj,a,x,b);
}
/*
* Class: soundtouch_ST
* Method: setup
* Signature: (IIIIFF)V
*/
JNIEXPORT void JNICALL Java_soundtouch_ST_setup
(JNIEnv *env, jclass obj, jint a, jint b, jint c, jint d, jfloat f, jfloat g) {
sts->setup(env,obj,a,b,c,d,f,g)
}发布于 2015-03-13 00:11:50
它是下列之一:
1)你的图书馆不包括在内。解压apk并确保其内部。
2)没有加载.so文件
3)C和Java端JNI函数的签名不匹配(错误期望它以该顺序接受4个ints和2个浮点数并返回the )。
4)您在Java或C中键入了一个名称,这样它们就不匹配了。
https://stackoverflow.com/questions/29022594
复制相似问题