Skip to content

Latest commit

 

History

History
175 lines (149 loc) · 7.3 KB

MULTIPLATFORM.md

File metadata and controls

175 lines (149 loc) · 7.3 KB

General requirements

  • Java 17 (should be specified in JAVA_HOME)
  • [macOs/Linux] Android SDK downloaded via ./jbdeps/android-sdk/downloadAndroidSdk
  • [Windows] Android SDK downloaded from Android Studio and specified in ANDROID_SDK_ROOT

Developing in IDE

  1. Download Android Studio from the official site (it is mandatory to use the version, written here). As an alternative you can use IDEA, which is compatible with this AGP version, or you can disable Android plugin in IDEA plugins, to develop non-Android targets.
  2. [macOs/Linux] Download Android SDK via ./jbdeps/android-sdk/downloadAndroidSdk
  3. [Windows] Download Android SDK via Android Studio and specify it in ANDROID_SDK_ROOT environment variable. Components, their versions and folder structure should be the same as in downloaded via script ./jbdeps/android-sdk/downloadAndroidSdk SDK for other platforms.
  4. Specify Gradle JVM to use JDK 17 in InteliJ IDEA Preferences (Build, Execution, Deployment -> Build Tools -> Gradle)

Run tests

Run tests for Desktop:

./gradlew desktopTest

Run tests for Web:

./gradlew :mpp:testWeb

Run tests for UIKit:

./gradlew :mpp:testUIKit -PiosSimulatorName='iPhone 15'

API checks

Compose Multiplatform stores all public API in *.api files. If any API is added/changed, ./gradlew checkDesktop will fail with an error that API is changed (it runs on CI). Example:

Execution failed for task ':compose:material3:material3:desktopApiCheck'.
> API check failed for project material3.
  --- D:\Work\compose-multiplatform-core\compose\material3\material3\api\desktop\material3.api
  +++ D:\Work\compose-multiplatform-core\out\androidx\compose\material3\material3\build\api\desktop\material3.api
  @@ -552,6 +552,11 @@
   public abstract interface annotation class androidx/compose/material3/ExperimentalMaterial3Api : java/lang/annotation/Annotation {
   }

  +public final class androidx/compose/material3/FF {
  +     public static final field $stable I
  +     public fun <init> ()V
  +}
  +
   public final class androidx/compose/material3/FabPosition {
        public static final field Companion Landroidx/compose/material3/FabPosition$Companion;
        public static final synthetic fun box-impl (I)Landroidx/compose/material3/FabPosition;

   You can run :material3:apiDump task to overwrite API declarations

To fix this error:

  1. Run ./gradlew desktopApiDump
  2. See what has changed in *.api files.
  3. If there are only additions - there is no binary incompatible change.
  4. If there are some removals - most probably there is a binary incompatible change and it needs to be fixed before merging it to the main branch.

Note that only desktop has API checks at the moment, but in the future it will be added for all targets.

Publishing

Compose Multiplatform core libraries can be published to local Maven with the following steps:

  1. Use these gradle properties to set the published libraries versions

-Pjetbrains.publication.version.CORE_BUNDLE, -Pjetbrains.publication.version.CORE_URI, -Pjetbrains.publication.version.COMPOSE, -Pjetbrains.publication.version.COMPOSE_MATERIAL3_ADAPTIVE, -Pjetbrains.publication.version.LIFECYCLE, -Pjetbrains.publication.version.NAVIGATION, -Pjetbrains.publication.version.SAVEDSTATE, -Pjetbrains.publication.version.WINDOW,

The default value for the version is 0.0.0-SNAPSHOT

And library groups: -Pjetbrains.publication.libraries=CORE_BUNDLE,CORE_URI,COMPOSE,COMPOSE_MATERIAL3_ADAPTIVE,LIFECYCLE,NAVIGATION,SAVEDSTATE,WINDOW

The default value includes all libraries.

  1. Publish core libraries
./gradlew :mpp:publishComposeJbToMavenLocal -Pcompose.platforms=all -Pjetbrains.publication.version.COMPOSE=0.1.0-dev1000 -Pjetbrains.publication.version.LIFECYCLE=0.1.0-dev1000

-Pcompose.platforms=all could be replace with comma-separated list of platforms, such as js,jvm,androidDebug,androidRelease,macosx64,uikit.

  1. Publish extended icons
./gradlew :mpp:publishComposeJbExtendedIconsToMavenLocal -Pcompose.platforms=all --max-workers=1
  1. (Optional) Publish Gradle plugin using instructions to check changes locally.

Run samples

Run jvm desktop samples:

./gradlew :compose:mpp:demo:runDesktop
./gradlew :compose:desktop:desktop:desktop-samples:run1
./gradlew :compose:desktop:desktop:desktop-samples:run2
./gradlew :compose:desktop:desktop:desktop-samples:run3
./gradlew :compose:desktop:desktop:desktop-samples:runSwing
./gradlew :compose:desktop:desktop:desktop-samples:runWindowApi
./gradlew :compose:desktop:desktop:desktop-samples:runVsync
./gradlew :compose:desktop:desktop:desktop-samples:runLayout
./gradlew :compose:desktop:desktop:desktop-samples-material3:runScaffold

Run wasm sample:

./gradlew :compose:mpp:demo:jsRun

Run native macos X64 sample:

./gradlew :compose:mpp:demo:runDebugExecutableMacosX64

Run native macos Arm64 sample:

./gradlew :compose:mpp:demo:runDebugExecutableMacosArm64

Run in KMP Wizard project

  • To use a locally built compose in KMP with Compose wizard project you need to perform some extra steps:-Checkout https://github.com/JetBrains/compose-multiplatform
  • Open gradle-plugins in compose-multiplatform
  • Update gradle.properties by setting compose.version and deploy.version to the version you've published (0.1.0-dev1000 in example above).
  • Run ./gradlew publishToMavenLocal
  • Open components in compose-multiplatform
  • Update gradle.properties by setting compose.useMavenLocal to true and compose.version to the version you've published.
  • Run ./gradlew publishToMavenLocal
  • Open KMP wizard project.
  • Update settings.gradle.kts by adding mavenLocal() to the end of both repositories blocks.
  • Update gradle/libs.versions.toml by setting compose-plugin to the version you've published.
  • Sync gradle, now the project will build with the locally published Compose.

Run mpp/demo-uikit sample on iOS

  • Install plugin Kotlin Multiplatform Mobile for AppCode
  • Disable Android Plugin in IDE preferences
  • Open root of repository with AppCode
  • Increase AppCode IDE memory more that 10GB
  • Restart AppCode
  • Wait while project synchronization with Gradle
  • [Optional] To run on real iOS device
  • Choose run configuration iOS App

Run mpp/demo sample on iOS with Xcode

Run script:

./compose/mpp/demo/regenerate_xcode_project.sh

Wait while Xcode is opening, and press run button.

Clean IDE and Gradle cache

  • Close project
  • ./cleanTempFiles.sh