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:
- Why is it necessary to wrap it in a *.jar?
- When changing something in my native libraries, I can see the changes taking effect in my Application, also the Gradle building process always outputs "...:app:nativeLibsToJar UP-TO-DATE...". So I assume this task is not re-run. But when this task wraps the *.so in *.jar than how is it possible to re-wrap them without rerunning this task??
I am thankful for every explanation :)