Cannot find 'MainViewControllerKt' in scope
Hello,
I have implemented Moko Resources in my Jetpack Compose Multiplatform module, following the guide in the readme. Everything is working smoothly on Android, but somehow I get an error when building the iOS app.
I have set up these scripts (I am using the regular framework):
"$SRCROOT/../gradlew" -p "$SRCROOT/../" :composeApp:copyFrameworkResourcesToApp \
-Pmoko.resources.PLATFORM_NAME="$PLATFORM_NAME" \
-Pmoko.resources.CONFIGURATION="$CONFIGURATION" \
-Pmoko.resources.ARCHS="$ARCHS" \
-Pmoko.resources.BUILT_PRODUCTS_DIR="$BUILT_PRODUCTS_DIR" \
-Pmoko.resources.CONTENTS_FOLDER_PATH="$CONTENTS_FOLDER_PATH"
"$SRCROOT/../gradlew" -p "$SRCROOT/../" :composeApp:copyResourcesDebugExecutableIosSimulatorArm64 \
-Pmoko.resources.BUILT_PRODUCTS_DIR=$BUILT_PRODUCTS_DIR \
-Pmoko.resources.CONTENTS_FOLDER_PATH=$CONTENTS_FOLDER_PATH
The error I get is: Cannot find 'MainViewControllerKt' in scope
My ContentView.swift file looks like this, that's where the error comes from:
import UIKit
import SwiftUI
import ComposeApp
struct ComposeView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
MainViewControllerKt.MainViewController()
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
struct ContentView: View {
var body: some View {
ComposeView()
.ignoresSafeArea(.keyboard)
}
}
Needless to say that the MainViewController.kt file is set up correctly, otherwise it wouldn't work without Moko.
When I roll back to a state where MokoResources was not included in the project, everything works fine.
I am pretty sure that there's an oversight somewhere on my side, but I've been through many tries and still can't get it right.
Could you please help me?
I am getting the same error: Cannot find 'MainViewControllerKt' in scope
Although, i am only getting it when i have set up the source sets in the build.gradle.kts like so:
sourceSets {
getByName("androidMain").dependsOn(commonMain.get())
getByName("desktopMain").dependsOn(commonMain.get())
getByName("iosArm64Main").dependsOn(commonMain.get())
getByName("iosX64Main").dependsOn(commonMain.get())
getByName("iosSimulatorArm64Main").dependsOn(commonMain.get())
}
(I have added those to solve another issue related to building for JVM.)
I tried to use only the getByName("desktopMain").dependsOn(commonMain.get()), but the result is the same: Cannot find 'MainViewControllerKt' in scope
When not using any dependsOn(commonMain.get()), i can build without issues.
Now, @piet90, do you have the dependsOn set up too? If not, there may be some deeper issue.
Thank you @FrancescoBottino for your reply.
Indeed, I have the dependsOn calls, but I added them to solve this issue: https://github.com/icerockdev/moko-resources/issues/618
Is there a workaround here?
@piet90 Using version 0.24.0-alpha-4 solved the issue. Take a look into the releases and to PR https://github.com/icerockdev/moko-resources/pull/575
should be fixed in 0.24.0-beta-1