moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

Cannot find 'MainViewControllerKt' in scope

Open piet90 opened this issue 2 years ago • 3 comments

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?

piet90 avatar Jan 30 '24 14:01 piet90

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.

FrancescoBottino avatar Feb 11 '24 10:02 FrancescoBottino

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 avatar Feb 13 '24 10:02 piet90

@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

FrancescoBottino avatar Feb 13 '24 12:02 FrancescoBottino

should be fixed in 0.24.0-beta-1

Alex009 avatar Apr 19 '24 14:04 Alex009