[英]Android NDK build cmake include .so library included in .aar library
I have an android_library.aar file that containing library.so and some other resources and java files.我有一个包含library.so和其他一些资源和 java 文件的android_library.aar文件。
I imported android_library.aar to my project.我将android_library.aar导入到我的项目中。 My project uses c++ code with NDK.
我的项目使用带有 NDK 的 C++ 代码。 My problem is I can not compile C++ code that dependent with library.so with CMake.
我的问题是我无法使用 CMake 编译依赖于library.so 的C++ 代码。 How could I extract library.so from aar before CMake compile?
如何在 CMake 编译之前从aar 中提取library.so ? I want to include library.so to my C++ code directly without java.
我想在没有 java 的情况下直接将library.so包含到我的 C++ 代码中。 I know how to include .so in a project but I don't know how to do it from inside of aar.
我知道如何将.so包含在项目中,但我不知道如何从 aar 内部进行。
I found a solution on my own after 1-week research.经过 1 周的研究,我自己找到了解决方案。 I found some code from Google GVR code.
我从 Google GVR 代码中找到了一些代码。 But it hasn't worked for my case.
但这对我的情况不起作用。 I changed build.dependsOn to preBuild.dependsOn then it worked.
我将build.dependsOn更改为preBuild.dependsOn然后它起作用了。 It might help some people in the future.
它可能会在未来帮助一些人。
Here is the example code:这是示例代码:
In the module's build.gradle file:在模块的 build.gradle 文件中:
sourceSets {
main {
jniLibs.srcDirs = ["jniLibs"]
}
}
task extractSo(type: Copy) {
println 'Extracting *.so file(s)....'
from zipTree("${project.rootDir}/ModuleName/ModuleName.aar")
into "${project.rootDir}/${project.name}/src/main/jniLibs/"
include "jni/**/*.so"
eachFile {
def segments = it.getRelativePath().getSegments() as List
println segments
it.setPath(segments.tail().join("/"))
return it
}
includeEmptyDirs = false
}
preBuild.dependsOn extractSo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.