A: Define top level function fun main(args: Array<String>)
, please ensure it's not
in a package. Also compiler switch -entry
could be use to make any function taking
Array<String>
and returning Unit
be an entry point.
A: Kotlin/Native provides automated memory management scheme, similar to what Java or Swift provides. Current implementation includes automated reference counter with cycle collector to collect cyclical garbage.
A: Use -produce dynamic
compiler switch, or konanArtifacts { dynamic('foo') {} }
in Gradle.
It will produce platform-specific shared object (.so on Linux, .dylib on macOS and .dll on Windows targets) and
C language header, allowing to use all public APIs available in your Kotlin/Native program from C/C++ code.
See samples/python_extension
as an example of using such shared object to provide a bridge between Python and
Kotlin/Native.
A: Use -produce static
compiler switch, or konanArtifacts { static('foo') {} }
in Gradle.
It will produce platform-specific static object (.a library format) and C language header, allowing to
use all public APIs available in your Kotlin/Native program from C/C++ code.
A: As Kotlin/Native need to download platform specific toolchain, you need to specify
-Dhttp.proxyHost=xxx -Dhttp.proxyPort=xxx
as compiler's or gradlew
arguments,
or set it via JAVA_OPTS
environment variable.
A: Use -module_name
compiler option or matching Gradle DSL statement, i.e.
framework("MyCustomFramework") {
extraOpts '-module_name', 'TheName'
}
A: It likely happens, because you are trying to mutate a frozen object. Object could transfer to the
frozen state either explicitly, as objects reachable from objects on which konan.worker.freeze
is called,
or implicitly (i.e. reachable from enum
or global singleton object - see next question).
A: Currently, singleton objects are immutable (i.e. frozen after creation), and it's generally considered
a good practise to have global state immutable. If for some reasons you need mutable state inside such an
object, use @konan.ThreadLocal
annotation on the object. Also konan.worker.AtomicReference
class could be
used to store different pointers to frozen objects in a frozen object and atomically update those.
A: We release dev builds frequently, usually at least once a week. You can check the list of available versions. But in the case we recently fixed an issue and you want to check before a release is done, you can do:
For the CLI, you can compile using gradle as stated in the README (and if you get errors, you can try to do a ./gradlew clean
):
./gradlew dependencies:update
./gradlew dist distPlatformLibs
You can then set the KONAN_HOME
env variable to the generated dist
folder in the git repository.
For Gradle, you can use Gradle composite builds like this:
# Set with the path of your kotlin-native clone
export KONAN_REPO=$PWD/../kotlin-native
# Run this once since it is costly, you can remove the `clean` task if not big changes were made from the last time you did this
pushd $KONAN_REPO && git pull && ./gradlew clean dependencies:update dist distPlatformLibs && popd
# In your project, you set have to the konan.home property, and include as composite the shared and gradle-plugin builds
./gradlew check -Pkonan.home=$KONAN_REPO/dist --include-build $KONAN_REPO/shared --include-build $KONAN_REPO/tools/kotlin-native-gradle-plugin