简体   繁体   English

您如何设置Kotlin多平台构建?

[英]How do you set up a Kotlin multi-platform build?

I'd like to build the same kotlin source code into javascript and java (android). 我想将相同的kotlin源代码构建为javascript和java(android)。 Is there a standard way to achieve this? 是否有实现此目的的标准方法?

Official multi-platform support for Kotlin hasn't been released yet. 尚未发布对Kotlin的官方多平台支持。 If you'd like to stay up to date on it I reccomend following the #multiplatform channel on the Kotlin Slack . 如果您想了解最新消息,建议您遵循Kotlin Slack上的#multiplatform频道

  1. Create a project in IntelliJ. 在IntelliJ中创建一个项目。 Select a Gradle project and then Java (and whatever else you want) 选择一个Gradle项目,然后选择Java(以及您想要的其他任何东西)

IntelliJ新项目菜单

  1. Create 3 new Gradle modules: common , android-specific and js-specific . 创建3个新的Gradle模块: commonandroid-specificjs-specific Make sure they are added as module to your main module 确保将它们作为模块添加到您的主模块中

添加新模块

添加新模块第2部分

  1. Press next, then finish (and repeat for android-specific and js-specific ) 按下一步,然后完成(并针对android-specificjs-specific重复此操作)
  2. Remove settings.gradle from common , and the other 2 modules as you aren't going to need them common和其他2个模块中删除settings.gradle ,因为您将不需要它们
  3. Make sure these 3 new modules are added to the main "parent" module's settings.gradle . 确保将这3个新模块添加到主“父”模块的settings.gradle It should look more less like this: 它看起来应该更像这样:

     rootProject.name = 'parent' include ':common' include ':android-specific' include ':js-specific' 
  4. Edit common 's module dependency ( build.gradle file, line 24 for me ) from org.jetbrains.kotlin:kotlin-stdlib-jre8 to org.jetbrains.kotlin:kotlin-stdlib so it's not platform-specific. org.jetbrains.kotlin:kotlin-stdlib-jre8org.jetbrains.kotlin:kotlin-stdlib编辑common的模块依赖项( build.gradle文件,第24行,对我来说 ),因此它不是特定于平台的。
  5. If you really want to be sure you've done everything right go to View -> Tool Windows -> Gradle 如果您真的想确定自己已正确完成所有操作,请转到视图->工具窗口-> Gradle

查看->工具窗口-> Gradle

  1. You should see the Gradle menu and it should look like this 您应该看到Gradle菜单,它应该看起来像这样

它应该是什么样子

The gradle config should also work without IntelliJ (or Android Studio) but I didn't test it gradle配置也可以在没有IntelliJ(或Android Studio)的情况下使用,但我没有对其进行测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM