NDK: how include *.so files in AndroidStudio

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)
     }

Leave a Comment