简体   繁体   English

AppDelegate.swift 中没有这样的模块“电容器”

[英]No such module 'Capacitor' in AppDelegate.swift

I'm working on an Ionic React Project running on top of Capacitor .我正在研究在Capacitor之上运行的Ionic React Project I added Android platform and everything went smoothly.我加了Android平台,一切顺利。 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.现在我正在尝试让我的应用程序在 iOS 中运行(第一次使用 iOS),在添加 ios 平台并在 XCode 中打开我的项目后,我遇到了一些问题。

See the errors:查看错误:

在此处输入图像描述

在此处输入图像描述

Podfile content:播客文件内容:

在此处输入图像描述

Any help would be really appreciated.任何帮助将非常感激。 Thank you!谢谢你!

For anyone interested, I deleted ios folder and added iOS platform again.对于任何感兴趣的人,我删除了 ios 文件夹并再次添加了 iOS 平台。 After that, instead of running ' pod install ' (I got errors via this command), I used these commands:之后,我没有运行' pod install '(我通过这个命令得到了错误),而是使用了这些命令:

in regular terminal, outside the Project directory:在常规终端中,项目目录外:

sudo arch -x86_64 gem install ffi

then inside iOS folder然后在 iOS 文件夹中

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.我使用以下命令打开应用程序: ionic cap open ios并收到错误: No module Capacitor found ,但无论如何我忽略了此错误并在 XCode 内运行/构建应用程序。模拟器成功打开并且应用程序运行顺利。

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.在做了一些研究之后,我终于让我的项目在 iOS 上运行。我使用的是 Angular 版本 9。我无法运行 XCode 项目,因为 ionic 不会创建所需的 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:我只是先用 npx 创建了 iOS 应用程序,然后使用 ionic 运行我的应用程序的实时重新加载:命令如下:

  1. npm install @capacitor/ios
  2. npx cap add ios
  3. ng build (creates the www directory) ng build (创建 www 目录)
  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从 XCode 运行应用程序,以便在运行时获取应用程序的日志

(Sources: npx and ionic ) (来源: npxionic

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.在 Xcode 中的 iOS 包中直接编辑 Podfile 的问题在于,每次构建包时,您都有可能丢失对 Podfile 所做的更改。

Capacitor should build it for you automatically when you run ionic cap add ios or ionic cap build ios .当您运行ionic cap add iosionic cap build ios时,电容器应该会自动为您构建。

If it doesn't, you could try deleting the iOS bundle in your IDE (eg VS Code) and then add it again using the CLI.如果没有,您可以尝试删除 IDE 中的 iOS 包(例如 VS Code),然后使用 CLI 再次添加它。

Obviously a Podfile will differ from project to project, but one generated with Ionic/Capacitor generally looks like this:显然,Podfile 因项目而异,但使用 Ionic/Capacitor 生成的 Podfile 通常如下所示:

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

If capacitor is a Pod I am assuming it since you have attached your podfile,如果电容器是一个 Pod,我假设它是因为你已经附加了你的 podfile,

Then add Capacitor pod with version to the podfile And run pod install It should be available,然后将带有版本的 Capacitor pod 添加到 podfile 并运行pod install它应该可用,

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否则,如果它是一个外部框架,请确保将其添加到项目中并将其复制到Target-> BuildPhases-> Link Binary With Libraries Option

I already had an IOS folder generated, so I deleted it and ran the following commands:我已经生成了一个 IOS 文件夹,所以我删除了它并运行了以下命令:

  1. npx cap add ios

  2. ionic build ios or ng build

  3. npx cap sync ios only if is necessary npx cap sync ios仅在必要时

  4. npx cap open ios

If you're trying to use multiple schemes within your capacitor project, I resolved this by adding this to my project's Podfile:如果你想在你的电容器项目中使用多个方案,我通过将它添加到我的项目的 Podfile 来解决这个问题:

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

It's in the docs here它在此处的文档中

In my case I was opening.xcodeproj instead of xcworkspace in xcode. Once I opened the.在我的例子中,我在 xcode 中打开了 .xcodeproj 而不是 xcworkspace。一旦我打开了。 xcworkspace file, app built successfully. xcworkspace 文件,应用构建成功。

Difference between the two is explained well here: https://stackoverflow.com/a/21631534/4868839两者之间的区别在这里得到了很好的解释: https://stackoverflow.com/a/21631534/4868839

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM