LoginSignup
15
7

More than 3 years have passed since last update.

UnityでHTTP通信をするときのAndroid9(Pie)対応の件

Posted at

はじめに

Android9 (Pie)から、暗号化されてない通信はデフォルトでは無効になっており、通信を許可するためには設定が必要になります。Unityで、Android Manifestをカスタマイズするときにはまったので、設定方法を残しておこうと思いました。

Android Manifest側の設定

簡易編

<application android:usesCleartextTraffic="true"
        ...
</application>

上記のように設定すれば、HTTP通信はすべて通す設定になります。

詳細設定編

Android Manifestに次のように設定を書きます

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

次に、Plugins/Android/res/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>

とします。
もし、特定のドメインのみ平文を通したい場合は

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">www.example.com</domain>
    </domain-config>
</network-security-config>

注意
www.example.com
の部分は平文を通したいドメイン(自分で変更する)

まとめ

Android9(Pie)から、iOSのATSと同様の決まりがはいりました、上記のように設定を行ってセキュリティを高めてアプリを作成しましょう。

15
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
7