anytime I add a implementation(project (":mycpplib...
# gradle
b
anytime I add a implementation(project (":mycpplib")) I get a No variant found. And I'm struggling to find examples of people doing kotlin and JNI where everything is built with gradle
b
That's because kotlin doesn't have cpp interop
b
yes I'm using cpp-library, but it is really a c program
(I force the compiler to take it as a c file)
b
Did you setup cinterop, then?
b
not at all I'm just using JNI
let me push the last version
I can't push a binary lib it depends on though as it is proprietary , so I don't think you'll be able to build
(it works beautifuly for what I wrote it for, but I would ideally want it to build and package properly)
b
Then you don't need to add your cpp project as dependency
Since kotlin cannot understand it
b
hmm but how do I tell gradle to build it as the project depends on it?
n
Since your project is using Kotlin JVM the C interop will be very difficult to implement. If the project was using Kotlin Native then C interop would be very easy to implement.
b
my Kotlin code is already calling my C code…
and it works
my problem is that my Kotlin gradle task cannot say it depends on the C gradle task…
I think I was not clear enough, lets summarize: • The kotlin code can call the C code through JNI that works perfectly • Gradle can build the C library (using cpp-library) (a sub project) • Gradle can build the Kotlin program (a sub project) • Gradle does not allow me to add the C library project as a dependency of the Kotlin project
g
It's correct, you cannot just add module with c code as dependency to JVM library, it will not work, because Kotlin/java plugin doesnt know how to work with such dependencies. What you really want is to set c compilation task as dependency of Kotlin compilation (or maybe better jar creation) task, so not dependencies between modules, but between task
👍 1
You probably need a custom task to copy resulting binaries
👍 1
b
ok that make sense, thanks. I think I found how to do that in gradle.
g
I found how to do that in gradle
You can set dependencies between tasks with
dependsOn
b
yes that's what I needed exactly, thanks.