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:
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:
LD_VERIFY_BITCODE = NO
in XCode: failsI'm using:
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. 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:
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.