Flutter - 警告(CocoaPods 未安装,跳过 pod install)即使已安装

14
我正在尝试在Android Studio上使用Geolocator插件构建一个Flutter应用程序。 当我运行应用程序时,我遇到了以下警告,这导致应用程序无法运行:
警告:未安装CocoaPods。跳过pod install。 CocoaPods用于检索响应Dart端插件使用的iOS和macOS平台端插件代码。 没有CocoaPods,插件将无法在iOS或macOS上工作。 有关更多信息,请参见https://flutter.dev/platform-plugins 要安装,请参见https://guides.cocoapods.org/using/getting-started.html#installation以获取说明。
异常:未安装或状态无效的CocoaPods。
我尝试了互联网上找到的每个解决方案(Stackoverflow和GitHub),但似乎没有任何解决办法。
重要提示:当我尝试从Xcode而不是从Android Studio运行应用程序时,我遇到了以下错误:
沙盒与Podfile.lock不同步。运行'pod install'或更新您的CocoaPods安装。
所以我做的是 - 切换到 Flutter 项目中的 ios 目录,并运行以下命令:
pod init
pod install

尝试从Xcode再次运行,结果完美无缺。 在Xcode上运行成功后,我尝试从Android Studio运行,但遇到了同样的错误,导致应用无法启动。
Flutter Doctor:
[✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale en-IL)
    • Flutter version 2.2.2 at /Users/idanrefaeli/Developer/flutter
    • Framework revision d79295af24 (5 weeks ago), 2021-06-11 08:56:01 -0700
    • Engine revision 91c9fc8fe0
    • Dart version 2.13.3

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/idanrefaeli/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.57.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.23.0

[✓] Connected device (2 available)
    • Idan’s (mobile) • 00008020-0011092101A2002E • ios            • iOS 14.6
    • Chrome (web)    • chrome                    • web-javascript • Google Chrome 91.0.4472.114

! Doctor found issues in 1 category.

额外的日志: 在Android Studio中的“运行”日志:pastebin.com/7iYtdcTQ 还有在运行“pod install”后的终端日志:pastebin.com/1cCNuFYM
-- 更新 --
最终我成功运行了应用程序,我所做的就是将所有项目文件从头开始复制到一个新项目中,然后它就可以工作了。 也许是某种冲突导致了这个问题,这当然是我最后的办法了。

1
我在使用VS Code时遇到了同样的问题,但是当我重新打开它时,问题得到了解决。 - Filipe Piletti Plucenio
我尝试重新打开、重启、清除Flutter缓存等所有操作。 - Idanref
请展示完整的错误信息(打印输出),我想尝试复现它。 - Filipe Piletti Plucenio
请在此处查看:https://pastebin.com/7iYtdcTQ还有运行“pod install”后的终端日志,请参见:https://pastebin.com/1cCNuFYM - Idanref
相同的问题 - kokserek
12个回答

28
在应用程序“终端”中,在打开模拟器后写入。
flutter run

在终端中 或者 关闭Android Studio,打开终端并粘贴
open /Applications/Android\ Studio.app 

它将打开Android Studio,您可以像平常一样运行。

3
这个命令:“open /Applications/Android\ Studio.app”对我很有用。 - AbdulMomen عبدالمؤمن
2
这个真的很有用,无需为Android Studio Bumblebee安装补丁1,只需运行open /Applications/Android\ Studio.app即可。 - Robert Apikyan
退出Android Studio并在终端中执行open /Applications/Android\ Studio.app。开始工作! - Ar1f
打开 /Applications/Android\ Studio.app,非常顺利,谢谢! - Leo

14
# uninstall
sudo gem uninstall cocoapods
brew uninstall cocoapods

# reinstall
sudo gem install cocoapods
pod setup

# rebuild
flutter build ios

然后,重新启动vscode和iTerm(这很重要),并进行调试


最终使用以下命令解决了我的问题 +1 - Priyanka
最完整和简单的答案。+1 - Utopion

11

在更新后,这个错误开始出现在 Mac OS 上。

Android Studio Bumblebee | 2021.1.1
Build #AI-211.7628.21.2111.8092744, built on January 19, 2022
Runtime version: 11.0.11+0-b60-7590822 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.0.1
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 8
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: com.bloc.intellij_generator_plugin (3.3.0), Dart (211.7798), andrasferenczi.dart-data-plugin (0.2.0), com.thoughtworks.gauge (211.6693.111), org.jetbrains.kotlin (211-1.6.10-release-923-AS7442.40), io.flutter (63.2.2), org.intellij.plugins.markdown (211.7142.37)

在我的情况下,通过在 VS Code 中启动项目或使用命令 flutter run 运行项目是有效的。

Android Canary 的最新版本解决了问题。

更新:正如 Ascot Harris 所提到的,Android Studio Bumblebee | 2021.1.1 补丁 1 解决了问题。


Android Canary现在是一个不错的解决方案,谢谢。 - Álvaro Agüero
Android Studio Bumblebee | 2021.1.1 补丁 1 对我解决了这个问题。 - Ascot Harris

4

只需要打开终端并输入以下命令:

sudo gem install cocoapods

这解决了我的问题


3

步骤1: 关闭Android Studio

步骤2: 打开终端

步骤3: 粘贴:

open /Applications/Android\ Studio.app

步骤4: Android Studio将自动启动。

步骤5: 点击运行按钮。


3
我有同样的问题,我安装了CocoaPods,现在它可以工作了。
只需复制并粘贴此行以安装CocoaPods: sudo gem install cocoapods 重新启动VSCode和终端。
然后运行您的应用程序。
我正在使用MAC和IOS(Iphone 13)模拟器。
CocoaPods指南:CocoaPods Guide.

2
首先,你应该执行以下命令:
sudo gem install activesupport -v 6.1.7.6

然后:
sudo gem install cocoapods  

0

如 @islomkhuja-akhrarov 所提到的,这是 Android Studio Bumblebee 的问题。安装补丁1有所帮助。


0

这是一个可怕的黑客方式,有时候会起作用。

我在 Visual Studio Code 中运行应用程序一次后,随后在 Android Studio 中运行就可以了。


0

通过删除 Podfile.lock 和 pods 文件夹并更新以下包 firebase_core: ^1.12.0,firebase_analytics: ^8.3.4,firebase_crashlytics: ^2.3.0,firebase_messaging: ^11.1.0,然后首先运行 pod repo remove trunk,最后运行 pod install 即可解决此问题。


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