A number of reports where received about crashes when the showFloatWindow API is called on devices running older versions of EMUI. Lets take a look at this crash today and how we can fix the issue.
Start by integrating version 6.1.0.301 of the Game Service SDK into a project and successfully implemented the floating window function.
Then, when testing the game on devices running a version of EMUI earlier than 9.1, the game crashed when showFloatWindow API is called. The crash logs are as follows.
The error logs suggested that the issue was caused by missing layout files during layout implementation. This error suggests that c_buoycircle_window_small.xml, c_buoycircle_hide_notice.xml, and c_buoycircle_hide_guide_dialog.xml layout files were not found in this project. However, they had been saved under the layout folder as displayed in the following figure.
The next possible issue could have been that the layout files were obfuscated. So, lets check the build file to be sure:
As you can see minifyEnabled was set to true, indicating that the obfuscation function was enabled. This was also the case for shrinkResources, which meant that resource files were excluded during package creation.
One option of course would be to simply disable the shrinking of resources. By commenting out this line the game would run fine and the API call wouldn't crash, however the resource files are not longer compressed and will take up much more space.
To compress the resources, you can create an XML file that contains the resources tag in the project or use the keep.xml file in the res/raw directory, and specify the resources to be reserved in the tools:keep attribute as follows:
This solution allows the floating window function to work and is able to compress the resource files.
Note: If you have integrated the Game Service SDK, Huawei suggests that you add the following resources and configure the following obfuscation scripts.
@drawable/c_buoycircle*
@drawable/hms_game*
@layout/c_buoycircle*
@layout/hms_game*
@strings/hms_game*
@strings/c_buoycircle*
Top comments (0)