Does anyone knows how the includes of srcDir works in gradle experimental files (cpp AND h)? This is kind of a "3-fold" question:
1°) how do the srcDir work?
1.a°) Does it include recursively all subdirs? Does it only include files at their deep level? Does it they include all cpp/c/cc/cxx files?
for example this command:
android.sources {
main {
jni {
source {
srcDir "../../../../some/path/src"
}
}
}
}
Does it include all cpp files under src? all files under src? all cpp files recursively into subdirs? all files recursively into subdirs?
The google documentation is very vague:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental
and the gradle one is not clear either:
https://docs.gradle.org/current/userguide/nativeBinaries.html
It says it only includes src/${name}/cpp ? what does it mean? Do I have to create a
../../../../some/path/src/cpp
folder?
1.b°) What about the headers:
android.sources {
main {
jni {
exportedHeaders {
srcDir "../../../../some/path/src"
}
}
}
}
I have the feeling that the srcDir directive applied on headers works differently than the srcDir for source (it includes only the headers of its current depth)
2°) What if I want a mix between file and dir?
android.sources {
main {
jni {
source {
srcDir "../../../../some/path/src"
srcFile "../../../../some/path/src/myFile.cpp"
}
}
}
}
doesn't seem to work
3°) how does the include/ exclude directive works?
What about the include/exclude directive, does they apply only on the previous srcDir statement? Or do they apply on all the statement of the "source" block?
doing:
android.sources {
main {
jni {
source {
srcDir "../../../../some/path/src"
include "*.cpp"
}
}
}
}
doesn't seem to include any cpp file. I thought it would include all cpp files of this folder hierarchy, or even all cpp files under src, but it looks like it doesn't.
I want to point that I am using gradle 2.9, which is required by the latest gradle-experimental-0.6.0-alpha3 plugin.
I can at least answer my first point. After digging through the sources (at some point it becomes the best documentation), I found the implementation of the methods that retrieves sources:
in DefaultSourceDirectorySet.java.
this method is used in the gradle-eperimental plugin to retrieve cpp AND c sources:
in execute method from the NdkConfiguration.java file.
For the header, it's different, there is no such things as source.getSource().include("**/*.H");
, instead we have:
In the execute method of the NdkComponentModelPlugin.java. It uses directly the getSrcDirs method of the default gradle implementation, which include recursively all dir under the given one
I will keep on investigating the other points
EDIT: In summary:
1°) a°) srcDir includes all file matching the pattern: *.C, *.CPP, *.c++, *.cc, *.cp, *.cpp, *.cxx
b°) includeHeaders works, and only include the header at the given folder depth (so you have to give all the subpath to the header if you are including them like this: #include "test.h", instead of #include "dir1/dir2/dir3/test.h"
2°) it looks I was doing some things wrong in my includes, as they now do seem to work. However, you can't just include files. It is thus better to include top dir of source file, and then exclude every file that doesn't match a given pattern (as described in Alex Cohn answer)
3°) The include directive doesn't work
For v. 0.4.0
srcDirs
includes all subdirectories andexclude
works on patterns. I don't know about plans to enableinclude
orsrcFile
.See also https://stackoverflow.com/a/32640823/192373
Even for 0.6.0 the docs don't speak about
exportedHeder
, and generally speaking the gradle native docs are not relevant for Android plugin.