Skip to content

RuntimeApi的问题请教 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
huahuacn opened this issue Aug 6, 2022 · 11 comments
Closed

RuntimeApi的问题请教 #5

huahuacn opened this issue Aug 6, 2022 · 11 comments

Comments

@huahuacn
Copy link
Contributor

huahuacn commented Aug 6, 2022

你好,我遇到了一个问题
/Assets/Game/Scripts/Base/HybridCLR/RuntimeApi.cs中,21、24、27、30使用的是HuatuoApi_开头,然后我打包后,发现这个方法找不到。我看了下官方,手动将这个改成了RuntimeApi_开头。但是打包后依然报错误,这次是metadata type not match错误,请问我这种做法是对的吗?还是应该用什么办法解决此问题呀?

@GREAT1217
Copy link
Owner

好巧~ 今天 hybridCLR 更新了部分 API,我已同步更新。注意使用 HybridCLR Builder 编辑器工具重新安装一遍,重新生成桥接函数后打包,我已打包测试 windows64 没有问题。

@huahuacn
Copy link
Contributor Author

huahuacn commented Aug 6, 2022

感谢感谢,我刚刚试用了一下,我不知道是不是我这边的问题。我遇到了两个问题:

  1. 当我不使用编辑器资源模式时,我依然可以进游戏,它仍然读取了编辑器下面的资源,这样没办法在编辑器模式下测试热更了,请问现在HybridCLR就是这样的吗?=。=
  2. 当我忽略第一步,直接打包后运行出现以下错误
    image
    希望得到您的指点,感谢感谢。
    我的平台是Unity2021.3.1f1,打的包是windowsx64。

@GREAT1217
Copy link
Owner

GREAT1217 commented Aug 6, 2022

重新生成桥接函数,重新编译hotfix.dll,重新打包。这些常见的错误可以在HybridCLR的使用文档中找到解决方法。

https://focus-creative-games.github.io/hybridclr/common_errors/

@GREAT1217
Copy link
Owner

GREAT1217 commented Aug 6, 2022

不使用编辑器资源模式,会使用streamingAssets下打的ab包,所以仍然可以进入游戏。这个是GameFramework的知识点。

关于逻辑热更新测试,可以看一下ProcedureCodeInit.cs,编辑器模式下加载的hotfix程序集,否则(运行时)加载hotfix.dll。

@huahuacn
Copy link
Contributor Author

huahuacn commented Aug 7, 2022

感谢感谢,我现在windows已经测试通过了,但是安卓还有些问题,win平台有1个问题:

  1. 虽然我选择的是windowsx64,实际上还是在请求WindowsVersion.txt而不是Windows64Version.txt,我看了下ProcedureVersionCheck的 GetPlatformPath会只返回windows,没有windows64。
    然后就是安卓平台了,切换到安卓平台会报错,我看了下,报错在BuildProcessor_2020_1_OR_NEWER.cs中,需要在顶部加入:#if UNITY_ANDROID using UnityEditor.Android; #endif
    但是在选择安卓平台并编译dll时,又报错了,如下图:
    image
    我构建过了apk包,仍然没有用~

@GREAT1217
Copy link
Owner

多谢反馈,刚刚整理并更新了Unity platform 和 GameFramework platform 之间平台表示符的转换

@GREAT1217
Copy link
Owner

关于 Android 平台,dll文件不存在,应该是 BuildProcessor_2020_1_OR_NEWER.CopyStripDlls() 没有找到源路径。

可以检查一下 BuildConfig.GetOriginBuildStripAssembliesDir() 返回的路径是否正确。(Unity不同版本的这个路径改得😓)

这个问题你自行测试吧😏,我是跟着 hybridclr_trial 改的

@GREAT1217 GREAT1217 pinned this issue Aug 7, 2022
@huahuacn
Copy link
Contributor Author

huahuacn commented Aug 7, 2022

不好意思,我下午自己尝试的修改可能是有问题的。我跟踪了一下,发现BuildProcessor_2020_1_OR_NEWER.CopyStripDlls是在BuildProcessor_2020_1_OR_NEWER.OnPostprocessBuild调用的,但是安卓打包的时候实际上不会走到这个函数里面,而是直接走到BuildProcessor_2020_1_OR_NEWER.OnPostGenerateGradleAndroidProject里面了,这里面又走到AddBackHotFixAssembliesToJson函数里面了。windows打包我看到在HybridCLRData/AssembliesPostIl2CppStrip/下生成了StandaloneWindows64,理论上安卓打包这里需要生成Android文件夹的,但是实际上没有,是因为前面没有走到CopyStripDlls,请问这里你知道如何解决吗?

@huahuacn huahuacn closed this as completed Aug 7, 2022
@huahuacn huahuacn reopened this Aug 7, 2022
@GREAT1217
Copy link
Owner

不好意思,刚看到,我工作中没有用到 HybridCLR,也不发行 Android 平台,只是兴趣使然。

你可以试试官方 hybridclr_trial 打包 Android 会不会有问题,然后在 hybridclr 的新手群中讨论。

我也在群里面。期待你的解决方案。😄

@GREAT1217
Copy link
Owner

下面是官方提供的代码,你可以试试 取消 OnPostGenerateGradleAndroidProject() 中注释的部分。

        public void OnPostGenerateGradleAndroidProject(string path)
        {
            Debug.Log("==== OnPostGenerateGradleAndroidProject");
            // 由于 Android 平台在 OnPostprocessBuild 调用时已经生成完 apk 文件,因此需要提前调用
            AddBackHotFixAssembliesToJson(null, path);

            // 对于 2020, 已经在OnBeforeConvertRun中复制了,因此这儿不再复制
//#if UNITY_2021_1_OR_NEWER
//            BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
//            CopyStripDlls(target);
//#endif
        }

        public void OnPostprocessBuild(BuildReport report)
        {
            Debug.Log("==== OnPostprocessBuild");
#if !UNITY_ANDROID

            AddBackHotFixAssembliesToJson(report, report.summary.outputPath);
#endif
        // Unity 2021开始,不再清理这个Temp目录,因此在这个时机复制较为合适
#if UNITY_2021_1_OR_NEWER
            BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
            CopyStripDlls(target);
#endif
        }

@huahuacn
Copy link
Contributor Author

huahuacn commented Aug 9, 2022

好滴,感谢感谢~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants