Unity Xcode "RegisterMonoModules.o"


如果你是第一次在mac 上运行ios unity程序,特别是使用了第三方插件或库 有可能你会遇到同样的错误。  

参考链接:

http://stackoverflow.com/questions/8093362/unity-scripting-armv7-error


就目前来说我们开发必须要在

1) android

·2) ios

两个平台上都能正确运行

android的直接生成apk包,安装基本没问题

今天在测试ios平台的时候,遇到了一些麻烦,便记录下来。在windows写好代码以后,导出xcode工程,导入mac  运行,出现如下错误:


[csharp]  view plain copy
  1. ld: warning: ignoring file /Volumes/NO NAME/isotest511/Libraries/libiPhone-lib.a, file was built for archive which is not the architecture being linked (i386): /Volumes/NO NAME/isotest511/Libraries/libiPhone-lib.a  
  2. Undefined symbols for architecture i386:  
  3.   "_RegisterModule_AI", referenced from:  
  4.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  5.   "_RegisterModule_Animation", referenced from:  
  6.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  7.   "_RegisterModule_Audio", referenced from:  
  8.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  9.   "_RegisterModule_ParticleSystem", referenced from:  
  10.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  11.   "_RegisterModule_ParticlesLegacy", referenced from:  
  12.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  13.   "_RegisterModule_Physics", referenced from:  
  14.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  15.   "_RegisterModule_Physics2D", referenced from:  
  16.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  17.   "_RegisterModule_Terrain", referenced from:  
  18.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  19.   "_RegisterModule_TerrainPhysics", referenced from:  
  20.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  21.   "_RegisterModule_TextRendering", referenced from:  
  22.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  23.   "_RegisterModule_UI", referenced from:  
  24.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  25.   "_RegisterModule_Umbra", referenced from:  
  26.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  27.   "_RegisterModule_VR", referenced from:  
  28.       RegisterStaticallyLinkedModules() in RegisterMonoModules.o  
  29.   "_UnityADBannerViewWasClicked", referenced from:  
  30.       -[UnityADBanner bannerViewActionDidFinish:] in iAD.o  
  31.   "_UnityADBannerViewWasLoaded", referenced from:  
  32.       -[UnityADBanner bannerViewDidLoadAd:] in iAD.o  
  33.   "_UnityADInterstitialADWasLoaded", referenced from:  
  34.       -[UnityInterstitialAd interstitialAdDidLoad:] in iAD.o  
  35.   "_UnityBindFramebuffer", referenced from:  


由于是第一次用mac运行ios程序,耽误了不少时间,最后发现 错误的根源是 unity 导出xcode工程的问题

注意发布的时候,player setting的 IOS的几个选项 非常重要
setting for ios
preloader assets
SDK version  如果是 device 那么一定要实机
SDK Device 必须是Device 
否则会报错






-------------------------我是分割线-----------------------------






我用的是:
xcode 6.1
unity3d 4.6


还没写完。。因为还有遇到其他麻烦的坑,解决了再写上来
 
第一步:导出的东西肯定先会在xcode里跑一下,可能出现如下问题
u3d中调用ios方法:


一开始拿到u3d源码,导出xcode项目时出现如下报错

Undefined symbols for architecture armv7:
  "_ios_onUnwearedClothes", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_ios_onLoadUnityPlayerOK", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_ios_onClothesWeared", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_ios_onClothesSelected", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

4.0版本的u3d导出的xcode项目是appController,但4.6版导出后是UnityAppController
上面的报错是因为在xcode中没有提供上面这些方法,要手动写到UnityAppController里

在UnityAppController.h中添加:
注意方法是否需要传入参数或返回值,我这里都是无参数无返回值的
#ifdef __cplusplus
extern "C" {
#endif
    void ios_onUnwearedClothes();
    void ios_onLoadUnityPlayerOK();
    void ios_onClothesWeared();
    void ios_onClothesSelected();
#ifdef __cplusplus
}
#endif

在UnityAppController.m中实现这些方法:
void ios_onUnwearedClothes()
{
    // do something
}
void ios_onLoadUnityPlayerOK()
{
    // do something
}
void ios_onClothesWeared()
{
    // do something
}
void ios_onClothesSelected()
{
    // do something
}

这个问题的原理可参考:
http://stackoverflow.com/questions/8093362/unity-scripting-armv7-error
http://forum.unity3d.com/threads/easy-code-scanner-unity-plugin-for-android-and-ios.159666/





第二步:
把unity3d项目整合嵌入到ios项目中:


贴几个别人的做法,不过可能因为u3d的版本不同,做法不一样
http://segmentfault.com/q/1010000000392448
http://www.cnblogs.com/shawn-zp/p/3225477.html(我用的这篇博客最后一条评论的解决办法)
原文:http://alexanderwong.me/post/29949258838/building-a-ios-unity-uiview-uiviewcontroller
翻译:http://blog.163.com/savage_cui/blog/static/64335507201332834915876/
补充:http://user.qzone.qq.com/1523511691/infocenter#!app=2&via=QZ.HashRefresh&pos=1375185802
其他参考:http://www.scio.de/en/blog-a-news/scio-development-blog-en/entry/iphone-a-unity3d-integrating-3rd-party-static-libraries-in-unity3d-generated-xcode-projects

整合就两种,把u3d丢到xcode项目里,把ios代码丢到u3d导出的项目里
但把u3d丢到xcode项目里会比较繁琐,因为u3d导出成ios项目时本身就附带各种配置,把u3d代码拷贝到xcode项目中后还要一个个对照u3d的配置去设置,需要相当的耐心。。很多时候都是error。。
所以我选择把ios代码丢到u3d导出的项目里,这样就只需要在u3d的rootviewcontroller中add入ios的rootview就行 了,这么做成功率高,也不需要拷贝一堆代码和手动搞一堆配置,但可能也有个缺点,每次u3d有改动后,可能就要手动做一遍整合,毕竟xcode配置里有 icon 启动图 之类



 


第三步:
如果原始ios代码用的ARC,就需要将u3d项目设置成ARC

不知道是不是我导u3d时没设置好,我导出的u3d项目都是非ARC的,我自己的ios代码都用ARC,所以代码里__weak之类的地方直接报错
需要把C Language Dialect设置成GNU99的这个
(如下图)
ios★把unity3d项目整合嵌入到xcode中

用ARC的话肯定要开启ARC(如下图)
ios★把unity3d项目整合嵌入到xcode中

把u3d导出的mm文件都打上-fno-objc-arc
ios★把unity3d项目整合嵌入到xcode中

如果还有其他问题:
如Xcode有引用某些第三方库,会有try catch代码,打包会报错
Cannot use '@try' with Objective-C exceptions disabled
解决方法:
修改target -> build settings -> All | Combined -> Apple LLVM Compiler 6.0 - Language 中 Enable Objective-C Exceptions为YES


u3d代码里加载ios原生viewcontroller:

在UnityAppController.mm中的- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions这个方法最末尾return YES;之前,可以添加以下代码:
UIViewController *_roottemp = UnityGetGLViewController();
[_roottemp.view addSubview:你的viewcontroller.view];
UINavigationControllerDelegate这样的代理也跟在ios里一样使用即可


整合过程中其他问题和注意点:

1. iPhone_target_Prefix.pch文件中会import一些常用的类,这些类一定要放在
#ifdef __OBJC__
    #import 《Foundation/Foundation.h》
    #import 《UIKit/UIKit.h》
    #import "macro.h"
    #import 各种你的类
#endif
放外面的话会报NSObjCRuntime.h,NSZone.h,NSObject.h里面的unknown type name 'NSString'之类的错
这里也有这类报错的解释http://stackoverflow.com/questions/9824754/strange-compiler-error-during-sharekit-integration

2.
 上面iPhone_target_Prefix.pch引用了macro.h,里面是各种宏,会引起如下错误,不知道是什么鬼。。
ios★把unity3d项目整合嵌入到xcode中
解决办法就是不要把宏引用放在
iPhone_target_Prefix.pch里,在各自的viewcontroller里引用macro.h
同样的,如果pch引用的其他ios原生文件中也写过宏,全部都要去掉
不知道还有没有别的办法了,我是把原先写在pch中的引用全都手动一个个拷贝到每个需要的viewcontroller中了

3. 如果报错一两百个,且很多错都是u3d自己的那些类里面的,那基本就是libiPhone-lib.a这个库消失了,我也是做着做着发现这库就这么莫名奇妙消失了。。
如果有
libiPhone-lib.a这个库,但编译时报错说not find -liphone-lib,就到Library search paths中重新编辑下$(SRCROOT)/Libraries的路径就行了

4. ios代码里有时需要用到(AppDelegate *)[[UIApplication sharedApplication] delegate]

在u3d里可以用(UnityAppController *)[[UIApplication sharedApplication] delegate]替代在unity3d里面UnityAppController就相当于AppDelegate(只要看UnityAppController.mm这个主体就行了,另外2个UnityAppController的category扩展无视

5. 关于keywindow,ios里有时要全屏显示一张广告图,我都是用的keywindow
不过u3d里我直接在_roottemp.view里加载全屏图就可以了
UIViewController *_roottemp = UnityGetGLViewController();








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值