Android (9) Pie에서 모든 네트워크 연결 유형 HTTP 및 HTTPS를 허용하는 방법은 무엇입니까? 9 Pie에서 암호화가없는

이제 Android 9 Pie에서 암호화가없는 요청은 작동하지 않습니다. 기본적으로 시스템은 기본적으로 TLS를 사용하도록 요구합니다. 여기에서이 기능을 읽을 수 있습니다. 따라서 HTTPS를 통해서만 요청하면 안전합니다. 그러나 브라우저와 유사한 앱과 같이 다른 사이트를 통해 요청하는 앱은 어떻습니까?

Android 9 Pie에서 모든 유형의 연결 HTTP 및 HTTPS에 대한 요청을 활성화하려면 어떻게해야합니까?



답변

이를 구현하는 쉬운 방법 은 모든 요청에 ​​대해 모두 AndroidManifest.xml를 허용하는 위치 에이 속성을 사용 하는 것 http입니다.

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

그러나 경우에 당신은 몇 가지 원하는 많은 구성을 허용하는 예를 들어 다른 링크에 대한 http몇 가지 도메인이 아닌 사용자가 제공해야하는 다른 도메인 res/xml/networkSecurityConfig.xml파일을.

Android 9 Pie 에서이 작업을 수행하려면 다음 과 같이 networkSecurityConfig매니페스트 application태그에 a를 설정해야합니다 .

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config">




    </application>
</manifest>

그런 다음 xml폴더 에서 이제 network_security_config매니페스트에서 이름을 지정한 것과 같은 이름의 파일을 작성 해야하며 파일 컨텐츠는 암호화없이 모든 요청을 가능하게하려면 다음과 같아야합니다.

<?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>

거기에서 당신은 갈 수 있습니다. 이제 앱이 모든 유형의 연결을 요청합니다. 이 주제에 대한 추가 정보는 여기를 참조하십시오 .


답변

완전히 일하고 솔루션 모두 Android또는 React-native이 문제에 직면 사용자는이 추가
android:usesCleartextTraffic="true"
에서 의 AndroidManifest.xml 이 같은 파일 :

android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<uses-library
    android:name="org.apache.http.legacy"
    android:required="false" />

사이에 <application>.. </application>태그와 같이 :

<application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme"
        android:usesCleartextTraffic="true"
        tools:ignore="GoogleAppIndexingWarning">
        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"/>
 </application>

답변

간단한 방법이 android:usesCleartextTraffic="true"당신에게 설정 됩니다AndroidManifest.xml

android:usesCleartextTraffic="true"

당신의 AndroidManifest.xml모습

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.dww.drmanar">
   <application
       android:icon="@mipmap/ic_launcher"
       android:label="@string/app_name"
       android:usesCleartextTraffic="true"
       android:theme="@style/AppTheme"
       tools:targetApi="m">
       <activity
            android:name=".activity.SplashActivity"
            android:theme="@style/FullscreenTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
       </activity>
    </application>
</manifest>

이것이 도움이되기를 바랍니다.


답변

쉬운 방법

추가 usesCleartextTrafficAndroidManifest.xml에

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

앱이 일반 텍스트 HTTP와 같은 일반 텍스트 네트워크 트래픽을 사용할지 여부를 나타냅니다. API 레벨 27 이하 를 대상으로하는 앱의 기본값 은 “true”입니다. API 레벨 28 이상 을 대상으로하는 앱은 기본적으로 “false”입니다.


답변

파일 usesCleartextTraffic의 응용 프로그램 태그에 플래그를 설정 AndroidManifest.xml하십시오. Android 용 구성 파일을 만들 필요가 없습니다.

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

답변

React Native디버그에서 실행되는 응용 프로그램의 경우 xml block@Xenolion 에서 언급 한 react_native_config.xml위치를<project>/android/app/src/debug/res/xml

다음 스 니펫과 유사합니다.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="false">localhost</domain>
        <domain includeSubdomains="false">10.0.2.2</domain>
        <domain includeSubdomains="false">10.0.3.2</domain>
    </domain-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

답변

나는 같은 문제를 겪었고 보안 구성에 @Xenolion 답변과 같은 다른 태그가 있음을 알았습니다.

<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
    </domain-config>
</network-security-config>

그래서 “base-config”에 대한 TAGS “domain-config”를 변경하고 다음과 같이 작동합니다.

<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
    </base-config>
</network-security-config>