Ani
Ani

Reputation: 948

No such module 'Capacitor' in AppDelegate.swift

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!

Upvotes: 18

Views: 23232

Answers (8)

User3250
User3250

Reputation: 3421

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://stackoverflow.com/a/21631534/4868839

Upvotes: 43

Alex
Alex

Reputation: 1

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

Upvotes: 0

Sam Borick
Sam Borick

Reputation: 955

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

Upvotes: 0

Juan Rosero
Juan Rosero

Reputation: 11

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

Upvotes: 1

Konstantinos
Konstantinos

Reputation: 61

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)

Upvotes: 6

Ani
Ani

Reputation: 948

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.

Upvotes: 15

Super_Simon
Super_Simon

Reputation: 1296

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

Upvotes: 5

nitin upadhyay
nitin upadhyay

Reputation: 133

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

Upvotes: 1

Related Questions