LoginSignup
1
1

More than 1 year has passed since last update.

Android Emulatorで「Cleartext HTTP traffic to ${IP} not permitted」エラーが出た場合の対応方法

Last updated at Posted at 2023-06-12

エラー内容

Cleartext HTTP traffic to ${IP} not permitted

原因

Android9からHTTP通信がデフォルトで無効になっている模様。

対策

AndroidManifest.xmlに「usesCleartextTraffic=true」を設定することで回避できる

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"  追加
        tools:targetApi="31"> 

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
1
1
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
1
1