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

Hello,

I have a Unity project that uses a native Swift + ObjC library that I made using Firebase MLKit. 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 :
Code Block
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. For the record, I did recompile my native library with Xcode 12 before importing it again in Unity.

Things I have tried:
  • Building a Unity project with a Swift library that doesn’t use Firebase MLKit : works fine

  • Building an Xcode only project that uses Firebase MLKit : works fine

  • Building the project with a more recent Unity version : fails

  • Integrating the Firebase SDK frameworks directly instead of using CocoaPods : fails

  • Adding an empty Swift file + bridging header to my project : fails

  • Adding the user defined setting LDVERIFYBITCODE = NO in XCode : fails

I’m using:
  • Xcode 12.2

  • Firebase 6.34

  • Swift 5.0

  • Unity 2019.3.6f1

Any help would be appreciated, I’ve been stuck on this for a while!
Answered by PaulineTilak in 651200022

Solution



I finally found the solution, it was linked to the UnityFramework target in Xcode. I had to remove some architectures that are not concerned by my build: i386 and x86_64. In addition, I updated the Library Search Paths to include $(SDKROOT)/usr/lib/swift.
 
To execute those actions automatically, you can add those lines in a PostProcessBuild file in your Unity project :
 
Code Block
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");

Accepted Answer

Solution



I finally found the solution, it was linked to the UnityFramework target in Xcode. I had to remove some architectures that are not concerned by my build: i386 and x86_64. In addition, I updated the Library Search Paths to include $(SDKROOT)/usr/lib/swift.
 
To execute those actions automatically, you can add those lines in a PostProcessBuild file in your Unity project :
 
Code Block
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");

Why do I get a linking error after updating to Xcode 12 ?
 
 
Q