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

Issue

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?
Log:

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?

Solution

Three options:

One

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

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

Two

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

There

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

//Another code....

    dependencies
    {
          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/'
    }
    
    tasks.withType(JavaCompile)
     {
          compileTask -> compileTask.dependsOn(nativeLibsToJar)
     }

Answered By – Aspicas

Answer Checked By – Gilberto Lyons (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published