Skip to main content
  1. About
  2. For Teams
Asked
Viewed 785 times
1

im trying to write JNI app and want to use kotlin in it.

As i understand kotlin equivalent of this:

private static native void hi();

is:

private external fun hi()

but the problemm is that i cant gen .h files with gradle in my project:

compileJava{
    options.headerOutputDirectory.set(file('src/main/java/idk/bluecross/JMM/natives'))
}

how can i do this?

here is my build.gradle by the way:

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.8.0-RC2'
    id 'application'
    id 'cpp'
}

group 'idk.bluecross'
version '1.0-SNAPSHOT'
application.mainClass = 'idk.bluecross.example.Main'

application {
    applicationDefaultJvmArgs +=
            ["-Djava.library.path=" + file("${buildDir}/libs/jMM/shared").absolutePath]
}

compileJava{
    options.headerOutputDirectory.set(file('src/main/java/idk/bluecross/JMM/natives'))
}

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}

model {
    platforms {
        x64 {
            architecture "x86_64"
        }
    }

    components {
        JMM(NativeLibrarySpec) {
            sources {
                cpp {
                    source {
                        srcDir "src/main/java/idk/bluecross/JMM/natives"
                    }
                }
            }
            targetPlatform "x64"
            binaries.all {
                def jvmHome = System.properties['java.home']
                if (targetPlatform.operatingSystem.macOsX) {
                    cppCompiler.args '-I', "${jvmHome}/include"
                    cppCompiler.args '-I', "${jvmHome}/include/darwin"
                    cppCompiler.args '-mmacosx-version-min=10.4'
                    linker.args '-mmacosx-version-min=10.4'
                } else if (targetPlatform.operatingSystem.linux) {
                    cppCompiler.args '-I', "${jvmHome}/include"
                    cppCompiler.args '-I', "${jvmHome}/include/linux"
                    cppCompiler.args '-D_FILE_OFFSET_BITS=64'
                } else if (targetPlatform.operatingSystem.windows) {
                    cppCompiler.args "-I${jvmHome}/include"
                    cppCompiler.args "-I${jvmHome}/include/win32"
                } else if (targetPlatform.operatingSystem.freeBSD) {
                    cppCompiler.args '-I', "${jvmHome}/include"
                    cppCompiler.args '-I', "${jvmHome}/include/freebsd"
                }
            }
        }
    }
}

classes.dependsOn 'JMMSharedLibrary'
1

0

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.