问题
I have several c++ projects which I currently build using Android.mk files and ndk-build. Since this is not really great to debug I want to include this c++ projects as modules inside my android studio project. This android studio project is currently an android java library which uses the .so from the ndk-build.
I got debugging to work by creating a new android library module and importing the c++ code, setting header and library paths. This module looks like this:
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = '23.0.2'
defaultConfig {
minSdkVersion.apiLevel = 4
targetSdkVersion.apiLevel = 23
}
}
android.ndk {
moduleName = 'module_name'
toolchain = 'gcc'
stl "gnustl_static"
ldFlags.addAll(["-L/LIB_PATH"])
ldLibs.addAll(["android", "log", "whatever_lib"])
cppFlags.addAll(['-std=c++11',
"-I" + "/SEARCH_PATHS"])
}
android.productFlavors {
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
}
android.sources {
main {
java.source.srcDirs += []
res.source.srcDirs += []
assets.source.srcDirs += []
jniLibs.source.srcDirs += []
jni.source{
srcDirs += [
NATIVE_PROJECT_PATH + "include/",
NATIVE_PROJECT_PATH + "src/",
]
}
}
}
}
This works fine but i get the .so in module/build/output/aar/libname_release.aar/lib/abi/lib.so which is not a good spot since i would need the .so directly without unzipping the aar.
Is there any possible way to let this module only create the .so at a given path and have another module build and use it?
回答1:
Of course I find a way shortly after asking. http://tools.android.com/tech-docs/new-build-system/gradle-experimental#TOC-NDK-Dependencies
Instead of "apply plugin: 'com.android.model.library'" you can use "apply plugin: 'com.android.model.native'" and in the module having the dependency you can use:
sources {
main {
jni {
dependencies {
project ":dependency_module"
}
}
}
}
来源:https://stackoverflow.com/questions/38521846/is-it-possible-in-android-studio-to-build-a-native-module-with-so-as-output