简体   繁体   English

为什么更新到 Xcode 12 后出现链接错误?

[英]Why do I get a linking error after updating to Xcode 12?

I have a Unity project that uses a native Swift + ObjC library that I made using Firebase MLKit.我有一个 Unity 项目,它使用我使用 Firebase MLKit 制作的原生 Swift + ObjC 库。 When trying to build for iOS, the Unity project always builds with Xcode 11.3.1, but when updating to any Xcode 12.X version, I get the following errors:尝试为 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)

I am not using either swiftCoreMIDI nor swiftUniformTypeIdentifiers in my code.我没有在我的代码中使用swiftCoreMIDIswiftUniformTypeIdentifiers For the record, I did recompile my native library with Xcode 12 before importing it again in Unity.作为记录,我确实使用 Xcode 12 重新编译了我的本机库,然后在 Unity 中再次导入它。

Things I have tried:我尝试过的事情:

  • Building a Unity project with a Swift library that doesn't use Firebase MLKit: works fine使用不使用 Firebase MLKit 的 Swift 库构建 Unity 项目:工作正常
  • Building an Xcode only project that uses Firebase MLKit: works fine构建仅使用 Firebase MLKit 的 Xcode 项目:工作正常
  • Building the project with a more recent Unity version: fails使用更新的 Unity 版本构建项目:失败
  • Integrating the Firebase SDK frameworks directly instead of using CocoaPods: fails直接集成 Firebase SDK 框架,而不是使用 CocoaPods:失败
  • Adding an empty Swift file + bridging header to my project: fails添加一个空的 Swift 文件 + 桥接 header 到我的项目:失败
  • Adding the user defined setting LD_VERIFY_BITCODE = NO in XCode: fails在 XCode 中添加用户定义设置LD_VERIFY_BITCODE = NO :失败

I'm using:我在用着:

  • Xcode 12.2 Xcode 12.2
  • Firebase 6.34 Firebase 6.34
  • Swift 5.0 Swift 5.0
  • Unity 2019.3.6f1统一2019.3.6f1

Any help would be appreciated, I've been stuck on this for a while!任何帮助将不胜感激,我已经坚持了一段时间!

SOLUTION解决方案

I finally found the solution, it was linked to the UnityFramework target in Xcode.我终于找到了解决方案,它链接到 Xcode 中的UnityFramework目标。 I had to remove some architectures that are not concerned by my build: i386 and x86_64 .我不得不删除一些与我的构建无关的架构: i386x86_64 In addition, I updated the Library Search Paths to include $(SDKROOT)/usr/lib/swift .此外,我更新了库搜索路径以包含$(SDKROOT)/usr/lib/swift

To execute those actions automatically, you can add those lines in a PostProcessBuild file in your Unity project:要自动执行这些操作,您可以在 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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM