Here we come, simply announce the official release of Compose for iOS Alpha

Here we come, looking forward to the stars and the moon, the long-awaited Jetpack Compose Multiplatform for iOS has finally officially released Alpha support recently . " and other articles have said many times that Compose Multiplatform is about to support iOS, but now it has finally come and completed the last screen for Compose Multiplatform .

In fact, last month JetBrains made some " major adjustments " to Compose Multiplatform, compose-jb "died 3 years old", compose-jb officially changed its name to compose-multiplatform , and provided template projects for different platforms, and this update , including compose-multiplatform-ios-android-template .

In addition, compose-multiplatform version 1.4.0 is also released following iOS support , that is, those who want to experience iOS need to try early adopters in version 1.4 , and start to support JDK 17 like the new version of Android Studio Flamingojpackage , because it is built and used , it will be used for this purpose JDK 17 :

  • JAVA_HOMEThe environment variable points to a compatible JDK version.
  • javaHomeSetup via DSL:
compose.desktop {
  application {
      javaHome = System.getenv("JDK_17")
  }
}
复制代码

Well, now you can officially use Kotlin to write a similar iOS UI, and have a development experience similar to Swift-UI (say goodbye to XML), and the existing Compose project can also be more easily compiled into an iOS application to realize the UI and logic sharing.

There is no productivity improvement.

At present, iOS support is still in the Alpha stage. If it is not in the beta stage, there may be some changes in API and compatibility , but as the officially released version, you can already start to experience using the same Kotlin code to compile the same Android and iOS interfaces. .

Of course, since KMM (Kotlin Multiplatform Mobile) already supports the iOS platform, and Compose Multiplatform is built on the basis of KMM, there is no big problem in supporting iOS native APIs, such as Bluetooth and cameras, and at the same time Native UI views such as embedded MKMapView are now also supported .

If you want to try iOS on Compose Multiplatform, you must first need a macOS computer, and then you must have:

  • Xcode
  • Android Studio
  • KMM plugin (plugin according to Android Studio)
  • CocoaPods (iOS package manager)

At the same time, you need to brew install kdoctorinstall KDoctor first , because KDoctor is a necessary command line tool under KMM, and KDoctor can also detect whether the build environment is normal.

接下来,如果使用 compose-multiplatform-ios-android-template ,在你的 Compose Multiplatform 项目会包括三个模块: androidApp 、iosApp 和 shared,其中 shared 故名思义就是共享的 Kotlin module :

  • shared 包含 Android 和 iOS 上的通用的代码,也就是平台共享的部分,也是正常开发的 module 目录,比如入口 shared/src/commonMain/kotlin/App.kt ,改模块会被编译成 Android library 和 iOS framework 。
  • androidApp 和 iosApp 就是支持变异为 App 的应用模块。

而目前要在 Android Studio 的 iOS 模拟器上运行 Compose Multiplatform,会需要在 iosApp 的运行配置上进行选择,主要是选择对应的 Execution target:

如果是需要运行到真机,那么首先你要有一个 iOS 开发者账号,然后登陆到你的 Xcode 上:

  • 获取你账号下的 TEAM_ID
  • 接入真机,在 Xcode 中注册的 iOS 设备

另外可以在终端运行 kdoctor --team-ids 来获取你当然的 Team Id 列表,当然,官方也表示如果 KDoctor 没起到作用,你还是需要打开 iosApp/iosApp.xcworkspace ,然后在 Signing & Capabilities 这个 Tab 下去选择和获取你的 Team 。

注意需要在现在 Xcode 上登录开发者账号,当然你不想登陆也可以,不过更麻烦,可以直接用生成的 p12 证书和 mobileprovision 文件,可参考《搭建 iOS 命令行服务打包发布全保姆式流程》 ,不过我想你们应该不会喜欢。

运行 iOS 之前需要设置上面说到的 TEAM_ID,可以打开 iosApp/Configuration/Config.xcconfig 文件下设置 TEAM_ID ,之后在 Android Studio 中重新打开项目,这时候就可以在 iosApp 的运行配置中看到已注册的 iOS 真机。

其次可以看到上面的 Config.xcconfig 文件下有多个配置信息:

  • APP_NAME:简单理解是应用名
  • BUNDLE_ID:类似 Application ID ,注意这个很重要,属于唯一标识应用,和 Andorid 随意折腾 application id 不同,请注意测试时,不要随便在临时账号上测试 Bundle ID, 因为被「登记」过的 Bundle ID 无法重复,要「找回」和「删除」是很麻烦(bu ke neng)的事情。
  • TEAM_ID:Apple 生成给你开发者账号的团队的唯一标识,因为运行 App 到真机需要证书和描述文件,而 team ID 就是证书简介中的对应组织单位

打开 Xcode ,登陆开发者账号,插上 iOS 真机,自动注册设备和同步证书与描述文件,是最简单的流程

如果在 Android Studio 中打开项目后,还需要更改上面的对应选项,目前还需要:

  • 在 Android Studio 中关闭项目。
  • 在的终端中运行 template 目录下的 ./cleanup.sh
  • 更改设置。
  • Open the project again in Android Studio.

The above introduction is mainly from the official compose-multiplatform-ios-android-template and has been supplemented. It may be that for many android development, the configuration of the iOS environment is still relatively unfamiliar, so now Compose Multiplatform for iOS is the best for you to get in touch with iOS Chance.

Therefore, without Flutter, with the support of Kotlin and Compose Multiplatform, Android development has once again launched an assault on the iOS territory , and Compose Multiplatform after complementing iOS has officially realized its promise of full platform support.

Let us look forward to the day when Compose Multiplatform for iOS is officially released.

Guess you like

Origin juejin.im/post/7221800875743182907