The following code snippet seems to be the answer how to include native libraries with Android Studio:
task nativeLibsToJar(type: Zip, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
extension 'jar'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
tasks.withType(Compile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
It seems to simply pack the *.so into *.jar. But I really don't understand it:
I am thankful for every explanation :)
That's really funny - I found this as solution so many times:
task nativeLibsToJar(type: Zip, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
extension 'jar'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
But it can be removed because it does nothing useful (maybe it did in older build-versions).
The real trick is done through sourceSets.main.jniLibs.srcDir 'src/main/libs/' //integrate your libs from libs instead of default dir 'jniLibs