CapacitorWatch icon indicating copy to clipboard operation
CapacitorWatch copied to clipboard

Cannot find 'CapWatchContentView' in scope

Open jacobglowdev opened this issue 2 years ago • 21 comments

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.

jacobglowdev avatar Feb 21 '24 16:02 jacobglowdev

You need to import CapactiorWatch here as well

giralte-ionic avatar Feb 21 '24 16:02 giralte-ionic

You need to import CapactiorWatch here as well

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

jacobglowdev avatar Feb 21 '24 16:02 jacobglowdev

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?

jacobglowdev avatar Feb 21 '24 17:02 jacobglowdev

just to confirm, are you using Xcode 15?

giralte-ionic avatar Feb 21 '24 17:02 giralte-ionic

just to confirm, are you using Xcode 15?

Yep, Xcode 15

jacobglowdev avatar Feb 21 '24 17:02 jacobglowdev

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.

giralte-ionic avatar Feb 21 '24 18:02 giralte-ionic

Thanks - is there an estimated timeframe for this fix?

jacobglowdev avatar Feb 26 '24 15:02 jacobglowdev

I'm hoping to get to it this week

giralte-ionic avatar Feb 26 '24 15:02 giralte-ionic

Is there any update on this?

jacobglowdev avatar Mar 12 '24 09:03 jacobglowdev

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 🙏

benmarsh avatar Mar 12 '24 13:03 benmarsh

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.

jacobglowdev avatar Mar 21 '24 10:03 jacobglowdev

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

giralte-ionic avatar Mar 25 '24 12:03 giralte-ionic

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.

giralte-ionic avatar Apr 05 '24 15:04 giralte-ionic

@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/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[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

JensUweB avatar Apr 08 '24 09:04 JensUweB

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

giralte-ionic avatar Apr 08 '24 13:04 giralte-ionic

The error still persists with version @capacitor/[email protected] for me. Stuff I tried:

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

JensUweB avatar Apr 08 '24 13:04 JensUweB

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.

giralte-ionic avatar Apr 08 '24 14:04 giralte-ionic

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.

JensUweB avatar Apr 09 '24 12:04 JensUweB

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 avatar Apr 09 '24 12:04 giralte-ionic

@JensUweB has this issue been resolved?

giralte-ionic avatar Apr 12 '24 11:04 giralte-ionic