Реагировать на собственную ошибку сети Android для вызовов http / https - PullRequest
0 голосов
/ 08 октября 2019

Я получаю следующую ошибку для любого вызова Http в эмуляторе Android (iOS работает нормально). Реактивный собственный отладчик имеет следующую ошибку. Ошибка происходит для любого HTTP-вызова в Android. Этого раньше не было, но недавно я перешел на RN 0,61 и понял, что HTTP-вызовы Android больше не работают.

Факты:

  1. Все мои вызовы эмулятора - все https://some -app.heroku.com
  2. Я думал, что это была проблема Android 8: HTTP-трафик в незашифрованном виде не разрешен , поэтому я обновил код с настройкой безопасности с помощью XMLфайл и включите этот файл в файл манифеста.
Error: Network Error
    at createError (http://localhost:8081/index.delta?platform=android&dev=true&minify=false&revisionId=653392ffc5065533:102999:17)
    at XMLHttpRequest.handleError (http://localhost:8081/index.delta?platform=android&dev=true&minify=false&revisionId=653392ffc5065533:102907:16)
    at XMLHttpRequest.dispatchEvent (http://localhost:8081/index.delta?platform=android&dev=true&minify=false&revisionId=653392ffc5065533:32303:27)
    at XMLHttpRequest.setReadyState (http://localhost:8081/index.delta?platform=android&dev=true&minify=false&revisionId=653392ffc5065533:31387:20)
    at XMLHttpRequest.__didCompleteResponse (http://localhost:8081/index.delta?platform=android&dev=true&minify=false&revisionId=653392ffc5065533:31214:16)
    at http://localhost:8081/index.delta?platform=android&dev=true&minify=false&revisionId=653392ffc5065533:31324:47
    at RCTDeviceEventEmitter.emit (http://localhost:8081/index.delta?platform=android&dev=true&minify=false&revisionId=653392ffc5065533:3317:37)
    at MessageQueue.__callFunction (http://localhost:8081/index.delta?platform=android&dev=true&minify=false&revisionId=653392ffc5065533:2618:44)
    at http://localhost:8081/index.delta?platform=android&dev=true&minify=false&revisionId=653392ffc5065533:2331:17
    at MessageQueue.__guard (http://localhost:8081/index.delta?platform=android&dev=true&minify=false&revisionId=653392ffc5065533:2572:13)

AndroidManifest.xml

<application android:networkSecurityConfig="@xml/network_security_config" android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
   .....
</application>

Конфигурация безопасности

<?xml version="1.0" encoding="utf-8" ?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">10.0.2.2</domain> <!-- Debug port -->
        <domain includeSubdomains="true">xxxxxx.herokuapp.com</domain>
    </domain-config>
</network-security-config>

android / build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'com.google.gms:google-services:4.3.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

Мои эмуляторы (не работает ни в одном из них)

Emulators

...