Kotlin multiplatform standard provides a standard setup for Kotlin multiplatform projects. With this setup, you'll be able to share Kotlin code between Android, JVM and iOS. The code will compile to a platform specific library which you'll be able to distribute via platform specific channels, namely Bintray (Maven) for Android/JVM and CocoaPods for iOS.
The current version still uses the old (outdated) gradle setup. But don't worry, we're working on a new version which uses the new setup ;)
Get started by cloning/forking this repository and checking out the sample implementations.
We included a sample project for Android (samples/android-app
) and iOS (samples/ios-app
) which use the local Kotlin sources making them perfect for your library development.
For Android the samples/android-app
has a dependency on the local library module. Every time you compile this sample app, you'll be using the latest version of the library.
For iOS it is sufficient to open the Xcode project found in samples/ios-app
and building the project. There is a custom build phase run script which will regenerate the MyLibrary.framework
file. Note that if you change the name of your library, you will have to change this in the run script as well.
If you want to publish your library to Bintray and/or CocoaPods, you'll need to make some changes in library/build.gradle
and update the properties to make sure all information matches your specific project and accounts.These properties will be used for both uploading to Bintray and generating a valid Podspec
file. For iOS projects, make sure to run pod install
in the iOS project folder and open the xcworkspace
project.
The easiest way to publish your library on a Maven repository is by using Bintray. Luckily, we already did most of the setup (based on this article) so you'll be able to get started right away!
After creating a Bintray account, you need to add the following properties to your local.properties
file in the root of your project:
bintray.user=USERNAME
bintray.apikey=API_KEY
The next step is preparing your setup on Bintray. Create a new Maven repository (or reuse an existing one) and open up library/build.gradle
.Fill in the name of your newly created repo as bintrayRepo
, update your bintrayOrganisation
if you want to use one (or leave blank), and update bintrayName
with the name of your library on Bintray.Once you're done with that, you can upload the library using the following command:
./gradlew bintrayUpload
Now your library is published on Bintray, and you can start using it.
Creating a Podspec
file is required for publishing a library to CocoaPods. In our setup, gradle will automatically make sure the Podspec
file is kept up-to-date and running any gradle command (like ./gradlew
) will suffice for updating it.
Before uploading the library to CocoaPods, we need to compile our Kotlin sources into a .framework
file first.Run the following command in order to compile your framework file:
./gradlew :library:mylibrary-ios:compileKonan
The framework file will be stored in the outputs
folder in the root of our repository so CocoaPods will be able to use it later on.
Note: If you prefer, you could simply include the framework file in your iOS project too. We recommend a more separated, versioned approach though.
After generating the framework file, you need to commit/push the file to our git repository. Then you should be able to publish it to a spec repo. But before that, it's best to make sure you didn't make any mistakes. Run the lint
command to verify if everything looks ok.
pod spec lint library/ios/MY_LIBRARY.podspec
Note: This command will probably show a note to warn you about the fact that the framework file doesn't include a file for the i386 architecture. This architecture is only used for the 32-bit iOS simulator, all other architectures should work fine.
If everything else looks ok, push your library to your private spec repository via:
pod repo push [repo] library/ios/MY_LIBRARY.podspec
or, push your library to the public spec repository via:
pod trunk push library/ios/MY_LIBRARY.podspec
Great! Now your library is published on CocoaPods and you'll be able to add it to your project via your Podfile
.
For more information about making a CocoaPod, see Making a CocoaPod
We've included a basic setup of Dokka in the project. The latest release at the moment (0.9.17) doesn't support Kotlin/Native yet, so we only generate Android documentation (which includes all the shared code as well).Simply run ./gradlew dokka
to generate documentation. For more advanced configuration, see dokka on GitHub and library/android/build.gradle
.
At November Five, we prefer to work with versioned libraries when sharing code between multiple applications. This way, we can quickly verify and change the versions used in of our applications.
For Kotlin multiplatform, this allows us to make sure both platforms are using the exact same version of our codebase. There are a few other Kotlin multiplatform templates available on GitHub, but for us, they had two problems:
This software is considered Beta.It has been thoroughly tested internally at November Five but not yet used in any live products.
Currently the following releases are planned:
kotlin-multiplatform
plugin has been released.This project is maintained by Arne Stockmans & Vincent de Smet.
Additional information about the project can be found in this blog post.
Got any questions or ideas? We'd love to hear from you. Check out our contributing guidelines for ways to offer feedback and contribute.
Copyright (c) November Five BVBA. All rights reserved.
Licensed under the MIT License.
我正在设置一个静态编程语言多平台项目,以便我可以在多个平台中为单个应用程序重用公共代码。在为应用程序构建公共代码时,我提取了一些基类,我希望能够在多个多平台项目中作为库重用。我正在尝试将库作为依赖项添加到Common Main中。有几件事我不明白。 首先:这目前可能吗? 如果是:默认的 stdlib-common 是 jar 文件,对吗?如果没有Java可以在那里使用,为什么jar可以在commo
下面是我试图用配置autowire的kotlin bean 最后,这是一个常规java bean,它确实用填充,但是当它得到时,我看到这些属性是空的/null
从https://api.spacexdata.com/v3获取日期启动此日期的格式为:2006-03-25T10:30:00+12:00。我想将其转换为“DD,mm,YYYY”,但总是得到错误:“java.time.format.DateTimeParseException:Text'2006-03-25T10:30:00+12:00'could not be parsed,unparsed T
Kotlin/Native The development of Kotlin/Native was moved to https://github.com/JetBrains/kotlin.Because of that, this repository was archived. Instead of creating new issues in this repository or comm
GraphQL Kotlin GraphQL Kotlin is a collection of libraries, built on top of graphql-java, that simplify running GraphQL clients and servers in Kotlin. Visit our documentation site for more details. ��
Pokedex app built with Kotlin Download Go to the releases page to download the latest available apk. Screenshots Development Roadmap Kotlin LiveData Navigation ViewModel Room Coroutines Gradle Kotlin