我正在尝试在我的 Android 应用程序中使用 MongoDB Mobile(测试版)。我已按照描述的步骤执行 here
这是执行的代码:
final StitchAppClient client = Stitch.initializeDefaultAppClient("<APP ID>");
final MongoClient mobileClient = client.getServiceClient(LocalMongoDbService.clientFactory);
第一行有效,但当执行第二行时,应用程序崩溃并出现此错误:
com.mongodb.embedded.client.MongoClientEmbeddedException: Failed to load the mongodb library: 'mongo_embedded_capi'.
Unable to load library 'mongo_embedded_capi': Native library (android-aarch64/libmongo_embedded_capi.so) not found in resource path (.)
Please set the library location by either:
- Adding it to the classpath.
- Setting 'jna.library.path' system property
- Configuring it in the 'MongoEmbeddedSettings.builder().libraryPath' method.
这个库不包含在 mongoDB 提供的下载中,但显然仍然需要。我做错了什么还是 mongoDB 的问题。
我使用的设备是 Oneplus 6,其位置为 mongoDB 的 arm64-v8a 库:app\src\main\jniLibs\arm64-v8a
供引用,这是我的build.gradle:
build.gradle(项目:应用程序):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(模块:应用程序):
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.mikakrooswijk.led"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
} }
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.volley:volley:1.0.0'
implementation 'com.jjoe64:graphview:4.2.2'
implementation 'org.mongodb:stitch-android-sdk:4+'
implementation 'org.mongodb:stitch-android-services-mongodb-local:4+'
}
最佳答案
来自下面的错误日志
Setting 'jna.library.path' system property
看起来您错过了项目的 JNA 依赖项。
尝试以下步骤:
将 JNA 依赖项添加到您的
build.gradle
dependencies { ... // JNA dependency implementation 'net.java.dev.jna:jna:4.5.0' ... }
为您的项目支持的所有 Android ABI 添加
libjnidispatch.so
共享库。- 导航到 JNA libraries .
- 在版本 4.5.0 下,下载 zip 存档
解压缩包,导航到
jna-4.5.0/dist/
目录。可以从各自的 jar 文件中提取用于不同 ABI 的libjnidispatch.so
。映射如下表所示。| JNA ABI | Android ABI | | ------------------- | ------------- | | android-aarch64.jar | arm64-v8a | | android-armv7.jar | armeabi-v7a | | android-x86-64.jar | x86_64 | | android-x86.jar | x86 |
将
libjnidispatch.so
放入对应的Android ABI文件夹中,例如arm64-v8a
,armeabi-v7a
,x86
和x86_64
。
关于android - MongoDB Mobile 错误 'loading android-aarch64/libmongo_embedded_capi.so',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53061872/