iOS

Xcode 12 - Architecture

2020-10-14  本文已影响0人  ienos

一、building for iOS Simulator, but linking in object file built for iOS, xxxx for architecture arm64

原项目迁移到 Xcode 12 运行模拟器的时候出现报错,在真机可正常运行

区别在于 Xcode 11 中 x86_64 是默认添加的,就算不填写也是默认支持,但是在 Xcode 12 中默认不添加 x86_64,需要手动加入

二、 in XXX.a(XXXXXXX.o), building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

静态库工程编译模拟器库报错,该提示说明该库不支持模拟器 arm64,需要在 Build Setting -> Excluded Architectures 添加 Any iOS Simulator SDK 对应值为 arm64

如何在 cocoapods 中移除 arm64

在 profile 中添加下面代码

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
  end
end

三、have the same architectures (arm64) and can't be in the same fat output file

Xcode 12 之前

Xcode 12 编译的模拟器静态库新增支持 arm64,导致和真机静态库不能合并的问题

需要忽略掉模拟器编译的 arm64,在 Build Setting -> Excluded Architectures 添加 Any iOS Simulator SDK 对应的值为 arm64

针对已打包好的 .a 或 .framework
lipo XXX.a -remove arm64 -output XXX.a

四、The linked library 'xxxx.a/Framework' is missing one or more architectures required by this target: armv7.

Target -> Build Setting -> Exculded Architectures 中添加如下代码

EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))

五、Could not find module 'XXXX' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator in Swift Project?

在 M1 芯片的 Xcode 中模拟器会使用 arm64 架构运行,非 M1 芯片的模拟器架构为 x86_64,如何让 M1 芯片使用旧模式运行,在 Xcode -> 简介(Get Info) -> 打开使用 Rosetta(Open using Rosetta)

Rosetta

关于官方对 Rosetta 的解释 About the Rosetta Translation Environment,简言之 Rosetta 是向 Apple 芯片的一个过渡模式,是一个翻译过程,如果可执行文件包含 Intel 指令,macOS 启动 Rosetta 进行翻译,翻译完成后,系统会启动已翻译的可执行文件来代替原始文件,这个过程会影响性能

Rosetta

默认使用苹果芯片,打开 Rosetta 说明应用程序仅支持英特尔处理器,需要 Rosetta 才能在任何配置 Apple Silicon 的 MAC 上运行

架构分离 & 合并 & 查看指令

以 framework 为例子

# 分离出 arm64 和 armv7
lipo xxxx.framework/xxxx -thin arm64 -output xxxx.framework/xxxx-arm64

lipo xxxx.framework/xxxx -thin armv7 -output xxxx.framework/xxxx-armv7

# 合并分离出两种架构
lipo -create xxxx.framework/xxxx-armv7 xxxx.framework/xxxx-arm64 -output xxxx.framework/xxxx

# 查询 framework 支持哪些架构
libo -info xxxx.framework/xxxx
上一篇 下一篇

猜你喜欢

热点阅读