https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
m

martmists

01/25/2023, 4:39 PM
How would I set up Gradle to build the android native targets (arm64, armv7, x86) using kotlin-native rather than cmake?
l

Landry Norris

01/25/2023, 4:44 PM
You can add the androidNative* targets to your build.gradle.kts and create corresponding source sets (I’d create an androidNdkMain source set and add the others as dependsOn). This will allow you to build the binaries for android ndk. From there, there’s not a good gradle way to automatically build and move them, so I usually copy a gradle task I wrote a while back.
Here's an example project where I set this up. I currently have it set to where you have to manually run the task to update the binaries. I just have to run
./gradlew prepareAndroidNdkSo
The native targets take a while to build sometimes and it’s hard to only build the one you need when you click run, so I’d recommend making it a manual process to trigger the prepareAndroidNdkSo task instead of running it every time.
m

martmists

01/25/2023, 9:45 PM
Is there a way to commonize between desktop JNI, android JNI and WASM-interop?
l

Landry Norris

01/25/2023, 9:48 PM
Funny you should ask. I just sat down to start adding that to JniUtils.
As far as I can tell, there's not a good way to do that by default, since the def file is set up for us by the Kotlin toolchain, so I don't think we can configure the packages to match.
23 Views