Android 版本 9.0 中的网络问题 Unity 游戏

Network problem Unity game in Android version 9.0

我使用 Unity 为 Android 版本 >= 6.0 制作了一个游戏。游戏 运行 在版本 < 9.0 中运行良好,但我的 Unity 游戏在 Android 9.0 中有问题。

我解释一下会发生什么: 首次开始游戏时,玩家必须在游戏中登录或注册(连接服务器中的数据库)。但是在 9.0 中,当你 运行 游戏并选择这两个选项之一并触摸按钮 login/sing 时,一条消息(我用来通知用户游戏无法连接到服务器,因为出现网络问题。

问题的原因可能是什么?也许是因为 Android 9.0 中的网络权限?

Pd: 我正在使用 http 连接到服务器。

查看 Google 控制台,我有 3 个警告:

The following APIs are on a gray list and Google cannot guarantee that they work on the available versions of Android. It is possible that some of them are restricted in your target SDK.

Google Play Console warnings

这可能是游戏无法向服务器发出请求的问题?

我也遇到了同样的问题。我使用以下代码解决了问题

在 xml 资源目录下创建新文件 network_security_config.xml

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

并且在 AndroidManifest.xml 文件中

<application
..............
android:networkSecurityConfig="@xml/network_security_config"
....... />

</application>