InjectFix icon indicating copy to clipboard operation
InjectFix copied to clipboard

安卓il2cpp包的异步函数修复失败

Open kpli opened this issue 5 years ago • 7 comments

一、使用的master版本 Commits on Sep 22, 2020 解决补丁函数里通过base调用父类函数报错问题 (#231) @annayxguo annayxguo committed 6 days ago

二、类似的问题 async await 报错 #222 https://github.com/Tencent/InjectFix/issues/222

三、出现的步骤及环境 1、Unity Version 2019.3.7f1 (6437fd74d35d)。 2、修复异步函数 [IFix.Patch] async void Function(){...}。 3、使用AddressableAssetSystem更新patch.bytes文件,读取为TextAsset类型数据。 4、加载方式,IFix.Core.PatchManager.Load(new MemoryStream(asset.bytes))。

四、结果 安卓mono包修复成功 安卓il2cpp包修复失败

五、附件代码和日志 日志il2cpp报错.txt 日志mono成功.txt 代码Fix-AsyncVoid.txt

kpli avatar Sep 28 '20 01:09 kpli

和#222 不一样吧? #222 是运行时报错,你这个是加载时报找不到方法。

chexiongsheng avatar Sep 28 '20 02:09 chexiongsheng

sorry,确实和#222不一样的,我这个是不是要换其他的加载方式呢?

kpli avatar Sep 28 '20 02:09 kpli

我先看下你为啥要调用那个函数

chexiongsheng avatar Sep 28 '20 02:09 chexiongsheng

你的unity是什么版本呢?

chexiongsheng avatar Sep 28 '20 02:09 chexiongsheng

2019.3.7f1

kpli avatar Sep 28 '20 02:09 kpli

用华为P20真机测试: AndroidPlayer([email protected]:34999) Exception: can not load method [SetStateMachine] of System.Runtime.CompilerServices.AsyncVoidMethodBuilder …… (Filename: currently not available on il2cpp Line: -1) 日志il2cpp华为P20真机运行.txt

kpli avatar Sep 28 '20 10:09 kpli

代码版本: master分支 552da3654e74c4b08bbe2533699fb2306df5de7e [552da36]

Unity版本: 2020.3.46f1c1

代码调整: 1.修复的dll 加载调整为读取 Application.persistentDataPath

string dllPath = Path.Combine(Application.persistentDataPath,"Assembly-CSharp.patch.bytes"); if(File.Exists(dllPath)) { UnityEngine.Debug.Log("loading Assembly-CSharp.patch ..."); var sw = Stopwatch.StartNew(); PatchManager.Load(new MemoryStream(File.ReadAllBytes(dllPath))); UnityEngine.Debug.Log("patch Assembly-CSharp.patch, using " + sw.ElapsedMilliseconds + " ms"); } //try to load patch for Assembly-CSharp-firstpass.dll dllPath = Path.Combine(Application.persistentDataPath,"Assembly-CSharp-firstpass.patch.bytes"); if(File.Exists(dllPath)) { UnityEngine.Debug.Log("loading Assembly-CSharp-firstpass ..."); var sw = Stopwatch.StartNew(); PatchManager.Load(new MemoryStream(File.ReadAllBytes(dllPath))); UnityEngine.Debug.Log("patch Assembly-CSharp-firstpass, using " + sw.ElapsedMilliseconds + " ms"); }

  1. 热更代码调整 // public int Add(int a, int b) // { // return a * b; // }

     [Patch]
     public int Add(int a, int b)
     {
         var go = new GameObject ("t");
         var transform = go.transform;
         transform.position = transform.position;
         Object.Destroy (go);
         return 0;
     }
    

结果 安卓mono包修复成功 安卓il2cpp包修复失败

报错信息: Exception: can not load method [set_position] of UnityEngine.Transform

tchenjian avatar Mar 26 '23 12:03 tchenjian