美文网首页
2022-03-09

2022-03-09

作者: Lee0528 | 来源:发表于2022-03-09 11:28 被阅读0次

    Xcode12 在使用模拟器(Simulator)时编译错误的解决方法

    Xcode12 上使用模拟器编译项目时,出现错误。同样的代码在Xcode11则不会有问题。

    一些错误如下:

    No such modules (import installed pods)

    Cocoapods post-build step with the script they install issue -> Pods/Target Support Files/Pods-All-Apps-XXX/Pods-All-Apps-XXX-frameworks.sh: line 141: ARCHS[@]: unbound variable

    ‘ObjCheaderFile.h’ file not found. (ObjC Headers in bridging file)


    image.png
    image.png image.png

    为什么会出现这些错误?

    在查阅Xcode12的升级文档,我们找到如下内容: image.png

    1、Xcode11 项目中模拟器会编译为x86_64,但Xcode12的模拟器基于苹果Apple Silicon architecture执行,需要编译为arm64运行在模拟器上。许多第三方库(如Firebase,AFNetworking等)并未提供Xcode12版本的更新支持,导致报错。

    2、Xcode12 开始移除编译设置(Bulid Settings)中的 Valid Architectures的宏定义。当项目使用Xcode12打开时候,会在User-Defines(项目的Bulid Settings里面)中自动生成VALID_ARCHS宏定义。如果旧项目存在于此冲突的宏定义,会导致编译失败。

    如何修复?

    第一步:添加 arm64 到 simulator architecture 中。主项目和pod项目都需要。
    在主项目和pod项目的PROJECT的Build Settings中,搜索Excluded Architecture ,添加 Any iOS Simulator SDK,value填入 arm64 image.png
    image.png

    注意:在pod项目的build setting是cocopod自动生成的,本次修改在下次更新第三方库时候会被覆盖,可以添加脚本在Podfile中,防止每次安装和更新都需要手动修改。

    post_install do |installer|
      installer.pods_project.build_configurations.each do |config|
        config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
      end
    end
    
    第二步:在主项目和pod项目的PROJECT的Build Settings中,删除VALID_ARCHS(整个删除,不能只删除value留下Key
    image.png

    本文转自他人!
    原文链接:https://blog.csdn.net/babylv1/article/details/109395657

    相关文章

      网友评论

          本文标题:2022-03-09

          本文链接:https://www.haomeiwen.com/subject/ygrtdrtx.html