我正在尝试运行this项目.Every,当我运行该项目时收到以下错误:
java.lang.UnsatisfiedLinkError: dlopen失败:dlopen具有文本位置
项目不会加载*.so文件。我已经将so文件的位置从libs更改为jniLibs,但仍然得到相同的问题。
构建.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.sharannya.androidspeakerrec"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
ndk {
abiFilters "armeabi-v7a","armeabi"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
}
从java代码调用
static {
try {
System.loadLibrary("ndkspeaker");
} catch (UnsatisfiedLinkError e) {
Log.e("Error in loading lib","Native code library failed to load" + e);
}
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ndkspeaker
LOCAL_LDLIBS := -llog
LOCAL_SRC_FILES := lib_mfcc/abs.c \
lib_mfcc/abs1.c \
lib_mfcc/fft.c \
lib_mfcc/fi_fft.c \
lib_mfcc/fi_mfcc.c \
lib_mfcc/fi_mfcc_initialize.c \
lib_mfcc/fi_mfcc_rtwutil.c \
lib_mfcc/fi_mfcc_terminate.c \
lib_mfcc/log.c \
lib_mfcc/mfcc_bare.c \
lib_mfcc/mtimes1.c \
lib_mfcc/power1.c \
lib_mfcc/rt_nonfinite.c \
lib_mfcc/rtGetInf.c \
lib_mfcc/rtGetNaN.c \
lib_mfcc/sqrt.c \
lib_mfcc/sum.c \
SpeakerRecognizer.c
APP_ABI := armeabi
include $(BUILD_SHARED_LIBRARY)
.so文件位于项目/app/src/main/jniLibs/armeabi和项目/app/src/main/jniLibs/armeabi-v7a中
我该如何解决这个问题?
发布于 2017-02-02 10:08:40
您可能需要在gradle文件中设置'jniLibs.srcDirs‘。您可以查看这里-实际上,问题中的代码应该会对您有所帮助:How to setup NDK libs path in Gradle?
发布于 2017-02-03 14:16:59
经过一段时间的代码挖掘,我得到了问题的解决方案。
我尝试运行的项目是一个使用Android mk ndk build .So的旧项目,我从项目中删除了所有的cpp文件夹和cmake文件。
然后右键单击库并选择"Link c++ with gradle“选项。单击该选项时,将显示一个窗口,用于选择构建system.Select "ndk build“的类型,并将Android.mk路径链接到项目。
https://stackoverflow.com/questions/41996546
复制相似问题