为什么更新到 Xcode 12 后出现链接错误?
Why do I get a linking error after updating to Xcode 12?
我有一个 Unity 项目,它使用我使用 Firebase MLKit 创建的本机 Swift + ObjC 库。当尝试为 iOS 构建时,Unity 项目始终使用 Xcode 11.3.1 构建,但是当更新到任何 Xcode 12.X 版本时,我收到以下错误:
ld: warning: Could not find or use auto-linked library 'swiftCoreMIDI'
ld: warning: Could not find or use auto-linked library 'swiftUniformTypeIdentifiers'
Undefined symbols for architecture armv7:
"__swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers", referenced from:
__swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers_$_NativeLibrary_iOS in NativeLibrary_iOS.a(NativeLibrary.o)
__swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers_$_NativeLibrary_iOS in NativeLibrary_iOS.a(UIImage.o)
(maybe you meant: __swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers_$_NativeLibrary_iOS)
"__swift_FORCE_LOAD_$_swiftCoreMIDI", referenced from:
__swift_FORCE_LOAD_$_swiftCoreMIDI_$_NativeLibrary_iOS in NativeLibrary_iOS.a(NativeLibrary.o)
__swift_FORCE_LOAD_$_swiftCoreMIDI_$_NativeLibrary_iOS in NativeLibrary_iOS.a(UIImage.o)
(maybe you meant: __swift_FORCE_LOAD_$_swiftCoreMIDI_$_NativeLibrary_iOS)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的代码中既没有使用 swiftCoreMIDI
也没有使用 swiftUniformTypeIdentifiers
。作为记录,在将其再次导入 Unity 之前,我确实使用 Xcode 12 重新编译了我的本地库。
我尝试过的事情:
- 使用不使用 Firebase MLKit 的 Swift 库构建 Unity 项目:工作正常
- 构建一个 Xcode 仅使用 Firebase MLKit 的项目:工作正常
- 使用更新的 Unity 版本构建项目:失败
- 直接集成 Firebase SDK 框架而不是使用 CocoaPods:失败
- 向我的项目添加空 Swift 文件 + 桥接头:失败
- 在 XCode 中添加用户定义的设置
LD_VERIFY_BITCODE = NO
:失败
我正在使用:
- Xcode 12.2
- Firebase 6.34
- Swift 5.0
- 统一 2019.3.6f1
任何帮助将不胜感激,我已经坚持了一段时间!
解决方案
我终于找到了解决方案,它已链接到 Xcode 中的 UnityFramework 目标。我不得不删除一些与我的构建无关的架构:i386
和 x86_64
。此外,我更新了 库搜索路径 以包含 $(SDKROOT)/usr/lib/swift
.
要自动执行这些操作,您可以在 Unity 项目的 PostProcessBuild
文件中添加这些行:
var projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
var proj = new PBXProject();
proj.ReadFromFile(projPath);
// Update the Library Search Paths of the whole Xcode project
proj.AddBuildProperty(proj.ProjectGuid(), "LIBRARY_SEARCH_PATHS", "$(SDKROOT)/usr/lib/swift");
// Get the UnityFramework target and exclude the unwanted architectures
var unityFrameworkGuid = proj.TargetGuidByName("UnityFramework");
proj.SetBuildProperty(unityFrameworkGuid, "EXCLUDED_ARCHS", "i386");
proj.AddBuildProperty(unityFrameworkGuid, "EXCLUDED_ARCHS", "x86_64");
我有一个 Unity 项目,它使用我使用 Firebase MLKit 创建的本机 Swift + ObjC 库。当尝试为 iOS 构建时,Unity 项目始终使用 Xcode 11.3.1 构建,但是当更新到任何 Xcode 12.X 版本时,我收到以下错误:
ld: warning: Could not find or use auto-linked library 'swiftCoreMIDI'
ld: warning: Could not find or use auto-linked library 'swiftUniformTypeIdentifiers'
Undefined symbols for architecture armv7:
"__swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers", referenced from:
__swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers_$_NativeLibrary_iOS in NativeLibrary_iOS.a(NativeLibrary.o)
__swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers_$_NativeLibrary_iOS in NativeLibrary_iOS.a(UIImage.o)
(maybe you meant: __swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers_$_NativeLibrary_iOS)
"__swift_FORCE_LOAD_$_swiftCoreMIDI", referenced from:
__swift_FORCE_LOAD_$_swiftCoreMIDI_$_NativeLibrary_iOS in NativeLibrary_iOS.a(NativeLibrary.o)
__swift_FORCE_LOAD_$_swiftCoreMIDI_$_NativeLibrary_iOS in NativeLibrary_iOS.a(UIImage.o)
(maybe you meant: __swift_FORCE_LOAD_$_swiftCoreMIDI_$_NativeLibrary_iOS)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的代码中既没有使用 swiftCoreMIDI
也没有使用 swiftUniformTypeIdentifiers
。作为记录,在将其再次导入 Unity 之前,我确实使用 Xcode 12 重新编译了我的本地库。
我尝试过的事情:
- 使用不使用 Firebase MLKit 的 Swift 库构建 Unity 项目:工作正常
- 构建一个 Xcode 仅使用 Firebase MLKit 的项目:工作正常
- 使用更新的 Unity 版本构建项目:失败
- 直接集成 Firebase SDK 框架而不是使用 CocoaPods:失败
- 向我的项目添加空 Swift 文件 + 桥接头:失败
- 在 XCode 中添加用户定义的设置
LD_VERIFY_BITCODE = NO
:失败
我正在使用:
- Xcode 12.2
- Firebase 6.34
- Swift 5.0
- 统一 2019.3.6f1
任何帮助将不胜感激,我已经坚持了一段时间!
解决方案
我终于找到了解决方案,它已链接到 Xcode 中的 UnityFramework 目标。我不得不删除一些与我的构建无关的架构:i386
和 x86_64
。此外,我更新了 库搜索路径 以包含 $(SDKROOT)/usr/lib/swift
.
要自动执行这些操作,您可以在 Unity 项目的 PostProcessBuild
文件中添加这些行:
var projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
var proj = new PBXProject();
proj.ReadFromFile(projPath);
// Update the Library Search Paths of the whole Xcode project
proj.AddBuildProperty(proj.ProjectGuid(), "LIBRARY_SEARCH_PATHS", "$(SDKROOT)/usr/lib/swift");
// Get the UnityFramework target and exclude the unwanted architectures
var unityFrameworkGuid = proj.TargetGuidByName("UnityFramework");
proj.SetBuildProperty(unityFrameworkGuid, "EXCLUDED_ARCHS", "i386");
proj.AddBuildProperty(unityFrameworkGuid, "EXCLUDED_ARCHS", "x86_64");