![]() ![]() It takes a C library and generates the corresponding Kotlin bindings, so that the library can be used as if it were Kotlin code. This is when the cinterop tool comes in handy. Kotlin/Native is already shipped with a set of prebuilt platform libraries, which provide some additional common functionality to the standard library.Īn ideal scenario for interop is to call C functions as if you are calling Kotlin functions, following the same signature and conventions. Kotlin/Native helps consume standard C libraries, opening up an entire ecosystem of functionality that exists for pretty much anything you may need. When writing native applications, you often need access to certain functionalities that are not included in the Kotlin standard library, such as making HTTP requests, reading and writing from disk, and so on. You may want to import the whole package in. By default, all the symbols from C are imported to the interop package. These can be left as default values.Ĭ interoperability is configured as an additional step in the build. The entry itself defines a series of properties to indicate how the binary is generated and the entry point of the applications. See the complete list of supported platforms. Targets are defined using macOSX64, macosArm64, linuxX64, linuxArm64, and mingwX64 for macOS, Linux, and Windows. HostOs = "Linux" & !isArm64 -> linuxX64("native")Įlse -> throw GradleException("Host OS is not supported in Kotlin/Native.") HostOs = "Linux" & isArm64 -> linuxArm64("native") HostOs = "Mac OS X" & !isArm64 -> macosX64("native") ![]() HostOs = "Mac OS X" & isArm64 -> macosArm64("native") Val isMingwX64 = hostOs.startsWith("Windows") Val isArm64 = System.getProperty("os.arch") = "aarch64" Val hostOs = System.getProperty("os.name") Pay special attention to the following in the build file: Open the file, the build script that contains the project settings. For this tutorial, keep the folder structure as is. Your code is placed in the nativeMain directory with a corresponding nativeTest. It's important to understand that an application written in Kotlin/Native can target different platforms if the code does not have platform-specific requirements. ![]() The template includes a project with the files and folders you need to get you started. Before you startĭownload and install the latest version of IntelliJ IDEA with the latest Kotlin plugin.Ĭlone the project template by selecting File | New | Project from Version Control in IntelliJ IDEA. Kotlin/Native can use the Gradle build system through the kotlin-multiplatform plugin. ![]() In this case, it is better to use the Kotlin/Native compiler with a build system, as it helps download and cache the Kotlin/Native compiler binaries and libraries with transitive dependencies and run the compiler and tests. bat file), this approach doesn't scale well for big projects with hundreds of files and libraries. While it is possible to use the command line, either directly or by combining it with a script file (such as a. The output will be an executable command-line app that you can run on macOS and Linux and make simple HTTP GET requests. You'll learn how to create a simple HTTP client that can run natively on specified platforms using Kotlin/Native and the libcurl library. This tutorial demonstrates how to use IntelliJ IDEA to create a command-line application. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |