JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.39k stars 1.18k forks source link

Unknown iOS platform: 'macosx' - Compose 1.5 #3617

Closed vinceglb closed 1 year ago

vinceglb commented 1 year ago

Describe the bug I have created a macOS target in my Compose Multiplatform project. When I build my app for that macOS target, I have an error: Unknown iOS platform: 'macosx'. It works well when I build for the default iOS target. It worked well when I was using Compose 1.4 but after upgrading to 1.5, the error happened.

Affected platforms macOS

Versions

To Reproduce Steps and/or the code snippet to reproduce the behavior:

  1. Create a Compose Multiplatform project using this template with Compose 1.5
  2. Go to Xcode and open the iosApp.xcodeproj of the project.
  3. Create a new macOS target.
  4. Copy the content of iOSApp.swift and paste it in the macOS.swift file.
  5. Select the new macOS target, select your device in the top Xcode selector and try to launch it.
  6. Error happened.

Expected behavior Should work like with Compose 1.4

Screenshots

image

Additional context Here is the log of the error:

Run custom shell script 'Compile Kotlin' 38.9 seconds

> Configure project :shared
w: file:///Users/vincent/AndroidStudioProjects/Teleport/shared/build.gradle.kts:73:13: Variable 'commonTest' is never used
w: file:///Users/vincent/AndroidStudioProjects/Teleport/shared/build.gradle.kts:98:13: Variable 'androidMain' is never used
w: file:///Users/vincent/AndroidStudioProjects/Teleport/shared/build.gradle.kts:120:13: Variable 'appleMain' is never used
w: file:///Users/vincent/AndroidStudioProjects/Teleport/shared/build.gradle.kts:135:13: Variable 'macosMain' is never used
w: file:///Users/vincent/AndroidStudioProjects/Teleport/shared/build.gradle.kts:143:13: Variable 'desktopMain' is never used
Configuration 'kspKotlinMacosArm64ProcessorClasspath' was resolved during configuration time.
This is a build performance and scalability issue.
See https://github.com/gradle/gradle/issues/2298
Run with --info for a stacktrace.

> Task :shared:generateAppleMainNonAndroidBuildConfig UP-TO-DATE
> Task :shared:generateGeneratedByKspKotlinMacosArm64NonAndroidBuildConfig UP-TO-DATE
> Task :shared:generateMacosArm64MainNonAndroidBuildConfig UP-TO-DATE
> Task :shared:generateMacosMainNonAndroidBuildConfig UP-TO-DATE
> Task :shared:generateNativeMainNonAndroidBuildConfig UP-TO-DATE
> Task :shared:generateNonAndroidBuildConfig UP-TO-DATE

> Task :shared:kspKotlinMacosArm64
note: [ksp] loaded provider(s): [com.rickclephas.kmp.nativecoroutines.ksp.KmpNativeCoroutinesSymbolProcessorProvider]

> Task :shared:compileKotlinMacosArm64
warning: Opt-in requirement marker androidx.compose.material3.ExperimentalMaterial3Api is unresolved. Please make sure it's present in the module dependencies
warning: Opt-in requirement marker com.google.accompanist.permissions.ExperimentalPermissionsApi is unresolved. Please make sure it's present in the module dependencies

> Task :shared:linkDebugFrameworkMacosArm64
warning: Cannot infer a bundle ID from packages of source files and exported dependencies, use the bundle name instead: shared. Please specify the bundle ID explicitly using the -Xbinary=bundleId=<id> compiler flag.

> Task :shared:assembleDebugAppleFrameworkForXcodeMacosArm64
> Task :shared:syncComposeResourcesForIos FAILED
error: Unknown iOS platform: 'macosx'

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shared:syncComposeResourcesForIos'.
> Unknown iOS platform: 'macosx'

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 39s
11 actionable tasks: 5 executed, 6 up-to-date

> Configure project :shared
w: file:///Users/vincent/AndroidStudioProjects/Teleport/shared/build.gradle.kts:73:13: Variable 'commonTest' is never used
w: file:///Users/vincent/AndroidStudioProjects/Teleport/shared/build.gradle.kts:98:13: Variable 'androidMain' is never used
w: file:///Users/vincent/AndroidStudioProjects/Teleport/shared/build.gradle.kts:120:13: Variable 'appleMain' is never used
w: file:///Users/vincent/AndroidStudioProjects/Teleport/shared/build.gradle.kts:135:13: Variable 'macosMain' is never used
w: file:///Users/vincent/AndroidStudioProjects/Teleport/shared/build.gradle.kts:143:13: Variable 'desktopMain' is never used
Configuration 'kspKotlinMacosArm64ProcessorClasspath' was resolved during configuration time.
This is a build performance and scalability issue.
See https://github.com/gradle/gradle/issues/2298
Run with --info for a stacktrace.

> Task :shared:generateAppleMainNonAndroidBuildConfig UP-TO-DATE
> Task :shared:generateGeneratedByKspKotlinMacosArm64NonAndroidBuildConfig UP-TO-DATE
> Task :shared:generateMacosArm64MainNonAndroidBuildConfig UP-TO-DATE
> Task :shared:generateMacosMainNonAndroidBuildConfig UP-TO-DATE
> Task :shared:generateNativeMainNonAndroidBuildConfig UP-TO-DATE
> Task :shared:generateNonAndroidBuildConfig UP-TO-DATE
> Task :shared:kspKotlinMacosArm64
> Task :shared:compileKotlinMacosArm64
[ksp] loaded provider(s): [com.rickclephas.kmp.nativecoroutines.ksp.KmpNativeCoroutinesSymbolProcessorProvider]
Opt-in requirement marker androidx.compose.material3.ExperimentalMaterial3Api is unresolved. Please make sure it's present in the module dependencies

> Task :shared:linkDebugFrameworkMacosArm64
Opt-in requirement marker com.google.accompanist.permissions.ExperimentalPermissionsApi is unresolved. Please make sure it's present in the module dependencies

> Task :shared:assembleDebugAppleFrameworkForXcodeMacosArm64
> Task :shared:syncComposeResourcesForIos FAILED
Cannot infer a bundle ID from packages of source files and exported dependencies, use the bundle name instead: shared. Please specify the bundle ID explicitly using the -Xbinary=bundleId=<id> compiler flag.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shared:syncComposeResourcesForIos'.
> Unknown iOS platform: 'macosx'

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 39s
11 actionable tasks: 5 executed, 6 up-to-date
Unknown iOS platform: 'macosx'
m-sasha commented 1 year ago

Hi. Can you be more specific about the reproduction steps, or share a complete reproducer project?

I was able to run a macOS target in Compose 1.5.0 by:

  1. Check out the template project and following the instructions from: https://github.com/JetBrains/compose-multiplatform-ios-android-template/
  2. Open XCode and open the iosApp project in it.
  3. Duplicate and rename the iosApp target in XCode:
image
  1. Rename the bundle identifier to match my team id.
  2. Select "macosApp -> My Mac (designed for iPad)" target at the top in XCode.
  3. Press the "play" button in XCode

The result is:

image
vinceglb commented 1 year ago

Sure! I found an easier setup to reproduce the problem:

  1. Check out the template project and following the instructions from: https://github.com/JetBrains/compose-multiplatform-ios-android-template/
  2. Open XCode and open the iosApp project in it.
  3. Open the iosApp Target and go to "Supported Destinations"
  4. Remove "Mac (Designed for iPad)" from the list and add "Mac"
  5. Select "iosApp -> My Mac" target at the top in XCode.
  6. Press the "play" button in XCode

image

Here is a reproducer project if you want, you just need to press play on XCode: https://github.com/EBfVince/compose-multiplatform-macosx-bug

I want to target the macOS SDK to be able to access MenuBarExtra.

m-sasha commented 1 year ago

Are you sure this (SDK=macOS) worked before with Compose 1.4?

elijah-semyonov commented 1 year ago

@EBfVince I'm not sure how that could work in the first place. iOSApp.swift is using UIViewControllerRepresentable transitively, which doesn't exist in macOS SDK.

vinceglb commented 1 year ago

Yes, you're right: using the compose plugin with macOS SDK should not work at all.

After some investigation, I realized that I had managed to get the compose plugin working with macOS SDK and Compose 1.4 using a dubious workaround. With Compose 1.5, this solution no longer works. I thought it was a bug, but it is just the expected behavior.

Thank you for your time. I close the issue.

vinceglb commented 1 year ago

@m-sasha, @elijah-semyonov If you are curious to reproduce the behavior I was talking about:

LionZXY commented 3 months ago

@vinceglb Did you eventually find a way to use MenuBarExtra with Compose Multiplatform?

vinceglb commented 3 months ago

Unfortunately I did not continue my investigations. But it seems doable using JNA to call native macOS API from Kotlin. I've done something similar to access native macOS file picker with Kotlin : here is an example

okushnikov commented 3 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.