mika
mika

Reputation: 343

Error 'loading android-aarch64/libmongo_embedded_capi.so' for MongoDB Mobile

I'm trying to use MongoDB Mobile (beta) in my Android app. I've folowed the steps as described here

This is the code that is executed:

final StitchAppClient client = Stitch.initializeDefaultAppClient("<APP ID>");

final MongoClient mobileClient = client.getServiceClient(LocalMongoDbService.clientFactory);

the first line works but when the second line is executed the app crashes with this error:

 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.

This library is not incuded in the download provided by mongoDB, but apperantly is still needed. Am I doing something wrong or is this a problem from mongoDB.

The device im using is a Oneplus 6 with the arm64-v8a libraries from mongoDB in this location: app\src\main\jniLibs\arm64-v8a

for reference, this is my build.gradle:

build.gradle(Project: App):

// 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(Module: App):

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+'

}

Upvotes: 1

Views: 475

Answers (2)

mika
mika

Reputation: 343

Unfortunately the answer from @shizhen didn't work for me. What did work in the end was renaming a library provided by mongoDB. I renamed the library libmongoc_embedded.so to libmongo_embedded_capi.so and it works perfectly.

My assumtion is that this is the same library with a different name. It was changed in the download from mongoDB but not in the Java code, mongoDB Mobile is still in beta. I do not know a lot about mongoDB Mobile or Stitch so this might not be true, but it fixed the problem for me.

Upvotes: 0

shizhen
shizhen

Reputation: 12583

From below error log

Setting 'jna.library.path' system property

It looks you miss the JNA dependencies for your project.

Try below steps:

  • Add JNA dependencies into your build.gradle

    dependencies {
        ...
        // JNA dependency
        implementation 'net.java.dev.jna:jna:4.5.0'
        ...
    }
    
  • Include the libjnidispatch.so shared library for all the Android ABIs that your project supports.

    • Navigate to JNA libraries.
    • Under Version 4.5.0, download the zip archive
    • Unzip the package, navigate to jna-4.5.0/dist/ directory. libjnidispatch.so for different ABIs can be extracted from respective jar file. The mapping is as below illustrated in below table.

      | JNA ABI             | Android ABI   |
      | ------------------- | ------------- |
      | android-aarch64.jar | arm64-v8a     |
      | android-armv7.jar   | armeabi-v7a   |
      | android-x86-64.jar  | x86_64        |
      | android-x86.jar     | x86           |
      
    • Put the libjnidispatch.so into the mapped Android ABI folder, for example, arm64-v8a, armeabi-v7a, x86 and x86_64.

Upvotes: 1

Related Questions