demo下载地址 http://pan.baidu.com/s/1pLcpKpl
1.Unity导出工程时设置bundle id要与项目一致
2.修改bit code为NO
3.删除Main.storyboard,代码设置控制器(方便切换window)
4.将Classes,Libraries,MapFileParser.sh拖入到项目(选中Copy items if needed, 选中Create groups)
将Data拖入到项目(选中Copy items if needed, 选中Create folder references)
文章图片
5.添加framework(最下边三个是HiAR UnitySDK里边的)
文章图片
6.添加 Header Search Paths 和 Library Search Paths
文章图片
文章图片
7.other C Flags -> -DINIT_SCRIPTING_BACKEND=1
文章图片
8.添加User-Defined (UNITY_RUNTIME_VERSION版本号与导出工程的Unity版本号一致)
文章图片
文章图片
9.Unity/Classes/Prefix.pch 的代码复制到新建的pch文件, 设置pch文件路径
10.将Classes/main.mm全部内容复制到main.m 并把扩展名改为.mm, 修改如下代码
文章图片
11.添加Run Script
文章图片
12. 修改UnityAppController.h如下代码
文章图片
13.在AppDelegate.h .m中添加如下代码
文章图片
文章图片
在集成过程中可能遇到的问题
1.Unknown type name 'UnityViewControllerBase'
UnityViewControllerBase报错, 把它改成UIViewController
文章图片
文章图片
2. Unknown type name 'AppDelegate'
在新建的项目里边不会报错, 但是我集成到公司项目的时候报这个错, 于是改成如下代码, 目前没有出现问题, 如果有人知道原因, 请在评论区告诉我
【IT|iOS - 将Unity导出的Xcode工程导入到另一个Xcode项目, 及常见报错的解决方法】
文章图片
文章图片
3. Undefined symbols for architecture armv7
遇到这个错的同学请添加AssetsLibrary.framework和Accelerate.framework
文章图片
4.编译时遇到Permission denied错误的是因为当前开发账号对项目目录没有权限执行MapFileParser.sh
解决办法: 在终端执行命令 sudo chmod -R 777 所在的目录
5. Functions that differ only in their return type cannot be overloaded
解决办法: 把Enable Strict Checking of objc_msgSend Calls 改为NO
文章图片
文章图片
6. Control reaches end of non-void function
解决办法: 把Mismatched Return Type 改为NO
文章图片
文章图片
C++混编需要设置的地方
文章图片
7.删除unity自带的.pch和main.mm文件
8.linker command failed with exit code 1
duplicate symbol __Z32RegisterAllStrippedInternalCallsv in:
/Users/xinshang/Library/Developer/Xcode/DerivedData/App3.0-hidvomkzbvfqvibtxzyzngoflknc/Build/Intermediates/App3.0.build/Debug-iphoneos/App3.0.build/Objects-normal/arm64/UnityICallRegistration.o
/Users/xinshang/Library/Developer/Xcode/DerivedData/App3.0-hidvomkzbvfqvibtxzyzngoflknc/Build/Intermediates/App3.0.build/Debug-iphoneos/App3.0.build/Objects-normal/arm64/RegisterMonoModules.o
duplicate symbol __Z18RegisterAllClassesv in:
/Users/xinshang/Library/Developer/Xcode/DerivedData/App3.0-hidvomkzbvfqvibtxzyzngoflknc/Build/Intermediates/App3.0.build/Debug-iphoneos/App3.0.build/Objects-normal/arm64/UnityClassRegistration.o
/Users/xinshang/Library/Developer/Xcode/DerivedData/App3.0-hidvomkzbvfqvibtxzyzngoflknc/Build/Intermediates/App3.0.build/Debug-iphoneos/App3.0.build/Objects-normal/arm64/RegisterMonoModules.o
duplicate symbol __Z43InvokeRegisterStaticallyLinkedModuleClassesv in:
/Users/xinshang/Library/Developer/Xcode/DerivedData/App3.0-hidvomkzbvfqvibtxzyzngoflknc/Build/Intermediates/App3.0.build/Debug-iphoneos/App3.0.build/Objects-normal/arm64/UnityClassRegistration.o
/Users/xinshang/Library/Developer/Xcode/DerivedData/App3.0-hidvomkzbvfqvibtxzyzngoflknc/Build/Intermediates/App3.0.build/Debug-iphoneos/App3.0.build/Objects-normal/arm64/RegisterMonoModules.o
duplicate symbol __Z39RegisterStaticallyLinkedModulesGranularv in:
/Users/xinshang/Library/Developer/Xcode/DerivedData/App3.0-hidvomkzbvfqvibtxzyzngoflknc/Build/Intermediates/App3.0.build/Debug-iphoneos/App3.0.build/Objects-normal/arm64/UnityClassRegistration.o
/Users/xinshang/Library/Developer/Xcode/DerivedData/App3.0-hidvomkzbvfqvibtxzyzngoflknc/Build/Intermediates/App3.0.build/Debug-iphoneos/App3.0.build/Objects-normal/arm64/RegisterMonoModules.o
ld: 4 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1(use -v to see invocation)
解决办法:
找到对应的RegisterMonoModules.cpp文件,注释掉重复的方法:
#if !INIT_SCRIPTING_BACKEND
extern void RegisterAllClassesGranular();
//void RegisterAllClasses()
//{
//// Register classes for unit tests
//RegisterAllClassesGranular();
//}
//
//void RegisterAllStrippedInternalCalls() {}
//
//void InvokeRegisterStaticallyLinkedModuleClasses() {}
//void RegisterStaticallyLinkedModulesGranular() {}
#endif // INIT_SCRIPTING_BACKEND
void RegisterMonoModules() {}
9.[DYMTLInitPlatform] platform initialization successful启动报错,
解决:修改main.m文件
//main.m
//App3.0
//
//Created by mac on 17/2/16.
//Copyright ? 2017年 mac. All rights reserved.
//
#include "RegisterMonoModules.h"
#include "RegisterFeatures.h"
#include
#include
// Hack to work around iOS SDK 4.3 linker problem
// we need at least one __TEXT, __const section entry in main application .o files
// to get this section emitted at right time and so avoid LC_ENCRYPTION_INFO size miscalculation
static const int constsection = 0;
void UnityInitTrampoline();
// WARNING: this MUST be c decl (NSString ctor will be called after +load, so we cant really change its value)
//const char* AppControllerClassName = "UnityAppController";
const char* AppControllerClassName = "AppDelegate";
int main(int argc, char* argv[])
{
signed long long startTime = mach_absolute_time();
@autoreleasepool
{
UnitySetStartupTime(startTime);
UnityInitTrampoline();
UnityInitRuntime(argc, argv);
RegisterMonoModules();
NSLog(@"-> registered mono modules %p\n", &constsection);
RegisterFeatures();
// iOS terminates open sockets when an application enters background mode.
// The next write to any of such socket causes SIGPIPE signal being raised,
// even if the request has been done from scripting side. This disables the
// signal and allows Mono to throw a proper C# exception.
std::signal(SIGPIPE, SIG_IGN);
UIApplicationMain(argc, argv, nil, [NSString stringWithUTF8String: AppControllerClassName]);
}
return 0;
}
#if TARGET_IPHONE_SIMULATOR && TARGET_TVOS_SIMULATOR
#include
extern "C" int pthread_cond_init$UNIX2003(pthread_cond_t *cond, const pthread_condattr_t *attr)
{ return pthread_cond_init(cond, attr);
}
extern "C" int pthread_cond_destroy$UNIX2003(pthread_cond_t *cond)
{ return pthread_cond_destroy(cond);
}
extern "C" int pthread_cond_wait$UNIX2003(pthread_cond_t *cond, pthread_mutex_t *mutex)
{ return pthread_cond_wait(cond, mutex);
}
extern "C" int pthread_cond_timedwait$UNIX2003(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *abstime)
{ return pthread_cond_timedwait(cond, mutex, abstime);
}
#endif // TARGET_IPHONE_SIMULATOR && TARGET_TVOS_SIMULATOR
// 可能有的步骤忘记了, 有疑问的可以在评论区留言
推荐阅读
- java|IOS 自动化测试
- 好文章|网景创始人(软件正吞噬整个世界)
- Android开发|移动端系统生物认证技术详解
- 数据结构|最新|蓝桥杯备赛冲刺攻略,人手必备!
- ios开发技术|《App Store创赢艺术(Apple开发的赚钱机密》这本书)
- java|苹果被罚3.1635亿元,因不愿开放第三方支付!
- java|2018-2019-20172329 《Java软件结构与数据结构》第二周学习总结
- java|iOS 高刷屏监控 + 优化(从理论到实践全面解析)
- java|7个小技巧,老板再也无法留我加班了...