Bootstrap

UE5的IOS项目打包为framework导入flutter项目经验总结

目前在做的项目是双端(安卓和IOS)作为动态链接库或者framework导入到flutter项目中去使用。这篇文章主要介绍IOS端打包为framework在flutter项目中使用的经验。

编译引擎源码

1.下载源码
下载地址:https://github.com/EpicGames/UnrealEngine
我下载的版本是5.1版本,详细过程在此不做介绍。

2.Mac上允许安装任何来源软件
下载源码后直接运行.sh文件会被mac阻止并提示无法确认软件来源,需要设置一下。
参考:https://zhuanlan.zhihu.com/p/51328476

最后在安全性设置界面设置如下:
在这里插入图片描述
*3.生成XCode工程并编译

然后点击setup.sh就可以进行环境setup了,setup.sh跑完后就可以点击GenerateProjectFiles.sh就可以生成xcode工程了,然后打开workspace编译即可。
在这里插入图片描述
编译以后就可以愉快的在Mac上打开UE了!

开发中的坑

APP的状态

在开发中,出现了一些Bug:应用退出到桌面再切回来回没有声音,并且有时候会出现屏幕上异常显示粉色。

在这里插入图片描述
异常显示的错误日志:

[UE] [2024.03.12-09.35.12:431][429]LogMetal: Warning: <CaptureMTLCommandBuffer: 0x28528c3c0> -> <MTLDebugCommandBuffer: 0x10786a000> -> <AGXA12FamilyCommandBuffer: 0x106ad6ae0>
    label = Frame 427 
    device = <AGXA12XDevice: 0x10b0ebc00>
        name = Apple A12Z GPU 
    commandQueue = <AGXA12FamilyCommandQueue: 0x107313960>
        label = <none> 
        device = <AGXA12XDevice: 0x10b0ebc00>
            name = Apple A12Z GPU 
    retainedReferences = 0
[UE] [2024.03.12-09.35.12:432][429]LogUnLua: GameState DoScoreRank
Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (00000006:kIOGPUCommandBufferCallbackErrorBackgroundExecutionNotPermitted)
Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (00000006:kIOGPUCommandBufferCallbackErrorBackgroundExecutionNotPermitted)
[UE] [2024.03.12-09.35.12:472][430]LogMetal: Warning: <CaptureMTLCommandBuffer: 0x28528ccc0> -> <MTLDebugCommandBuffer: 0x10786a000> -> <AGXA12FamilyCommandBuffer: 0x106ad6ae0>
    label = Prologue ClearGPUMessageBuffer 
    device = <AGXA12XDevice: 0x10b0ebc00>
        name = Apple A12Z GPU 
    commandQueue = <AGXA12FamilyCommandQueue: 0x107313960>
        label = <none> 
        device = <AGXA12XDevice: 0x10b0ebc00>
            name = Apple A12Z GPU 
    retainedReferences = 0
Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (00000006:kIOGPUCommandBufferCallbackErrorBackgroundExecutionNotPermitted)
Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (00000006:kIOGPUCommandBufferCallbackErrorBackgroundExecutionNotPermitted)
[UE] [2024.03.12-09.35.12:475][431]LogMetal: Warning: <CaptureMTLCommandBuffer: 0x28528c240> -> <MTLDebugCommandBuffer: 0x107988e00> -> <AGXA12FamilyCommandBuffer: 0x106abfd70>
    label = Frame 428 
    device = <AGXA12XDevice: 0x10b0ebc00>
        name = Apple A12Z GPU 
    commandQueue = <AGXA12FamilyCommandQueue: 0x107313960>
        label = <none> 
        device = <AGXA12XDevice: 0x10b0ebc00>
            name = Apple A12Z GPU 
    retainedReferences = 0
[UE] [2024.03.12-09.35.12:475][431]LogMetal: Warning: <CaptureMTLCommandBuffer: 0x28528cd80> -> <MTLDebugCommandBuffer: 0x107bbc400> -> <AGXA12FamilyCommandBuffer: 0x106a6ae10>
    label = Frame 428 
    device = <AGXA12XDevice: 0x10b0ebc00>
        name = Apple A12Z GPU 
    commandQueue = <AGXA12FamilyCommandQueue: 0x107313960>
        label = <none> 
        device = <AGXA12XDevice: 0x10b0ebc00>
            name = Apple A12Z GPU 
    retainedReferences = 0
Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (00000006:kIOGPUCommandBufferCallbackErrorBackgroundExecutionNotPermitted)

经过查阅资料后,发现是应用在后台时还继续提交GPUTask,这个情况是不被苹果允许的。所以重写IOSAppDelegate中的两个函数即可。

func applicationWillResignActive(_ application: UIApplication) {
    //Pause or suspend any operations using Metal
}

func applicationDidBecomeActive(_ application: UIApplication) {
    //Resume or start operations using Metal
}

https://stackoverflow.com/questions/59805668/execution-of-the-command-buffer-was-aborted-due-to-an-error-during-execution-o

最后的AppDelegate.mm

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [super applicationDidEnterBackground:application];
    [UnrealContainerView AllowUnrealToSleep];
}


- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [super applicationWillEnterForeground:application];
    [UnrealContainerView WakeUpUnreal];
}


// Do not remove, some clients may be calling these via `super`.
- (void)applicationWillResignActive:(UIApplication*)application {
    [super applicationWillResignActive:application];
}
// Do not remove, some clients may be calling these via `super`.
- (void)applicationDidBecomeActive:(UIApplication*)application {
    [super applicationDidBecomeActive:application];
}
// Do not remove, some clients may be calling these via `super`.
- (void)applicationWillTerminate:(UIApplication*)application {
    [super applicationWillTerminate:application];
}

修改后切换回来没声音以及异常显示的Bug就解决了。

;