为什么升级到Xcode 12后会出现链接错误?

3

我有一个使用Firebase MLKit创建的本地Swift + ObjC库,用于Unity项目中。在尝试为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中。

我尝试过以下几种方法:

  • 编译一个不使用 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
  • Unity 2019.3.6f1

如果有帮助,任何帮助都将不胜感激!我已经卡在这里一段时间了!

1个回答

0

解决方案

我最终找到了解决方案,它与 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");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接