問題の原因は次のとおりです。
Google は、ユーザー データとデバイスのセキュリティを確保するために、次世代 Android システム (Android P) 用のアプリケーションはデフォルトで暗号化された接続を要求すると述べました。これは、Android P では、アプリが暗号化されていない接続をすべて使用することを禁止することを意味します。 Android P システムの Android デバイスは、トラフィックの受信または送信に関係なく、将来的には平文で送信できなくなり、次世代 (Transport Layer Security) トランスポート層セキュリティ プロトコルを使用する必要があります。 Android Nougat と Oreo は影響を受けません。
解決:
1. HTTPS プロトコルを使用すると、暗号化されていないリクエストが回避されます。
2. TargetSdkVersion が 27 を下回ります。
3. ネットワーク セキュリティ構成 XML を追加します。
res の下に新しい xml ディレクトリを追加し、urls_config.xml という名前のファイルを作成します (名前はカスタマイズすることもできます)。内容は次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
APP の AndroidManifest.xml ファイルの下の application タグに次の属性を追加します。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.xxxx.xxx">
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:networkSecurityConfig="@xml/urls_config"
...
>
</manifest>
4. <code>android:usesCleartextTraffic 属性を Application タグの下に追加します。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.xxxx.xxx">
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...
>
</manifest>