Native prebuilt library: platform-specific headers

Hi, I’m trying to find a way to specify different headers for a prebuilt library depending on target platform.
According to the sample from samples/native-binaries/prebuilt I can set sharedLibraryFile for a binary, but headers property seems to be read-only and can only be set globally for a library.
Simple example is java JNI API which has different headers for different operating systems.
Ideally I would expect something like this to work:

model {
    repositories {
        libs(PrebuiltLibraries) {
            jni {
                headers.srcDir "${javaHome}/include"

                binaries.all {
                    if (targetPlatform.operatingSystem.linux) {
                        headers.srcDir "${javaHome}/include/linux"
                    } else if (targetPlatform.operatingSystem.macOsX) {
                        headers.srcDir "${javaHome}/include/darwin"
                    } else if (targetPlatform.operatingSystem.windows) {
                        headers.srcDir "${javaHome}/include/win32"
                    }
                }
            }
        }
    }
}

But currently it always adds headers for all platforms beacuse headers property is not definned in binary, and gradle uses global headers property from library.

1 Like

Anyone?
I found another thread with the same question. With no answer unfortunately

I moved this to ‘Bugs’ category, can someone of gradle devs take a look?

I have exactly the same issue. As a workaround I added platform-specific headers lookup path to compiler options of executable but this really looks dirty. We definitely need support of platform-specific headers for prebuilt libraries.

1 Like

Hi zgmnkv,

Did you ever come up with a solution for this? I have hit the same problem and a quick search is not showing up anything useful.

Thanks,
Shaun