Flutter shared_preferences 模块未找到 - iOS Xcode 构建

问题描述 投票:0回答:11

我在 Flutter 中使用

shared_preferences
依赖项。

构建 Xcode(产品->存档 - 用于通用目标)失败并显示

module 'shared_preferences' not found

我尝试过

flutter clean
flutter pub cache repair
,尝试将 Flutter lib/ 移动到新项目(
flutter create .
)并使用旧版 Xcode 版本(11.4.1)进行构建。目前我有 12.0 beta 3。

奇怪的是,从我的 IDE (IntelliJ) 在模拟器中运行运行得很好,没有错误。

这些是我的依赖项(pubspec.yaml)

dependencies:
  flutter:
    sdk: flutter
  http: ^0.12.2
  intl: any
  flutter_spinkit: ^4.1.2
  redux: any
  flutter_redux: any
  redux_thunk: any
  shared_preferences: 0.5.1+2
ios xcode flutter sharedpreferences
11个回答
21
投票

就我而言,问题是我从 Project.xcodeproj 而不是 Project.xcworkspace 打开 Xcode 项目。


2
投票

我必须按以下方式更改方案:

产品 -> 方案 -> 编辑方案


2
投票

在 Stack Overflow 上搜索我发现了这个 Xcode 中未找到 Flutter 模块 哪个链接到这个 https://github.com/flutter/flutter/issues/54599#issuecomment-644336055

这为我解决了问题!


0
投票

如果您使用项目方案模式作为调试,则将您的方案更改为从调试中发布。

产品->方案->调试发布。

并再次尝试存档项目。


0
投票

我在 flutter 升级 xcode 和 flutter 2.12 时也遇到了这个问题。

解决这个问题:

  1. 在 ios 文件夹内,删除所有文件夹和文件,将 ios 文件夹保留在您的 flutter 项目中。
  2. 在 flutter 项目中执行 > flutter create 。
  3. 使用 xcode 打开 ios/Runner.xworkspace
  4. 在 xcode 中,右上角会有一个黄色警报图标,单击该图标并修复建议的问题。
  5. 使用 xcode 构建

0
投票

我删除了ios文件夹,然后我在项目路径中运行:

flutter create .
flutter build ios

0
投票
  1. 删除 podfile.lock 和 pods 文件夹以及派生数据
  2. 再次“pod install”
  3. 清洁和建造

这应该可以解决问题


0
投票

致 2022 年带着 Mac M1 来到这里的任何人

请尝试

  1. 扑扑干净
  2. cd ios/
  3. arch -x86_64 pod 安装

这解决了我的问题


0
投票

对于在使用 Fastlane 时遇到此问题的任何人:解决方案“打开 Project.xcodeproj 而不是 Project.xcworkspace”也适用于这种情况!

在您的

Fastfile
中,像这样构建应用程序:

build_app(
  workspace: "Runner.xcworkspace",
  # ...
)

不是这样的:

build_app(
  project: "Runner.xcodeproj", # BAD IDEA!
  # ...
)

否则,Cocoapods 依赖项无法正确引用。我花了一段时间才弄清楚......


0
投票

我用新的 flutter 项目的 ios floder 替换了

ios/Runner.xcodeproj/project.pbxproj
文件。这对我有用。


-1
投票

你可以尝试使用这个命令

pod 分解 && pod 设置 && pod 安装

© www.soinside.com 2019 - 2024. All rights reserved.