【问题标题】:Xcode can't find Alamofire, error: No such module 'Alamofire'Xcode 找不到 Alamofire,错误:没有这样的模块 'Alamofire'
【发布时间】:2016-09-19 23:55:10
【问题描述】:

我正在尝试按照 github(https://github.com/Alamofire/Alamofire#cocoapods) 指令将 Alamofire 包含在我的 Swift 项目中。

我创建了一个新项目,导航到项目目录并运行此命令sudo gem install cocoapods。然后我遇到以下错误:

ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/pod

搜索后我设法通过运行此命令sudo gem install -n /usr/local/bin cocoapods 安装cocoapods

现在我通过pod init 生成一个 pod 文件并以这种方式进行编辑:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'


target 'ProjectName' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!


  # Pods for Law
    pod 'Alamofire'
  target 'ProjectNameTests' do
    inherit! :search_paths
    # Pods for testing
  end


  target 'ProjectNameUITests' do
    inherit! :search_paths
    # Pods for testing
  end


end

最后我运行pod install 来安装Alamofire。之后我打开项目,import Alamofire 语句给了我以下错误No such module 'Alamofire'

Update-1:pod install 的结果是:

Analyzing dependencies
Downloading dependencies
Using Alamofire (3.4.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

【问题讨论】:

  • 当您运行 pod install 时,您是否看到安装了依赖项?如果需要,你有 -bridging-header.h 吗?如果该进程实际下载了 Alamofire,请打开已创建的 .xcworkspace。
  • 我在编辑 pod 文件后运行 pod installpod install 的结果在更新中给出。所以我猜是正确安装了依赖项
  • 听起来很像。你打开的是 .xcworkspace 而不是 xcodeproj?
  • 尝试打开 xcodeproj 和 xcworkspace。不幸的是,两者都不起作用! :(
  • 您是否在项目中看到具有适当框架的 pod?它们是 swift 框架吗?

标签: ios xcode swift cocoapods alamofire


【解决方案1】:

打开 .xcworkspace 而不是 .xcodeproj

【讨论】:

  • 尝试打开xcodeprojxcworkspace。不幸的是,两者都不起作用! :(
  • 嘿! @gelSisaed 在 SO 上查看此 answer 以正确解释其工作原理。
  • @imrajatgupta 酷豆!感谢您的协助。但检查链接
【解决方案2】:

转到产品 -> 方案 -> 管理方案... 并检查 Alamofire true 这对我有用

【讨论】:

  • 很好的解决方案!
【解决方案3】:

有时 xcode 无法加载模块 Alamofire。它可能发生在工作会议之后,在打开项目之后。解决此问题的方法是选择一个模式 -> Alamofire,然后运行。如果消息为“成功”,则可以将架构更改回项目,并且不会出现任何问题。

【讨论】:

  • 在尝试了大量建议的解决方案之后,这确实有效!谢谢。
【解决方案4】:

我建议你像下面这样更改你的 pod 文件:

# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
 use_frameworks!

pod 'Alamofire', '~> 3.0' <<<----  Alamofire library is cross beetween projects

target 'NotifyM' do

end

target 'NotifyMTests' do

end

target 'NotifyMUITests' do

end 

另一件事是use_frameworks!,如果项目基于Objective-C,您应该使用它并尝试使用Swift pod 库。

更新:对于新的 cocoapods 1.x 版,共享库应该是这样的:

# There are no targets called "Shows" in any Xcode projects
abstract_target 'Shows' do
  pod 'ShowsKit'
  pod 'Fabric'

  # Has its own copy of ShowsKit + ShowWebAuth
  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  # Has its own copy of ShowsKit + ShowTVAuth
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end
end

如 cocoapods 网站所示:http://guides.cocoapods.org/using/the-podfile.html

【讨论】:

    【解决方案5】:

    您必须先清理项目并构建,然后才能导入该库。

    【讨论】:

    • 应该在评论中
    【解决方案6】:

    您应该在编码之前点击目标以选择 Alamofire 并构建一次。

    【讨论】:

    • 我没有找到将AlamofireBuild Phases 添加到Target Dependancies 的选项。请问有什么建议吗?
    • 如果您在 Target 中没有看到 Alamofire,您可以点击 Manage Schemes 进行检查。
    • 我在 Product->Scheme->Manage Schemes 列表中找不到Alamofire。如果我尝试添加它不会显示Alamofire。如果我尝试通过单击设置图标进行导入,它会在项目的 pod 目录中显示 Alamofire 文件夹。有什么问题吗?
    • 尝试打开 xcodeproj 和 xcworkspace。不幸的是,两者都不起作用! :(
    【解决方案7】:

    这样安装Pod文件

    # Uncomment this line to define a global platform for your project
     platform :ios, '8.0'
    # Uncomment this line if you're using Swift
     use_frameworks!
    
    target 'NotifyM' do
    
    pod 'Alamofire', '~> 3.0'
    
    end
    
    target 'NotifyMTests' do
    
    end
    
    target 'NotifyMUITests' do
    
    end
    

    【讨论】:

      【解决方案8】:

      我建议这样做,它对我有用:

      platform :ios, '8.0'
      use_frameworks!
      
      target 'App' do
        pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'
        pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'
      
      end
      

      之后,在您的项目存储库中运行:pod install

      【讨论】:

        【解决方案9】:

        使用 Cocoapods 包含依赖项时,请始终打开您的 .xcworkspace

        • 在 Podfile 中使用 use_frameworks!
        • 从构建阶段移除所有链接的库。
        • 在 Build Setting 中查找 Framework Search Path 并在 debug 和 release 中添加 $(inherited)
        • 对标头搜索路径也执行相同操作。

        现在尝试一个干净的构建。

        【讨论】:

          【解决方案10】:

          2021 M1 用户

          根据:https://developer.apple.com/forums/thread/123614?answerId=683594022#683594022

          • 关闭 XCode
          • 打开 Finder 应用并在此处显示“应用程序”
          • 右键单击 Xcode 图标并单击“获取信息”(或类似内容)
          • 有“Open with Rosseta”复选框(或类似的东西)。选择它
          • 再次运行 Xcode 并尝试构建

          它对我有用,希望它对你有用。

          【讨论】:

            【解决方案11】:

            经过大量的努力和上面提供的所有解决方案。我已经修复了 Xcode 13.0:

            用于模拟器: 前往:

            - Build settings -> EXCLUDED_ARCHS = arm64
            - Build settings -> VALID_ARCHS = arm64e armv7 armv7s arm64  x86_64
            

            用于领域设备: 前往:

            - Build settings -> EXCLUDED_ARCHS = 
            - Build settings -> VALID_ARCHS = arm64e armv7 armv7s arm64 
            

            【讨论】:

              猜你喜欢
              • 2018-10-23
              • 2018-01-17
              • 2016-01-04
              • 2021-07-08
              • 2016-10-23
              • 2017-09-28
              • 2016-07-24
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多