[FIXED] NDK: how include *.so files in AndroidStudio


I have libs jar and *.so. I created Eclipse project as in tutorial (for this libs). I am now doing project in Android Studio, but system can’t find *.so files. I make how in this – Include .so library in apk in android studio . My app does not find function in so libs. How to find them?

10-16 12:16:55.965: W/dalvikvm(4386): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/atol/drivers/fptr/IFptrNative;
10-16 12:16:55.965: W/dalvikvm(4386): threadid=1: thread exiting with uncaught exception (group=0x41869438)
10-16 12:16:55.976: E/AndroidRuntime(4386): FATAL EXCEPTION: main
10-16 12:16:55.976: E/AndroidRuntime(4386): java.lang.ExceptionInInitializerError

An error occurs when creating an object using a JAR library. She in turn poked *.so files, but to find what she needs. Who is to blame and what to do?


Three options:


Copy yours *.SO libraries on your libs folder and put that on build.gradle:

    compile fileTree(include: ['*.jar'], dir: 'libs')


Make a new folder on src/main/jniLibs and write that on your build.gradle:

android {
    //Another code 
    sourceSets {
        main {         
            jniLibs.srcDirs = ['src/main/jnilibs']          
        //Another code 
    }//sourceSets tag close
}//Android tag close


Make a new folder on src/main/jniLibs and write that on your build.gradle:

//Another code....

          compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    }//end dependencies

    task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
        destinationDir file("$buildDir/native-libs")
        baseName 'native-libs'
        from fileTree(dir: 'src/main/jnilibs', include: '**/*.so')
        into 'lib/'
          compileTask -> compileTask.dependsOn(nativeLibsToJar)

Answered By – Aspicas

Answer Checked By – Gilberto Lyons (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published