what is the magic of nativeLibsToJar

妖精的绣舞 提交于 2019-12-24 15:54:37

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/37447811/what-is-the-magic-of-nativelibstojar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!