No such module 'Capacitor' in AppDelegate.swift
Asked Answered
C

8

15

I'm working on an Ionic React Project running on top of Capacitor. I added Android platform and everything went smoothly. Now that I'm trying to make my app work in iOS (first time working with iOS), after adding ios platform and open my project in XCode, I ran into some issues.

See the errors:

enter image description here

enter image description here

Podfile content:

enter image description here

Any help would be really appreciated. Thank you!

Crossarm answered 7/7, 2021 at 9:27 Comment(2)
you need to add 'Capacitor' to podfileTso
@Tso How to do that, please?Cockaleekie
C
15

For anyone interested, I deleted ios folder and added iOS platform again. After that, instead of running 'pod install' (I got errors via this command), I used these commands:

in regular terminal, outside the Project directory:

sudo arch -x86_64 gem install ffi

then inside iOS folder

arch -x86_64 pod install

After these commands, all capacitor pods/plugins got installed successfully. I opened the app using this command: ionic cap open ios and got an error: No module Capacitor found, but anyway I ignored this error and ran/build the app inside XCode. The emulator got opened successfully and the app ran smoothly.

Crossarm answered 7/7, 2021 at 14:22 Comment(0)
S
33

In my case I was opening .xcodeproj instead of xcworkspace in xcode. Once I opened the . xcworkspace file, app built successfully.

Difference between the two is explained well here: https://mcmap.net/q/16060/-xcode-project-vs-xcode-workspace-differences

Stowaway answered 1/2, 2023 at 8:51 Comment(0)
C
15

For anyone interested, I deleted ios folder and added iOS platform again. After that, instead of running 'pod install' (I got errors via this command), I used these commands:

in regular terminal, outside the Project directory:

sudo arch -x86_64 gem install ffi

then inside iOS folder

arch -x86_64 pod install

After these commands, all capacitor pods/plugins got installed successfully. I opened the app using this command: ionic cap open ios and got an error: No module Capacitor found, but anyway I ignored this error and ran/build the app inside XCode. The emulator got opened successfully and the app ran smoothly.

Crossarm answered 7/7, 2021 at 14:22 Comment(0)
E
6

I faced the same problem today. After doing some research I finally made my project work on iOS! I am using Angular version 9. I could not run the XCode project since ionic would not create the required podfile. I simply created the iOS app with npx first and then used ionic to run a live reload of my app. The commands are the following:

  1. npm install @capacitor/ios
  2. npx cap add ios
  3. ng build (creates the www directory)
  4. npx cap open ios
  5. ionic capacitor run ios --livereload --external
  6. Run the app from XCode in order to get the app's logs during runtime

(Sources: npx and ionic)

Eyas answered 23/8, 2021 at 8:23 Comment(0)
L
5

The problem with editing your Podfile directly within the iOS bundle in Xcode is that every time you build your bundle, you risk losing the changes you have made to the Podfile.

Capacitor should build it for you automatically when you run ionic cap add ios or ionic cap build ios.

If it doesn't, you could try deleting the iOS bundle in your IDE (e.g. VS Code) and then add it again using the CLI.

Obviously a Podfile will differ from project to project, but one generated with Ionic/Capacitor generally looks like this:

platform :ios, '12.0'
use_frameworks!

# workaround to avoid Xcode caching of Pods that requires
# Product -> Clean Build Folder after new Cordova plugins installed
# Requires CocoaPods 1.6 or newer
install! 'cocoapods', :disable_input_output_paths => true

def capacitor_pods
  pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
  pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
  pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app'
  pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device'
  pod 'CapacitorGeolocation', :path => '../../node_modules/@capacitor/geolocation'
  pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics'
  pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
  pod 'CapacitorLocalNotifications', :path => '../../node_modules/@capacitor/local-notifications'
  pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network'
  pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
  pod 'CapacitorStorage', :path => '../../node_modules/@capacitor/storage'
  pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
end

target 'App' do
  capacitor_pods
  # Add your Pods here
end
Leonard answered 7/7, 2021 at 10:12 Comment(3)
I deleted ios folder and ran again: ionic cap add ios. Now, Podfile contains Capacitor inside but the problem is that No Podfile is in project structure when I open my project in XCode.Crossarm
Have you tried running ionic cap build ios?Leonard
Yes and it fails! an error occurred while running Capacitor, capacitor sync ios exited with code -1. there are too many logs but one of them was: Pod install failed and Bus ErrorCrossarm
B
1

If capacitor is a Pod I am assuming it since you have attached your podfile,

Then add Capacitor pod with version to the podfile And run pod install It should be available,

Otherwise if it a external framework make sure to add it to the project and copy it under Target-> BuildPhases-> Link Binary With Libraries Option

Bleacher answered 7/7, 2021 at 9:40 Comment(3)
Like this: pod 'Capacitor' ? Is this enough?Crossarm
I added it like this: target 'App' do pod 'Capacitor', '~> 3.0.0' end and ran pod install, but the error is still there. Should I do any clean or sth?Crossarm
it should be like target 'App' do pod 'Capacitor' or if you have a version pod 'Capacitor', '3.0.0'Bleacher
P
1

I already had an IOS folder generated, so I deleted it and ran the following commands:

  1. npx cap add ios

  2. ionic build ios or ng build

  3. npx cap sync ios only if is necessary

  4. npx cap open ios

Poon answered 30/10, 2022 at 0:50 Comment(0)
M
0

If you're trying to use multiple schemes within your capacitor project, I resolved this by adding this to my project's Podfile:

target 'TARGETNAME' do
  capacitor_pods
  # Add your Pods here
end

It's in the docs here

Michelemichelina answered 16/11, 2022 at 19:31 Comment(0)
D
0

I navigated to the ios directory then App directory (ios/App) in Finder, then I went in and changed the pod files

  • Podfile.lock
  • Podfile
  • Pods / Pods.xcodeproj

to read in and writeable. I did this by "Right Clicking" and then clicking get info. Under "Sharing & Permissions" I changed all the permissions

Debus answered 31/10, 2023 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.