Kirito
Kirito

Reputation: 175

Network problem Unity game in Android version 9.0

I made a game using Unity for Android versions >= 6.0. The game runs well in versions < 9.0, but I have a problem with my Unity Game in Android 9.0.

I explain what happens: When the game starts for the first time, the player must login or sign up in the game (connecting with the database in the server). But in 9.0, when you run the game and choose one of those 2 options and touch the button to login/sing up, a message (which I made to notify the user that game cannot connect to the server because a network problem) appears.

What can be the cause of the problem? Maybe it is because of network permissions in Android 9.0?

Pd: I'm using http to connect to server.

Looking Google Console, I have 3 warnings:

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

This can be the problem because the game cannot do a request to the server?

Upvotes: 3

Views: 4806

Answers (2)

Ferhat Tepe
Ferhat Tepe

Reputation: 1

Just add 'android:usesCleartextTraffic="true"' in AndroidManifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

Upvotes: 0

Chirag Savsani
Chirag Savsani

Reputation: 6140

I also had same problem. I solved problem using below code

create new file network_security_config.xml under xml resource directory.

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>

And in AndroidManifest.xml file

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

</application>

Upvotes: 7

Related Questions