android - 它说“尝试加载库”然后应用程序退出而没有任何信息
问题描述
我已经下载了一个使用 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)
}
解决方案
我之前遇到的可能原因
- 更好地检查您的本机库是否与“tensorflow_inference”匹配。因为在你的 build.gradle 它显示了 native_lib 类似的东西。
验证 tensorflow_inference 是否已添加到 Cmakelists.txt 中。
如果您使用 openCV,请确保您已正确导入本机库
推荐阅读
- reactjs - “--watchAll=false”和“CI=true”有什么区别?
- javascript - 你能改变 RenderSection 的执行顺序吗?
- wordpress - AWS Cloudfront 设置浏览器信息不正确后
- google-cloud-platform - 根据主键将 BigQuery 中的两个表导出到 csv
- windows-terminal - 在 Windows 终端中为 Powershell 启用 CTRL 快捷方式
- tfs - 如何在 TFS Sprints 任务板中添加列(不是 TFS 的在线版本)
- java - Eclipse Jee Oxyg 运行时环境中的问题
- java - RapidClipse:如何根据单元格内容更改 XDevTable/XdevGrid 的行样式
- kendo-ui - 如果不存在数据,则 Kendo Multiselect 删除所有选项
- python - TypeError:bool_ 类型的对象不是 JSON 可序列化的