我有一个 Android 项目,我们使用实验性 Gradle 插件已经有一段时间了。随着 Android Studio 3 的发布和 Gradle 4 的迁移,我有几个问题
仅仅看,几个月内没有人添加新的实验性 gradle 版本,最后一个版本 11 alpha 是 3 个月前。这个还在维护吗?
有没有比实验性 Gradle 插件更好的方法来进行复杂的 NDK 构建?我做了一些研究,看起来有一种方法可以拥有一个 cMake txt 文件并像他们对这个 Samba 客户端所做的那样调用它 https://github.com/google/samba-documents-provider/tree/master/app
当我说复杂的 NDK 构建时,我将许多 C++ 库放在一起。我有一堆自定义 C++ 代码,我有几个 3rd 方库,它们有自己的代码以及共享库。而且我有许多 jni 接口文件来管理它。
我缩短了这个例子,但我有 12 个这样的文件。
model {
// this repositories section defines our list of external shared libraries
// included here are all nuance libs and python 3.5
repositories {
libs(PrebuiltLibraries) {
lib1 {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("src/main/jniLibs/${targetPlatform.getName()}/lib1.so")
}
}
lib2{
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("src/main/jniLibs/${targetPlatform.getName()}/lib2.so")
}
}
}
}
然后我有以下 NDK 部分
// defines the NDK build
ndk {
moduleName "myApp"
toolchain = "clang"
// We set the platform for the NDK. with the a certain device we were getting missing libraries without it
// https://github.com/android-ndk/ndk/issues/126
platformVersion="23"
// If switching to GNU, here are the values to replace with
stl "gnustl_shared"
CFlags.addAll(["-DNDEBUG"])
cppFlags.addAll(["-fexceptions", "-std=gnu++11"])
// when adding system library dependencies, they are added here
ldLibs.addAll(["log","atomic"])
// C include directories
CFlags.addAll(["-I${file("src/main/jni/lib1/inc")}".toString(),
"-I${file("src/main/jni/lib2")}".toString()
])
// C++ include directories
cppFlags.addAll(["-I${file("src/main/jni/lib1/inc")}".toString(),
"-I${file("src/main/jni/lib1")}".toString(),
"-I${file("src/main/jni/lib2")}".toString(),
"-I${file("src/main/jni/lib2/os")}".toString(),
"-I${file("src/main/jni")}".toString()
])
}
`
然后也在gradle中列出我所有的jni来源
// this section is to list the NDK static/shared library dependencies
// these dependencies are defined in detail above in the repositories section
sources {
main {
jni {
dependencies {
library "lib1"
library "lib2"
library "lib3"
library "lib4"
library "lib5"
library "lib6"
library "lib7"
library "lib8"
library "lib9"
library "lib10"
library "lib11"
library "lib12"
}
}
}
}