【问题标题】:Module compiled with swift 4.0 cannot be imported in swift 3.1swift 4.0编译的模块不能导入swift 3.1
【发布时间】:2017-06-10 15:52:38
【问题描述】:

显然我已经设法在 Xcode 9 beta 中构建了我的项目,现在我只得到错误

swift 4.0编译的模块不能导入swift 3.1

当我在 Xcode 8 中运行项目时。我的模块是 Alamofire。我已尝试重新启动 Xcode,但没有任何反应有什么办法解决这个问题吗?

【问题讨论】:

  • 注意:有同样的问题,Clean & Rebuild 我的项目解决了这个问题,我不必编辑 Podfile

标签: ios swift xcode xcode9-beta xcode9


【解决方案1】:

您有两种选择:

Clean 项目,然后尝试re-build 您的解决方案,看看它是否有效。

如果它不起作用并且您仍然收到相同的错误消息,请执行以下步骤,它应该适合您:

  1. 打开您的podfile 并删除Alamofire
  2. 运行pod update
  3. Alamofire 重新添加到您的podfile
  4. 运行pod update
  5. 完成后,clean 您的项目并运行它

【讨论】:

  • 这里有同样的问题,但使用的是迦太基。尝试我知道的所有技巧来清理项目,问题仍然存在。知道如何为迦太基解决这个问题吗?
  • 按照步骤操作,但不幸的是没有奏效。有趣的事实是它可以在模拟器(与硬件版本相同的 iPad 版本)上正常工作,但在准备硬件 iPad 时会显示此错误(Alamofire 4.5.1)
  • @Heki,尝试从您的设备中删除该应用并重新安装,看看是否有任何不同。
  • @Rashwan L,不幸的是,该应用程序从未进入设备,因此我无法将其删除。构建失败
【解决方案2】:

这里有同样的问题,但使用的是 Carthage。这是答案:

  • rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData
  • 删除项目的Carthage 文件夹
  • 更新迦太基:carthage update --platform iOS

瞧!

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,清理构建文件夹有帮助:

    Command+Option+Shift+K
    

    Product -> Option+Clean

    【讨论】:

      【解决方案4】:

      只需删除派生数据对我有用,无需再次安装 Pod

      【讨论】:

        【解决方案5】:

        我在 Carthage 管理依赖项的项目中遇到了这个问题。在我的情况下,我没有在 xcode 中设置命令行工具(输入 xcodebuild -version,你会知道你是否设置它),所以第一步是去 XCode --> Preference --> Locations 然后选择要用作命令行工具的 xcode。然后你可以按照上面提到的@Domsware 的步骤来重建你将要使用的所有框架。

        ================================================

        这里有同样的问题,但使用的是 Carthage。这是答案:

        rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData
        delete the Carthage folder for the project
        Update Carthage: carthage update --platform iOS
        

        ================================================

        然后不要忘记删除“链接框架和库”下的旧链接,并将所有框架从您项目下的 /Carthage 文件夹拖到“链接框架和库”。

        然后瞧!

        对于那些使用 CocoaPods 的人,我怀疑(免责声明:我没有在 CocoaPods 是依赖管理器的项目中遇到这个问题)解决方案将在终端中运行以下命令:

        $ pod deintegrate
        $ pod clean
        $ pod install
        

        您可能需要为 CocoaPod 安装“deintegrate”和“clean”工具的位置

        $ sudo gem install cocoapods-deintegrate cocoapods-clean
        

        更多详情见帖子 How to remove CocoaPods from a project?

        【讨论】:

          【解决方案6】:

          在您的 pod 文件末尾添加以下行:

          post_install do |installer|
              print "Setting the default SWIFT_VERSION to 4.0\n"
              installer.pods_project.build_configurations.each do |config|
                  config.build_settings['SWIFT_VERSION'] = '4.0'
              end
          
              installer.pods_project.targets.each do |target|
                  if ['SomeTarget-iOS', 'SomeTarget-watchOS'].include? "#{target}"
                      print "Setting #{target}'s SWIFT_VERSION to 3.0\n"
                      target.build_configurations.each do |config|
                          config.build_settings['SWIFT_VERSION'] = '3.0'
                      end
                  else
                      print "Setting #{target}'s SWIFT_VERSION to Undefined (Xcode will automatically resolve)\n"
                      target.build_configurations.each do |config|
                          config.build_settings.delete('SWIFT_VERSION')
                      end
                  end
              end
          end
          

          【讨论】:

            猜你喜欢
            • 2018-01-09
            • 1970-01-01
            • 2017-11-08
            • 2022-01-07
            • 2021-01-04
            • 1970-01-01
            • 2019-09-08
            • 2020-02-27
            • 1970-01-01
            相关资源
            最近更新 更多