Unity XCode Project

Unity XCode 项目相关笔记

添加和设置框架代码

  • 右键点击项目,选择 Add Files to "项目"...,在弹出的窗口中选择 Sources 目录,Added Folders 选择 Create Groups

  • 选中文件 Libraries/Plugins/iOS/ShibaInu/AppControllerProtocol.h 设置为 Public

  • Undefined symbol: _OBJC_CLASS_$_UnityFramework

TARGET -> Build Phases -> Link Binary With Libraries 添加 UnityFramework




遇到过的问题

禁用 Bitcode

报错如图:

TARGET -> Build Settings -> Enable Bitcode 设置成:NO




Could not produce class with ID [Number]

Find Class with ID:

https://docs.unity3d.com/2020.3/Documentation/Manual/ClassIDReference.html

Find Assemblies:

https://docs.unity3d.com/2020.3/Documentation/ScriptReference/UnityEngine.AIModule.html

然后将对应的 Assembly 和 Class 添加到 Assets/link.xml 文件中




Could not launch “[App Name]”

  • iPhone7-36 has denied the launch request.
    原因可能是证书类型与运行目标类型不匹配。打开Edit Scheme, 确认 Build Configuration 值:Debug 或 Release; 以及 Signing Certificate 值:Developer 或 Distribution 是否匹配。



- clang: error: linker command failed with exit code 1 (use -v to see invocation)

- undefined symbols for architecture armv7 _gadurequestinterstitial

  • Native 代码文件没有加入到项目中,选中文件夹 Classes/Nitive,右键,选择 Add Files to [Project]
  • 查看日志详情,是否 native 函数命名有误。



libiconv.2.dylib is in RED

XCode 7 uses tdb libraries instead of dylib libraries. So you should remove the libiconv.2.dylib dependency and add libiconv.2.tdb.




Undefined symbols for architecture arm64

“_OBJC_CLASS_$_ASIdentifierManager”, referenced from: objc-class-ref in DeviceUtil.o

添加 AdSupport.Framework 即可。

此类编译错误可使用关键字,如:_OBJC_CLASS_$_ASIdentifierManager 搜索查出对应的 Framework 名称。




-canOpenURL: failed for URL: “weixinULAPI://” - error: “This app is not allowed to query for scheme weixinulapi”

接入第三方登录时,运行时可能会在控制台看到该错误。解决办法:

TARGET -> Info -> Custom iOS Target Properties

添加新项,Key = LSApplicationQueriesSchemes Type = Array

添加内容:wechat , weixinULAPI , weixin

接入微博等其他平台时,也有可能会遇到该错误,追加相关内容即可。

Thread 1: “+[WXApi genExtraUrlByReq:withAppData:]: unrecognized selector sent to class 0x100966948”

这个运行时异常出现在跳转(唤起)第三方 APP 时。解决办法:

TARGET -> Build Setting -> Linking -> Other Linker Flags

添加内容:-ObjC -all_load




dyld: Library not loaded

dyld: Library not loaded: @rpath/UnityFramework.framework/UnityFramework...

dyld: launch, loading dependent libraries
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

这个错误出现于:XCode 为最新版本 (xcode 13.2.1),设备 iOS 版本过低 (ios 13)。 解决方法:升级设备的 iOS 至最新版本 (ios 15)。




Multiple commands produce

这个错误是由于存在 Info.plist 导致的。 解决办法:

Solution -> TARGET -> Build Phases > Copy Bundle Resources and remove Info.plist from there.




clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Ld /.../Build/Products/Debug-iphoneos/TargetName.app/.debug.dylib normal (in target 'TargetName' from project 'ProjectName')
    cd .../projdir
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -Xlinker -reproducible -target arm64-apple-ios12.0 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.5.sdk -O0 
    ...
    ...
    .../Build/Products/Debug-iphoneos/TargetName.app/TargetName.debug.dylib

Undefined symbols for architecture arm64:
  "__mh_execute_header", referenced from:
      UnityFrameworkLoad() in main.o
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Build Settings 中将 Enable Debug Dylib Support 设置为 NO 即可解决。

设置为 NO 有什么影响?

对于 Unity 项目,几乎没有任何负面影响,反而是一个正确的选择。 主要影响:你放弃了 Xcode 使用 dylib 注入来加速增量调试的特性。 具体表现:

  • 编译方式回归传统:Xcode 会将所有的代码和调试符号直接编译链接到主可执行文件中。这正是 Unity 项目所期望的传统行为。
  • 增量编译可能稍慢:在一些非常大的纯 Swift/Objective-C 项目中,每次修改代码后的编译链接时间可能会比 YES 时稍微长一点点。但在 Unity 项目中,主要编译时间消耗在 Unity 本身和 UnityFramework 的编译上,App Target 这部分的编译时间影响微乎其微。
  • 调试功能完全正常:你仍然可以正常地设置断点、查看变量、调试代码。只是实现调试信息加载的方式不同而已。
  • 发布(Archive)不受影响:这个设置通常只在 Debug 配置下默认为 YES。在 Release 配置下,它通常是 NO,因为发布的应用不需要这种调试机制。所以,这不会影响你打包上架。



其他

编译 tolua_runtime

tolua_runtime 项目

ToLua(Unity Editor) 添加 Apple Silicon 支持

XCode 打开项目 tolua_runtime/macnojit

开始设置 TARGETS -> tolua -> Build Settings

Architectures 值改为 Standard Architectures (Apple Silicon, Intel) - $(ARCHS_STANDARD)

VALID_ARCHS 值改为 arm64 x86_64(添加 arm64,并去掉对 i386 的支持)

C 编译报错: implicit declaration of function xxx is invalid in C99

原因:隐式声明在 C99 中无效。

解决办法:在头文件或文件开头声明 xxx 函数即可。

macOS 10.15 以上,自己编译的 xxx.bundle 提示损坏,移动到废纸篓

解决办法:手动执行 sudo xattr -r -d com.apple.quarantine xxx.bundle

Copyright © 2025 LOLO