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 'CapWatchContentView' in scope #35

Open
jacobglowdev opened this issue Feb 21, 2024 · 20 comments
Open

Cannot find 'CapWatchContentView' in scope #35

jacobglowdev opened this issue Feb 21, 2024 · 20 comments

Comments

@jacobglowdev
Copy link

jacobglowdev commented Feb 21, 2024

I've followed the documentation up to step 7, my watchOS.swift file currently looks like this:

import SwiftUI
import WatchConnectivity

@main
struct watchOS_Watch_AppApp: App {
    var body: some Scene {
        WindowGroup {
            CapWatchContentView()
                .onAppear {
                    assert(WCSession.isSupported(), "This sample requires Watch Connectivity support!")
                    WCSession.default.delegate = WatchViewModel.shared
                    WCSession.default.activate()
                }
        }
    }
}

I'm receiving the error:
Cannot find 'CapWatchContentView' in scope

I can confirm the capacitor/watch plugin exists in my package.json file. The only other thing I can think of that may (or may not) be relevant is that after I added the Capacitor Watch Swift Package from node modules, its name reads as iOS-capWatch-watch instead of CapWatch-Watch-SPM.

I have tried adding import CapacitorWatch above the @main statement, but this also throws the No such module 'CapacitorWatch' error.

@giralte-ionic
Copy link
Contributor

You need to import CapactiorWatch here as well

@jacobglowdev
Copy link
Author

You need to import CapactiorWatch here as well

Apologies - I have updated my comment to highlight that I have tried this already.

@jacobglowdev
Copy link
Author

Additional Information - after adding the package dependency, I quit xcode and tried to build it again with npm run ios, however it now fails with the following message:

RuntimeError - PBXProject attempted to initialize an object with unknown ISA XCLocalSwiftPackageReference from attributes: {"isa"=>"XCLocalSwiftPackageReference", "relativePath"=>"../../node_modules/@capacitor/watch/CapWatch-Watch-SPM"}

So something has gone wrong with the adding the package dependency?

@giralte-ionic
Copy link
Contributor

just to confirm, are you using Xcode 15?

@jacobglowdev
Copy link
Author

just to confirm, are you using Xcode 15?

Yep, Xcode 15

@giralte-ionic
Copy link
Contributor

so I just tried running the install instructions on a new cap project and encountered the same thing you have. This is happening because for some reason Xcode is now assuming everything inside an SPM is 'private' and that causes the things there to be out of scope. I'll need to make an update to the package to fix this.

@jacobglowdev
Copy link
Author

Thanks - is there an estimated timeframe for this fix?

@giralte-ionic
Copy link
Contributor

I'm hoping to get to it this week

@jacobglowdev
Copy link
Author

Is there any update on this?

@benmarsh
Copy link

Appreciate this may be lower down on the list of priorities but we're also looking into adding Apple Watch functionality to our Capacitor app and this looks to be the ideal solution. Would be great to get an ETA if at all possible. Thanks 🙏

@jacobglowdev
Copy link
Author

I'm hoping to get to it this week

I understand if this isn't a priority ticket for you guys, but are you able to advise a rough timeframe for this fix? Just so I can make a decision on whether to look into alternative approaches.

@giralte-ionic
Copy link
Contributor

I should have a little time this week. So maybe this week, but I'm not promising anything

@giralte-ionic
Copy link
Contributor

Ok give version 0.1.11 a spin. I've also updated the README a little, in Step 6 of creating the watch app you need to add import iOS_capWatch_watch in addition to the other changes. Let me know if this gets you up and running.

@JensUweB
Copy link

JensUweB commented Apr 8, 2024

@giralte-ionic I tested your fix including the changes in step 6 in our Enterprise App and tried running ionic cap build ios.
Sadly, the command failed basically with the same error as before.

> capacitor sync ios
[capacitor] ✔ Copying web assets from dist to ios/App/App/public in 117.81ms
[capacitor] ✔ Creating capacitor.config.json in ios/App/App in 2.36ms
[capacitor] ✔ copy ios in 168.15ms
[capacitor] ✔ Updating iOS plugins in 10.15ms
[capacitor] [info] Found 8 Capacitor plugins for ios:
[capacitor]        @capacitor-community/screen-brightness@5.0.0
[capacitor]        @capacitor/app@5.0.6
[capacitor]        @capacitor/camera@5.0.8
[capacitor]        @capacitor/haptics@5.0.6
[capacitor]        @capacitor/keyboard@5.0.7
[capacitor]        @capacitor/share@5.0.6
[capacitor]        @capacitor/splash-screen@5.0.7
[capacitor]        @capacitor/watch@0.1.11
[capacitor] ✖ Updating iOS native dependencies with pod install - failed!
[capacitor] ✖ update ios - failed!
// ...
RuntimeError - `PBXProject` attempted to initialize an object with unknown ISA `XCLocalSwiftPackageReference` from attributes: `{"isa"=>"XCLocalSwiftPackageReference", "relativePath"=>"../../node_modules/@capacitor/watch/CapWatch-Watch-SPM"}`
[capacitor]         If this ISA was generated by Xcode please file an issue: https://github.com/CocoaPods/Xcodeproj/issues/new

@giralte-ionic
Copy link
Contributor

I'm sorry the cocoapod failed to publish. I have corrected this. Please try again.

@JensUweB
Copy link

JensUweB commented Apr 8, 2024

The error still persists with version @capacitor/watch@0.1.12 for me.
Stuff I tried:

  • rm -rf node_modules
  • pod cache clean --all
  • repeated step 5 - just in case
  • rm -rf ~/Library/Caches/CocoaPods

@giralte-ionic
Copy link
Contributor

giralte-ionic commented Apr 8, 2024

try removing your Podfile.lock file and run npx cap sync from your project root. I just tried an initial project setup and things worked correctly.

@JensUweB
Copy link

JensUweB commented Apr 9, 2024

I'm sorry to bother you again, but I can't get it to work. I set up a completely new App with Ionic Capacitor & React, installed capacitor watch, executed the steps in your Readme and run into the error again.

You can check out this repo if you like for reproduction. I'm using XCode 15.3 & MacOS Sonoma 14.4. Maybe this is an issue with the latest XCode version?

A coworker of mine could reproduce the issue with that repo above & our production app as well.

@giralte-ionic
Copy link
Contributor

giralte-ionic commented Apr 9, 2024

So I pulled your repo down and there are two problems:

  1. In your watch app target, add the iOS-capWatch-watch framework to the 'Frameworks, Libraries and Embedded content' section. When you added the watch spm to the project, you didn't select the watch app as the target

  2. In AppDelegate.swift, you typo'd import CapacitorWatch:

import CapacitorWatch
//import CapactiorWatch 

Fixing these two things gets me a successful build.

@giralte-ionic
Copy link
Contributor

@JensUweB has this issue been resolved?

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

4 participants