android - MongoDB Mobile 错误 'loading android-aarch64/libmongo_embedded_capi.so'

标签 android mongodb java-native-interface shared-libraries

我正在尝试在我的 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, x86x86_64

关于android - MongoDB Mobile 错误 'loading android-aarch64/libmongo_embedded_capi.so',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53061872/

相关文章:

android - 如果我没有任何数据要存储,在使用 GCM 时是否需要后端服务器作为中介?

android - 构建 Cordova Android 应用程序时,构建找不到 aidl

mongodb - MongoDB 中数十亿小文档的快速搜索策略

MongoDB - 不同集合中的相同_id

model-view-controller - 在 node.js 模块中异步初始化导出可以吗?

android - mupdf for android : ndk-build problem (error: redefinition of typedef. ...)

java - 如何使用 Firebase 的 ServerValue.TIMESTAMP 作为子项并为其设置值

android - 状态栏不是透明的而是白色的

Android - 'Couldn' t 加载 Foo : findLibrary returned null'

java - 允许 native 代码直接访问java堆中的对象吗?