C/C++: How to locate and include jni.h file

I need to include jni.h, which is in different locations depending on the installation and/or the platform (Linux/Windows/Mac). How does one search and include this elusive header file?

My build.gradle file:

apply plugin: 'c'
apply plugin: 'cpp'
  task wrapper(type: Wrapper) {
    gradleVersion = '1.10-rc-1'
}
  libraries {
    'libhbase-jni' {
        binaries.withType(SharedLibraryBinary)
    }
}
  sources {
    'libhbase-jni' {
        cpp {
            source {
                srcDirs "src/jni_impl"
                include "*.cc"
            }
            exportedHeaders {
                srcDirs "include"
                include "**/*.h"
            }
        }
        c {
            source {
                srcDirs "src/common"
                include "*.c"
            }
            exportedHeaders {
                srcDirs "include"
                include "**/*.h"
            }
        }
    }
}

There’s not a good way to do this presently. We’re actively working on better support for pre-built libraries, which will better support this use case.

For now your best option is likely to use the fact that this configuration is actually groovy code: detect the operating system and select the correct include directory. The very simple way is:

def findJniHeader() {
    def osName = System.properties['os.name']
    switch (osName) {
        case: 'windows'
             return ...
    ...
}
  cpp {
    exportedHeaders {
        srcDir findJniHeader()
    }
}

Alternatively, you might want to start to define the supported platforms in your build script. You could then define different source sets for different operating systems, and use ‘binary.targetPlatform.operatingSystem’ to selectively include the correct source set in your binary. The ‘native-binaries/assembler’ and ‘native-binaries/variants’ samples should point you in the right direction.

Sorry to revive this thread, but… has this been improved in the last months?

Unfortunately, not for me. I eventually had to give up.