简体   繁体   中英

Android Studio unable to read Mega .so library

I am trying to integrate Mega Api in Android. They have lib.so which i need to add in Android Studio.

Here is my code

在此处输入图片说明

However it fails to load the libs

Here is what i get

STACK_TRACE=java.lang.UnsatisfiedLinkError: Native method not found: com.neberox.app.libraries.mega.megaJNI.swig_module_init:()V
    at com.neberox.app.libraries.mega.megaJNI.swig_module_init(Native Method)

What should i do to make AndroidStudio read these files.

During compilation, the native libraries are packaged only if there path has been specified in the build.gradle file.

Check this:

sourceSets.main {
    jniLibs.srcDir 'src/main/jniLibs'
}

As an example:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.cprakashagr.jni"
        minSdkVersion 21
        targetSdkVersion 23

        ndk {
            moduleName "ndkfoo"
        }
    }

    sourceSets.main {
        jniLibs.srcDir 'src/main/libs' //set libs as .so's location instead of jni
        jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk file
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

}

dependencies {
    compile 'com.android.support:support-v4:23.1.1'
}

Reference: http://tools.android.com/tech-docs/new-build-system/user-guide

Additionally to @cprakashagr 's post, you could try using ReLinker or Facebook's SoLoader library to ensure that the system finds your native library.

https://github.com/KeepSafe/ReLinker

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM