我已经下载了一个使用tensorflow实现情感识别的android程序。我已经完成了环境配置的工作。而且我发现当我使用识别应用程序时,日志显示"Trying to load lib /data/app-lib/com.example.alex.opencvdemo-1/libtensorflow_inference.so 0xa4f77c88"
,然后应用程序将退出。我不知道如何解决这个问题
这是我的loadLibrary代码
static {
//load libtensorflow_inference.so
//System.load("/app/com.example.alex.opencvdemo/libs/libtensorflow_interface.so");
System.loadLibrary("tensorflow_inference");
Log.e("tensorflow","libtensorflow_inference.so is successfully load");
}
以下是我的应用程序build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.alex.opencvdemo"
minSdkVersion 18
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
multiDexEnabled true
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
buildTypes {
debug {
ndk { abiFilters "armeabi-v7a","x86"}
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets{
main {
jni.srcDirs = []
//jni库的调用会到资源文件夹下libs里面找so文件
jniLibs.srcDirs = ['libs']
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
compile project(':openCVLibrary342')
implementation files('libs/libandroid_tensorflow_inference_java.jar')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
答案 0 :(得分:0)
我先前遇到的可能原因
verify tensorflow_inference。
如果您使用的是openCV,请确保您导入的本地库很好