Unity-huatuo热更新调研

1. 相关资料

bilibili视频:https://www.bilibili.com/video/BV1SW4y1a7dr/?spm_id_from=autoNext&vd_source=7b7d563864f61c9cee6d3ec1f675d0c0

官方文档:https://focus-creative-games.github.io/

2. 环境准备

2.1 项目和编辑器版本

demo:https://github.com/focus-creative-games/hybridclr_trial.git

demo运行的unity版本:2020.3.33f1

在这里插入图片描述

2.2 安装huatuo插件

打开项目的init_local_il2cpp_data.sh文件,

第一步,将IL2CPP_BRANCH更改为指定的unity版本;

第二步,将IL2CPP_PATH指定为本地unity版本对应的il2cpp目录,这里将会用huatuo的il2cpp替换原unity的il2cpp;

第三步,执行init_local_il2cpp_data.sh脚本。
在这里插入图片描述

2.3 在build settings里面勾选Export Project

这样可以将工程导出成android工程,方便我们打debug包调试。
在这里插入图片描述

2.4 导出Android studio工程

在这里插入图片描述
在这里插入图片描述

3. 验证热更新

3.1 更改读取目录

原demo中,默认是从asset目录读取,不方便我们修改,将其替换成cache目录,

对应的cache目录为:/storage/emulated/0/Android/data/com.Dev.HybridCLRTrial/cache
在这里插入图片描述

3.2 运行android apk

此时,我们会看到如下界面,因为对应的cache目录里面读不到内容
在这里插入图片描述

3.3 热更新

修改HotFix文件下的代码
在这里插入图片描述
在这里插入图片描述
然后再打出bundle包
在这里插入图片描述
生成的bundle在StreamingAssets目录下
在这里插入图片描述
将其push到对应的cache目录当中,重启App,可以看到生效了
在这里插入图片描述
再更改一下代码,重新push,重启,发现已经生效了。
在这里插入图片描述
adb 脚本


import() {
    
    
    # rootImportPath="tobeimport/"
    # cd $rootImportPath

    transfer='/data/local/tmp/import/' #中转文件夹

    adb shell rm -rf $transfer
    adb shell mkdir $transfer
    

    adb push build_info $transfer
    adb push common $transfer

    adb shell run-as com.Dev.HybridCLRTrial cp -ri $transfer*  /storage/emulated/0/Android/data/com.Dev.HybridCLRTrial/cache/
}

import

猜你喜欢

转载自blog.csdn.net/hbdatouerzi/article/details/127693309