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.26k stars 1.18k forks source link

iOS/Android template fails to run due to `error: no such module 'shared'` #3190

Closed tahoeschrader closed 1 month ago

tahoeschrader commented 1 year ago

Describe the bug I downloaded the iOS/Android template repo and can successfully build for android. iOS on the other hand is returning:

/Projects/compose-multiplatform-ios-android-template/iosApp/iosApp/ContentView.swift:3:8: error: no such module 'shared'
import shared

My version of cocoapods is 1.12.1 and I installed it via brew at /opt/homebrew/bin/pod

Affected platforms Select one of the platforms below:

Versions

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

  1. Open Edit Configurations -> ios Application -> iosApp
  2. Choose iosApp/iosApp.xcodeproj as the Xcode Project FIle -> Apply -> OK
  3. Run iosApp
  4. See error

After this I also tried:

cd iosApp
pod cache clean --all
pod install

Then I tried deleting all the build folders, building the android app first, then iOS. No matter what I do or what order I try it, I get this error.

Expected behavior The iOS simulator should open up a virtual iPhone with the template app, aka no build errors.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Sometimes, rather than the error being re: shared it is that Main_iosKt doesn't exist in the space... which is an error I see in some recently closed issues for this project. The only problem is the "fix" was to run something that is supposed to work for iOS, which I am currently doing.

tahoeschrader commented 1 year ago

After restarting my computer, the error is now the missing Main_iosKt one:

/Projects/compose-multiplatform-ios-android-template/iosApp/iosApp/ContentView.swift:7:9: error: cannot find 'Main_iosKt' in scope
        Main_iosKt.MainViewController()

Where is it even defined that the name of the package should be "Main_iosKt"? Is that just what main.ios.kt gets converted to under the hood? Either way, any help would be appreciated.

jnelle commented 1 year ago

Hey @tahoeschrader,

I think you missed the following steps:

https://kotlinlang.org/docs/multiplatform-mobile-integrate-in-existing-app.html#create-an-ios-project-in-xcode

tahoeschrader commented 1 year ago

Hey @tahoeschrader,

I think you missed the following steps:

https://kotlinlang.org/docs/multiplatform-mobile-integrate-in-existing-app.html#create-an-ios-project-in-xcode

Hm, I see. A lot of documentation I've found online imply xcode will be called from Android Studio via the cli though. Especially considering this official template already has the xcode project files and whatnot already included.

I was under the impression i'd only need to do the step you're linking for a brand new multiplatform project id be writing from scratch without building off this template.

ronjunevaldoz commented 1 year ago

@tahoeschrader I have experience this error using the project template after corrupting the gradle.

I recommend you to re-download the gradle by removing the current caches rm -rf ~/.gradle/caches/

b0r1ngx commented 1 year ago

Now its is fixed if you using Kotlin Multiplatform Wizard: https://kmp.jetbrains.com/?_gl=1*1ds9oqm*_ga*MzUzNzc0NzEuMTY5MjYxMjIxMA..*_ga_9J976DJZ68*MTY5OTAxNTg2NC4yMC4xLjE2OTkwMTc3MzcuMC4wLjA.&_ga=2.23061945.388460062.1699015864-35377471.1692612210

When open iosApp as Xcode project, make sure that you first build it in Android Studio, and then also build in Xcode, after that any errors of Xcode project must not appear and u can run project on any of you devices!

okushnikov commented 4 months ago

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