繁体   English   中英

为什么更新到 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)

我没有在我的代码中使用swiftCoreMIDIswiftUniformTypeIdentifiers 作为记录,我确实使用 Xcode 12 重新编译了我的本机库,然后在 Unity 中再次导入它。

我尝试过的事情:

  • 使用不使用 Firebase MLKit 的 Swift 库构建 Unity 项目:工作正常
  • 构建仅使用 Firebase MLKit 的 Xcode 项目:工作正常
  • 使用更新的 Unity 版本构建项目:失败
  • 直接集成 Firebase SDK 框架,而不是使用 CocoaPods:失败
  • 添加一个空的 Swift 文件 + 桥接 header 到我的项目:失败
  • 在 XCode 中添加用户定义设置LD_VERIFY_BITCODE = NO :失败

我在用着:

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

任何帮助将不胜感激,我已经坚持了一段时间!

解决方案

我终于找到了解决方案,它链接到 Xcode 中的UnityFramework目标。 我不得不删除一些与我的构建无关的架构: i386x86_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");

暂无
暂无

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

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