Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find 'MainViewControllerKt' in scope #639

Closed
piet90 opened this issue Jan 30, 2024 · 4 comments
Closed

Cannot find 'MainViewControllerKt' in scope #639

piet90 opened this issue Jan 30, 2024 · 4 comments
Milestone

Comments

@piet90
Copy link

piet90 commented Jan 30, 2024

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?

@FrancescoBottino
Copy link

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.

@piet90
Copy link
Author

piet90 commented Feb 13, 2024

Thank you @FrancescoBottino for your reply.

Indeed, I have the dependsOn calls, but I added them to solve this issue: #618

Is there a workaround here?

@FrancescoBottino
Copy link

@piet90 Using version 0.24.0-alpha-4 solved the issue. Take a look into the releases and to PR #575

@Alex009
Copy link
Member

Alex009 commented Apr 19, 2024

should be fixed in 0.24.0-beta-1

@Alex009 Alex009 closed this as completed Apr 19, 2024
@Alex009 Alex009 added this to the 0.24.0 milestone Apr 19, 2024
@Alex009 Alex009 mentioned this issue Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants