Unity3d IOS 64 IL2CPP迁移之 AStarPath JosnFX 错误

在为公司的Unity3d游戏从Mono迁移到IOS 64过程中,出现了许多问题。

在看到Xcode提示Build Success时会有一种成就感油然而生,但是噩梦才刚刚开始。

由于IL2CPP的不完善或者说这种把C#代码转换成C++的方式太粗暴,不仅在Build阶段会出现很多错误,在运行期出现的异常崩溃更是数不胜数。

解决掉Build阶段的错误之后,昨天终于把游戏运行起来,但是在进入主城之后就黑屏了,What Fuck!

不过还好在Xcode中有异常爆出。

Method not found: 'Default constructor not found...ctor() of System.ComponentModel.Int64Converter'.
  at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in <filename unknown>:0
  at System.ComponentModel.TypeDescriptor.GetConverter (System.Type type) [0x00000] in <filename unknown>:0
  at Pathfinding.Serialization.JsonFx.TypeCoercionUtility.CoerceType (System.Type targetType, System.Object value) [0x00000] in <filename unknown>:0
  at Pathfinding.Serialization.JsonFx.JsonReader.ReadNumber (System.Type expectedType) [0x00000] in <filename unknown>:0
  at Pathfinding.Serialization.JsonFx.JsonReader.Read (System.Type expectedType, Boolean typeIsHint) [0x00000] in <filename unknown>:0
  at Pathfinding.Serialization.JsonFx.JsonReader.PopulateObject (System.Object& result, System.Type objectType, System.Collections.Generic.Dictionary`2 memberMap, System.Type genericDictionaryType) [0x00000] in <filename unknown>:0 

从字面上来看,没有默认的构造函数?

什么鬼。

但是根据异常来看,异常指向了系统函数……

没办法只有谷歌。

在Unity官方论坛终于看到有开发者反应这个问题,怀疑是因为Unity的代码裁剪优化,消减了这一部分的代码支持!

官方技术支持回答说,不大可能是这个优化造成的,但是也还是给出了一个解决方案。

对于提示出异常的类,创建一个脚本,在这个脚本里面使用new 来调用一下这个类的构造函数,这样就避免被优化裁剪。

I actually doubt this is a stripping issue. It is more likely related to an AOT limitation. IL2CPP can only construct and instance of a type at runtime that it knows about at compile time. So for a call to System.Activator.CreateInstance to succeed, IL2CPP needs to have previously generated code for the System.Type passed as the first argument to CreateInstance.

You may be able to work around this issue by declaring an unused field of type System.ComponentModel.Int64Converter in a class that will not be stripped. A MonoBehaviour in one of your scripts is likely a good candidate. Maybe try something like this:
    class AotTypes : MonoBehaviour
    {
        private static System.ComponentModel.Int64Converter _unused = new System.ComponentModel.Int64Converter();
    }

然后呢对于所有你需要用到的一些类都这样用一下。

private static System.ComponentModel.Int64Converter _unused = new System.ComponentModel.Int64Converter();
    private static System.ComponentModel.DecimalConverter _unused2 = new System.ComponentModel.DecimalConverter();
    private static System.ComponentModel.ByteConverter _unused3 = new System.ComponentModel.ByteConverter();
    private static System.ComponentModel.CollectionConverter _unused4 = new System.ComponentModel.CollectionConverter();
    private static System.ComponentModel.CharConverter _unused5 = new System.ComponentModel.CharConverter();
    private static System.ComponentModel.SByteConverter _unused6 = new System.ComponentModel.SByteConverter();
    private static System.ComponentModel.Int16Converter _unused7 = new System.ComponentModel.Int16Converter();
    private static System.ComponentModel.UInt16Converter _unused8 = new System.ComponentModel.UInt16Converter();
    private static System.ComponentModel.Int32Converter _unused9 = new System.ComponentModel.Int32Converter();
    private static System.ComponentModel.UInt32Converter _unused10 = new System.ComponentModel.UInt32Converter();
    private static System.ComponentModel.Int64Converter _unused11 = new System.ComponentModel.Int64Converter();
    private static System.ComponentModel.UInt64Converter _unused12 = new System.ComponentModel.UInt64Converter();
    private static System.ComponentModel.DoubleConverter _unused13 = new System.ComponentModel.DoubleConverter();
    private static System.ComponentModel.SingleConverter _unused14 = new System.ComponentModel.SingleConverter();
    private static System.ComponentModel.BooleanConverter _unused15 = new System.ComponentModel.BooleanConverter();
    private static System.ComponentModel.StringConverter _unused16 = new System.ComponentModel.StringConverter();
    private static System.ComponentModel.DateTimeConverter _unused17 = new System.ComponentModel.DateTimeConverter();
    private static System.ComponentModel.EnumConverter _unused18 = new System.ComponentModel.EnumConverter(typeof(<any your enum>));
    private static System.ComponentModel.TimeSpanConverter _unused19 = new System.ComponentModel.TimeSpanConverter();

这样就避免代码被裁剪。

游戏成功运行。

时间: 2024-08-02 05:57:03

Unity3d IOS 64 IL2CPP迁移之 AStarPath JosnFX 错误的相关文章

让kbmmw 4.8 支持ios 64

随着xe8 的出来,其开始支持IOS 64 的编译了(不支持也没办法,从今年2月开始不支持ios 64 的应用 就不允许入住apple appstore,霸气呀).相信不少同学迫不及待的开始了ios64 的开发. kbmmw 4.8 开始支持xe8,但是目前确无法直接编译IOS64 的应用,经过分析其源码,发现主要存在两个 问题. 一个问题是流的seek 方法,非ios64时可以 使用  soFromBeginning = 0;  soFromCurrent = 1;  soFromEnd =

Unity3d iOS基本优化和高级优化

原地址:http://www.cocoachina.com/bbs/read.php?tid=70395&page=1 分享看见的2篇好文.简单翻译了一下并且放出原文http://www.cratesmith.com/archives/1831.做减法大量代码在Update()或FixedUpdate()中做处理,意味着无论代码的执行速度如何,都将在每次帧刷新的时候调用到, 复制代码 public class MyHoming : MonoBehaviour { public void Upda

unity3d ios 交互

写这篇博文之前,我也为之忙活了半天,对于那些不熟悉oc的童鞋来说,非常有用,这里主要会讲到常用的通信机制.和一些关于IOS的代码讲解. 一下主要讲解使用unity3d调用IOS的界面浏览一张图片. 1.unity3d 与 IOS 的基本通信机制. 在C#脚本中,定义一个类,里面写入类似这样的 public static class PlatformNative{ [DllImport("__Internal")] private static extern void extern_lo

Unity3D IOS IPhone添加Admob的方法

原地址:http://dong2008hong.blog.163.com/blog/static/4696882720140403119293/ 首先阅读官方文档https://developers.google.com/mobile-ads-sdk/docs/ 按步就班注册获取AdMob Publisher ID已及开发SDK包和DEMO工程,确保官方的demo工程能正确运行: 如果没法运行,再仔细阅读官方文档!! 为了省事,就直接在BannerExampleViewController上修改

hishop网站迁移后出现DataProtectionConfigurationProvider错误(转)

配置错误说明: 在处理向该请求提供服务所需的配置文件时出错.请检查下面的特定错误详细信息并适当地修改配置文件.分析器错误信息: 未能使用提供程序"DataProtectionConfigurationProvider"进行解密.提供程序返回错误信息为: 该项不适于在指定状态下使用. (异常来自 HRESULT:0×8009000B)源错误:行 10:行 11:   <connectionStrings configProtectionProvider="DataProt

【三分钟视频教程】iOS开发中 Xcode 报 apple-o linker 错误的#解决方案#

[三分钟视频教程]iOS开发中 Xcode 报 apple-o linker 错误的#解决方案# [三分钟视频教程]iOS开发中 Xcode 报 apple-o linker 错误的#解决方案#,布布扣,bubuko.com

iOS 开发过程中常出现的一些错误总结

iOS 开发过程中常出现的一些错误总结 1.两个视图控制器之间的跳转 (1)跳转:[self presentModalViewController:control animated:YES]; 返回:[self dismissModalViewControllerAnimated:YES]; (2) 跳转:[self.navigationController  pushViewController:subTableViewController animated:YES]; 返回:[self.na

iOS 64位编程

1.拒绝基本数据类型和隐式转换 1)基本数据类型 64位下,基本类型long从占用4字节变为占用8字节.要注意看一下程序中出现sizeof函数的地方,并注意尽量不要使用基本数据类型,改用对象类型: int -> NSInteger unsigned -> NSUInteger float -> CGFloat 动画时间 -> NSTimeInterval … 2)隐式转换 NSArray *items = @[<a href="http://www.jobbole.

32位工程到64位迁移

最近小组,提出一个蛋疼的要求,要把32位的工程转成64位,并且要产生 debug x86, debug x64, release x86 release x64 这4个版本,并且不需要anycpu 经过几天的摸索,发现 对于 第三方的 c++等dll 很好处理, 直接复制,覆盖过去就可以了, 但是 c#自身的我们通过using的dll由于会产生信息记录,所以不行 不过对于c#32位的dll,64位程序实际上是可以直接调用的,于是无关太大的影响. 下面开始迁移之旅 首先建立一个测试工程 然后设置e