After lastFlutter Integrated with Unity Trampling Journey

Currently, the 3D project of the company has basically completed the alpha version, and we are going to conduct internal testing. From the completion of the first version to the current internal testing version, we have also stepped into some pits, as shown below.

Question 1:

In the previous article, the solution was to uninstall the scene resources and pause the Unity player when exiting the Unity page. This reduced the memory footprint of the app as much as possible, but only by a limited amount.

Solution process:

The flutter_unity_widge plugin is implemented by connecting unity view textures to the flutter layer via PlatformView. The previous approach is based on this plug-in, and the problem can be solved better without this plug-in.

Solution:

Make your own plug-ins. The best way to get Unity to release all resources is to call quit() to terminate the process, so when we start a new process in Unity, we can immediately terminate the process when we exit without affecting the current flutter process.

To do this, create a plugin, create an Activity in the Android project, inherit UnityPlayerActivity (this Activity contains some basic methods related to the Unity page), and when opening the Unity page, Start the Activity we created with a new process

This allows you to run Unity in a new process.

Because the Unity process is not in the same process as the flutter process, a cross-process communication may be required to communicate with flutter. At present, our project does not involve frequent communication, so we have not done it for the time being. If we do it later, we will continue to update it.

Question 2:

The company’s Flutter project uses AliPlayer, an open source player from Alibaba Cloud. After completing the first version of its development, tests found that AliPlayer played abnormally on Huawei’s Hongmeng system.

Solution process:

At the beginning, we started to troubleshoot the problem from Unity, and solved the problem by modifying unity’s related packaging configuration. After several attempts, we found that this way was blocked.

After checking the problem in Aliplayer, it was found that there was a problem when the video texture of the native layer was connected to the flutter layer. Pull down the source code of Aliplayer and check it. It was found that the textures of the native Aliplayer and the flutter layer were connected through AndroidView. So the solution is to bypass AndroidView and connect native textures to flutter by other means.

Solution:

This article describes how to use Hybrid Composition to connect native textures to flutter.

The WebView plugin used in the Flutter project, the Autoramap plugin, and some other plugin for AndroidView can all be used in this way to solve the problem on the Hongmun system.

Stay tuned for an update on the IOS packaging issue.