我正在尝试利用实验性 gradle 插件的“多个 NDK 项目”功能。我正在使用 Android Studio 2.1 和 gradle 插件 0.7.0 稳定版。博客好像是说编译时会包含原生库的exportedHeaders部分指定的头文件
exportedHeaders {
srcDir "src"
}
这似乎对我不起作用。比如说我有以下文件夹结构,我希望 Addition.h 在 native.cpp 中可用,即我应该可以说
#include <Addition.h>
但只有
#include "../../../../../../../Framework/Addition/src/Addition.h"
作品。添加 cppFlags 以包含标题没有区别。
以下是一些相关文件如何查找示例项目。示例项目模块“app”依赖于本地库模块“addition”来添加 2 个数字。本机库使用新的本机插件。
设置.gradle
include ':app'
include ':Addition'
project (":Addition").projectDir = new File("../../../Framework/Addition")
gradle-wrapper.properties
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
build.gradle (:app)
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
ndk {
moduleName = 'native'
platformVersion = 17
toolchain "clang"
cppFlags.addAll(['-I' + file('src/main/jni'),
'-I' + file('../../../Framework/Addition')])
}
sources {
main {
jni {
dependencies {
project ':Addition' linkage 'static'
}
}
}
}
defaultConfig {
applicationId "com.harkish.nativepluginexample"
minSdkVersion.apiLevel 21
targetSdkVersion.apiLevel 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
}
build.gradle (:加法)
apply plugin: 'com.android.model.native'
model {
android {
compileSdkVersion = 23
buildToolsVersion = '23.0.2'
defaultConfig {
minSdkVersion.apiLevel = 21
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = '1.0'
}
ndk {
moduleName = 'addition'
}
sources {
main {
jni {
source {
srcDir "src"
}
exportedHeaders {
srcDir "src"
}
}
}
}
}
}
有人解决了这个问题吗?想法?