“npx cap add ios”命令执行失败,错误提示为“使用pod install更新iOS本地依赖项失败!”

20

我刚刚使用命令“ionic start myApp blank”创建了一个全新的Ionic应用程序。

我添加了必要的Angular依赖项,以使“ionic serve”正常工作。

我使用以下命令安装了Capacitor。

npm install @capacitor/cli @capacitor/core
npx cap init

npm install @capacitor/ios @capacitor/android

我的Package.json文件如下所示,

{
  "name": "myApp",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~12.1.1",
    "@angular/core": "~12.1.1",
    "@angular/forms": "~12.1.1",
    "@angular/platform-browser": "~12.1.1",
    "@angular/platform-browser-dynamic": "~12.1.1",
    "@angular/router": "~12.1.1",
    "@capacitor/android": "^3.2.4",
    "@capacitor/app": "1.0.3",
    "@capacitor/core": "^3.2.4",
    "@capacitor/haptics": "1.1.0",
    "@capacitor/ios": "^3.2.4",
    "@capacitor/keyboard": "1.1.0",
    "@capacitor/status-bar": "1.0.3",
    "@ionic/angular": "^5.5.2",
    "rxjs": "~6.6.0",
    "tslib": "^2.2.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~12.1.1",
    "@angular-eslint/builder": "~12.0.0",
    "@angular-eslint/eslint-plugin": "~12.0.0",
    "@angular-eslint/eslint-plugin-template": "~12.0.0",
    "@angular-eslint/template-parser": "~12.0.0",
    "@angular/cli": "~12.1.1",
    "@angular/compiler": "~12.1.1",
    "@angular/compiler-cli": "~12.1.1",
    "@angular/language-service": "~12.0.1",
    "@capacitor/cli": "^3.2.4",
    "@ionic/angular-toolkit": "^4.0.0",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "@typescript-eslint/eslint-plugin": "4.16.1",
    "@typescript-eslint/parser": "4.16.1",
    "eslint": "^7.6.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "~3.8.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.3.2",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "typescript": "~4.2.4"
  },
  "description": "An Ionic project"
}

我运行了以下命令,它们起作用了。

rm -r "./www"
rm -r "./ios"
ng build

接下来我尝试运行以下命令:

ionic capacitor add ios 或者 npx cap add ios

但是出现以下错误:

✔ Adding native Xcode project in ios in 29.98ms
✔ add in 30.56ms
✔ Copying web assets from www to ios/App/App/public in 864.98ms
✔ Creating capacitor.config.json in ios/App/App in 699.86μp
(node:25320) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /Users/493055/Desktop/dev/IonicExperiment/myApp/node_modules/tslib/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
✔ copy ios in 908.37ms
✔ Updating iOS plugins in 5.66ms
[info] Found 4 Capacitor plugins for ios:
       @capacitor/app@1.0.3
       @capacitor/haptics@1.1.0
       @capacitor/keyboard@1.1.0
       @capacitor/status-bar@1.0.3
✖ Updating iOS native dependencies with pod install - failed!
✖ update ios - failed!
[error] ERR_SUBPROCESS_NON_ZERO_EXIT
AND
(base) AMBIN01978:myApp 493055$ ionic capacitor add ios
> npm i -E @capacitor/ios@latest
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/


up to date in 5s

136 packages are looking for funding
  run `npm fund` for details
> capacitor add ios
[capacitor] ✔ Adding native Xcode project in ios in 32.31ms
[capacitor] ✔ add in 33.30ms
[capacitor] ✔ Copying web assets from www to ios/App/App/public in 696.66ms
[capacitor] ✔ Creating capacitor.config.json in ios/App/App in 446.33μp
[capacitor] (node:25522) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /Users/493055/Desktop/dev/IonicExperiment/myApp/node_modules/tslib/package.json.

[capacitor] Update this package.json to use a subpath pattern like "./*".
[capacitor] (Use `node --trace-deprecation ...` to show where the warning was created)
[capacitor] ✔ copy ios in 715.44ms
[capacitor] ✔ Updating iOS plugins in 4.48ms
[capacitor] [info] Found 4 Capacitor plugins for ios:
[capacitor]        @capacitor/app@1.0.3
[capacitor]        @capacitor/haptics@1.1.0
[capacitor]        @capacitor/keyboard@1.1.0
[capacitor]        @capacitor/status-bar@1.0.3
[capacitor] ✖ Updating iOS native dependencies with pod install - failed!
[capacitor] ✖ update ios - failed!
[capacitor] [error] xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
[capacitor]         
[ERROR] An error occurred while running subprocess capacitor.
        
        capacitor add ios exited with exit code 1.
        
        Re-running this command with the --verbose flag may provide more information.

最近几天一直在苦恼这个问题,请求得到帮助。


2
这个回答解决了你的问题吗?xcode-select active developer directory error - user796446
2
非常感谢您,Maggini。"sudo xcode-select --reset"解决了这个问题。 - kathikeyan A
6个回答

69

我在终端中运行了以下命令:

sudo xcode-select --reset

这让我解决了错误。


1
完美的答案,经过尝试了很多其他方法后,终于对我有用了。感谢分享。 - Bas Que
3
对我有用。你能否发布更多关于它是如何工作或为什么会发生的详细信息? - user3642342
1
太好了,那也帮助了我。 - Kristian Heitkamp
1
我已经为此苦苦挣扎了几个小时,现在终于解决了!! - Scottie
4
完成了。不知道它的作用,解释会有所帮助。 - MadMac
太棒了!所以,通过运行sudo xcode-select --reset命令,你将把Xcode的命令行工具路径重置回默认路径。 - Daniel

40
如果您使用的是 M1 机型,问题可能与 Cocoapods 有关。如果其他答案无法解决问题,请尝试以下步骤:先在终端输入命令 "sudo arch -x86_64 gem install ffi" ,然后进入 ios/App 目录,再在终端输入命令 "arch -x86_64 pod install" 。最后,为了检查是否有效,依次输入命令 "cd ..","cd .."和 "npx cap sync"。

4
你是赢家。结果与你所说的完全一样。 - Ruan
1
谢谢!让我摆脱了M1的困境! - Tyler C
我最近购买了一台M2 MacBook Pro,一开始遇到了很多问题,但是现在终于解决了,我现在可以在手机上部署了。非常感谢! - David

7

运行以下命令:

  1. cd ios
  2. cd App
  3. pod install
  4. cd ..
  5. cd ..

然后通过 ionic cap open ios 检查,问题解决 :) :)


2

请使用以下命令

  1. 删除 Visual Studio Code 上此项目的 iOS 版本:

rm -r iOS

  1. 将 iOS 版本加入项目:

npx cap add ios
npx cap sync

  1. 如果遇到 pod install 或插件问题(例如运行 pod update 或 install 时出现“找不到 Capacitor 的 podspec”等问题):

npm i @capacitor/ios


这就是实际答案。 - Ben Racicot

0

只需使用Rosetta打开您的终端,然后运行npx cap sync命令


0
我从头开始重新构建了我的Mac Monstery 12.6.6。所有的软件都是全新安装 - Xcode、Android Studio、VSCode、Node、Cocoapods等。
虽然
pod install

执行正常

ionic cap sync iOS

操作消息失败。

执行以下两个命令解决了我的问题

sudo xcode-select -s /Library/Developer/CommandLineTools
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接