programing

Android 8: 일반 텍스트 HTTP 트래픽이 허용되지 않음

linuxpc 2023. 6. 5. 23:40
반응형

Android 8: 일반 텍스트 HTTP 트래픽이 허용되지 않음

Android 8을 사용하는 사용자로부터 (백엔드 피드를 사용하는) 내 앱이 콘텐츠를 표시하지 않는다는 보고를 받았습니다.조사 결과 Android 8에서 다음과 같은 예외가 발생했습니다.

08-29 12:03:11.246 11285-11285/ E/: [12:03:11.245, main]: Exception: IOException java.io.IOException: Cleartext HTTP traffic to * not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:115)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:458)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at com.deiw.android.generic.tasks.AbstractHttpAsyncTask.doConnection(AbstractHttpAsyncTask.java:207)
at com.deiw.android.generic.tasks.AbstractHttpAsyncTask.extendedDoInBackground(AbstractHttpAsyncTask.java:102)
at com.deiw.android.generic.tasks.AbstractAsyncTask.doInBackground(AbstractAsyncTask.java:88)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

(패키지 이름, URL 및 기타 가능한 식별자를 제거했습니다.)

7작동하도록 Android 7을 설정하지 .android:usesCleartextTraffic을 매페스및트 (에니설정서및에)로 합니다.true도움이 되지 않습니다. 기본값입니다). 네트워크 보안 정보도 사용하지 않습니다.내가 전화하면NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted()그것은 돌아옵니다.false 8, Android 8의 »true이전 버전의 경우 동일한 apk 파일을 사용합니다.저는 안드로이드 O에 대한 구글 정보에서 이것에 대한 언급을 찾으려 했지만 성공하지 못했습니다.

네트워크 보안 구성에 따라 -

Android 9(API 레벨 28)부터는 일반 텍스트 지원이 기본적으로 비활성화됩니다.

Android M과 일반 텍스트 트래픽에 대한 전쟁도 살펴봅니다.

구글의 코드랩스 설명

옵션 1 -

처로을 URL 클니다로 .https://http://

옵션 2 -

res/xml/network_security_config.xml-

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">api.example.com(to be adjusted)</domain>
    </domain-config>
</network-security-config>

AndroidManifest.xml-

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

옵션 3 -

Android: Cleartext TrafficDoc 사용

AndroidManifest.xml-

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

또한 @david.지적된 s의 대답android:targetSandboxVersion가 될 도 있습니다.

매니페스트 문서에 따르면 -

android:targetSandboxVersion

이 앱이 사용할 대상 샌드박스입니다.샌드박스 버전 번호가 높을수록 보안 수준이 높아집니다.기본값은 1이며, 2로 설정할 수도 있습니다.이 속성을 2로 설정하면 앱이 다른 SELinux 샌드박스로 전환됩니다.레벨 2 샌드박스에는 다음과 같은 제한이 적용됩니다.

  • 은 다음과 .usesCleartextTraffic네트워크 보안 구성이 false입니다.
  • UID 공유는 허용되지 않습니다.

그래서 옵션 4 -

가지고 계신다면,android:targetSandboxVersion<manifest>그 다음으로 줄입니다.1

AndroidManifest.xml-

<?xml version="1.0" encoding="utf-8"?>
<manifest android:targetSandboxVersion="1">
    <uses-permission android:name="android.permission.INTERNET" />
    ...
</manifest>

Android 9에서 제 문제는 http로 도메인을 통해 웹 뷰를 탐색하는 것이었습니다. 이 답변의 해결책입니다.

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

그리고:

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>

Android Manifest에서 다음 매개 변수를 찾았습니다.

android:networkSecurityConfig="@xml/network_security_config"

@xml/network_security_config는 network_security_config.xml에서 다음과 같이 정의됩니다.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <!--Set application-wide security config using base-config tag.-->
    <base-config cleartextTrafficPermitted="false"/>
</network-security-config>  

방금 cleartextTrafficPermitted를 true로 변경했습니다.

디버깅하는 동안 일반 텍스트만 허용하고 프로덕션에서 일반 텍스트를 거부할 경우의 보안 이점은 유지할 수 있습니다.이것은 https를 지원하지 않는 개발 서버와 비교하여 앱을 테스트하기 때문에 유용합니다.다음은 프로덕션에서 https를 적용하지만 디버그 모드에서 일반 텍스트를 허용하는 방법입니다.

build.gradle에서:

// Put this in your buildtypes debug section:
manifestPlaceholders = [usesCleartextTraffic:"true"]

// Put this in your buildtypes release section
manifestPlaceholders = [usesCleartextTraffic:"false"]

AndroidManifest.xml의 응용 프로그램 태그

android:usesCleartextTraffic="${usesCleartextTraffic}"

좋아요, 그게 아니라 수천 번의 반복입니다.add it to your Manifest이를 기반으로 한 힌트를 제공하지만 추가 이점(및 배경 정보)을 제공합니다.


다음 솔루션을 사용하면 환경별 프로토콜(HTTP/HTTPS)을 설정할 수 있습니다.

이방으사수있다니습용을 사용할 수 .http및 DEV-Environment에 합니다.https항상 변경할 필요 없이 운영 환경에 적합합니다!일반적으로 로컬 또는 개발 환경에 대한 https 인증서가 없지만 프로덕션 환경 및 스테이징 환경에 대한 필수 인증서이기 때문에 이러한 인증서가 필요합니다.


Android에는 src-Directory에 대한 일종의 덮어쓰기 기능이 있습니다.

기본적으로 사용자는

/app/src/main

그러나 AndroidManifest.xml을 덮어쓰는 디렉터리를 추가할 수 있습니다.작동 방식은 다음과 같습니다.

  • 디렉토리 /app/src/debug 생성
  • AndroidManifest.xml을 만듭니다.

파일 안에는 모든 규칙을 넣을 필요가 없고 /app/src/main/AndroidManifest.xml에서 덮어쓰려는 규칙만 넣을 수 있습니다.

다음은 요청된 CLEARTEXT-Permission의 예입니다.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.yourappname">

    <application
            android:usesCleartextTraffic="true"
            android:name=".MainApplication"
            android:label="@string/app_name"
            android:icon="@mipmap/ic_launcher"
            android:allowBackup="false"
            android:theme="@style/AppTheme">
    </application>

</manifest>

이러한 지식을 통해 디버그 | main | 릴리스 환경에 따라 권한을 오버로드하는 것이 1,2,3만큼 쉽습니다.

거기서 얻을 수 있는 큰 이점은...프로덕션 매니페스트에 디버그 기능이 없으며, 유지 관리가 용이한 구조를 유지합니다.

가능하면 URL을 에서 로 변경합니다.

잘 되가요!!!

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">***Your URL(ex: 127.0.0.1)***</domain>
    </domain-config>
</network-security-config>

위의 제안에서 저는 제 URL을 http://xyz.abc.com/mno/ 로 제공하고 있었습니다.

는 그것을 xyz.abc.com 으로 바꾸었고 그것은 작동하기 시작했습니다.

누군가에게 유용할 수도 있습니다.

최근 Android 9에서도 동일한 문제가 발생했지만, WebView 내에서 일부 URL만 표시하면 됩니다. 특별한 문제는 없습니다.그래서 추가하는 중android:usesCleartextTraffic="true"매니페스토는 작동했지만, 우리는 이것 때문에 전체 앱의 보안을 손상시키고 싶지 않았습니다.그래서 해결책은 링크를 바꾸는 것이었습니다.httphttps

React Native 프로젝트의 경우

그것은 이미 RN 0.59에 고정되었습니다.0.58.6에서 0.59로의 업그레이드 차이를 확인할 수 있습니다. RN 버전을 업그레이드하지 않고 적용할 수 있습니다. 다음 단계를 따라야 합니다.

파일 만들기:

Android/app/src/src/res/res/xml/sl_native_config.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>
</network-security-config>

Android/app/src/디버그/AndroidManifest.xml -

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

  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

  <application tools:targetApi="28"
      tools:ignore="GoogleAppIndexingWarning" 
      android:networkSecurityConfig="@xml/react_native_config" />
</manifest>

승인된 답변을 확인하여 근본 원인을 알 수 있습니다.

이미 있는 안드로이드 매니페스트 파일에서 이 라인을 제거했습니다.

 android:networkSecurityConfig="@xml/network_security_config" 

추가됨

android:usesCleartextTraffic="true"

매니페스트의 응용 프로그램 태그에 입력합니다.

<application
    android:usesCleartextTraffic="true"
    android:allowBackup="true"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    >

그러면 overlay.openstreetmap.nl 에 대한 HTTP 트래픽 지우기가 허용되지 않음 오류가 Android 9 및 10에서 사라집니다.저는 이것이 안드로이드 8에도 효과가 있기를 바랍니다. 만약 당신이 투표하는 것을 잊지 않는다면 감사합니다.

Android:usesCleartextTraffic="true"...를 매니페스트 파일에 추가하면 문제가 해결되는 것처럼 보이지만 데이터 무결성에 위협이 됩니다.

보안상의 이유로 안드로이드에서 매니페스트 자리 표시자를 사용했습니다. 디버그 환경에서 클리어 텍스트만 허용하기 위해 매니페스트 파일 내의 CleartextTraffic을 사용합니다(: 승인된 답변의 옵션 3에 있는 경우 @Hrishikesh Kadam의 응답).

build.gradle(:app) 파일 안에 다음과 같은 매니페스트 자리 표시자를 추가했습니다.

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

        debug {
            manifestPlaceholders.cleartextTrafficPermitted ="true"
        }
    }

자리 표시자 이름 위의 이 줄에서 허용된 textTrafficPermitted를 확인합니다.

            manifestPlaceholders.cleartextTrafficPermitted ="true"

Android 매니페스트에서 같은 자리 표시자를 사용했습니다.

Android Manifest.xml -

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="${cleartextTrafficPermitted}"
        ...>
        ...
    </application>
</manifest>

따라서 일반 텍스트 트래픽은 디버그 환경에서만 허용됩니다.

간단하고 쉬운 솔루션 [Xamarin Form]

안드로이드용

  1. 에 가다Android Project 을 합니다.Properties,

여기에 이미지 설명 입력

  1. 을 엽니다.AssemblyInfo.cs이 코드를 바로 저기에 붙여넣습니다.

    [assembly: Application(UsesCleartextTraffic =true)]

여기에 이미지 설명 입력

iOS용

사용하다NSAppTransportSecurity:

여기에 이미지 설명 입력

은 야합해니다설을 .NSAllowsArbitraryLoads에 대한 열쇠.YESNSAppTransportSecurity전에있에 있는 info.plistjava.

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

플리스트 구성

좋아요, 제가 알아냈어요.은 Manifest 매페매변인발해생합다니 입니다.android:targetSandboxVersion="2"Instant App 버전도 있기 때문에 추가했습니다. 사용자가 Instant App에서 일반 앱으로 한 번 업그레이드하는 것보다 전송 시 데이터가 손실되지 않도록 해야 합니다.그러나 모호한 설명에서 알 수 있듯이:

이 앱에서 사용할 대상 샌드박스를 지정합니다.SANbox 버전이 높을수록 보안 수준이 높아집니다.

이 특성의 기본값은 1입니다.

적어도 Android 8에서는 분명히 새로운 수준의 보안 정책이 추가됩니다.

을 러한다답적위해기용에 .Xamarin.Android 및 vs.할 수 .AndroidManifest.xml

물론 인터넷 허가가 필요합니다.):

[assembly: UsesPermission(Android.Manifest.Permission.Internet)]

의 ": " " " " 에 추가됩니다.AssemblyInfo.csfile 모든 파일은 과 같습니다.using 에위그 에.namespace작동하다.

응용 프로그램 클래스에 " " " " " " " " " " " " (" " " " " " " " " " " 을 할 수 있습니다.NetworkSecurityConfigResources/xml/ZZZZ.xml파일 이름:

#if DEBUG
[Application(AllowBackup = false, Debuggable = true, NetworkSecurityConfig = "@xml/network_security_config")]
#else
[Application(AllowBackup = true, Debuggable = false, NetworkSecurityConfig = "@xml/network_security_config"))]
#endif
public class App : Application
{
    public App(IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer) : base(javaReference, transfer) { }
    public App() { }

    public override void OnCreate()
    {
        base.OnCreate();
    }
}

에 .Resources/xmlfolder)를 .xml폴더(필요한 경우).

»xml/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 includeSubdomains="true">notsecure.com</domain>
          <domain includeSubdomains="false">xxx.xxx.xxx</domain>
    </domain-config>
</network-security-config>

은 또한 있다니습수도를 할 수 .UsesCleartextTraffic에 있는 ApplicationAttribute:

#if DEBUG
[Application(AllowBackup = false, Debuggable = true, UsesCleartextTraffic = true)]
#else
[Application(AllowBackup = true, Debuggable = false, UsesCleartextTraffic = true))]
#endif

제게 효과적인 대답은 @Pablo Cegarra의 다음과 같습니다.

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

경고 메시지가 표시될 수 .cleartextTrafficPermitted="true"

'화이트리스트' 도메인을 알고 있는 경우 승인된 답변과 위 답변을 함께 사용해야 합니다.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="false">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">books.google.com</domain>
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </domain-config>
</network-security-config>

이 코드는 나에게 효과가 있지만, 내 앱은 books.google.com 에서만 데이터를 검색해야 합니다.이렇게 하면 보안 경고가 사라집니다.

또한 응용프로그램을 개발하는 동안 "일반 텍스트 HTTP 트래픽이 허용되지 않음" 오류가 발생합니다.애플리케이션에서 네트워크 통화에 Retrofit2를 사용하고 있으며 두 가지 프로젝트 환경(개발 및 프로덕션)이 있습니다.내 운영 도메인에 HTTPS 호출이 있는 SSL 인증서가 있으며 dev에는 https가 없습니다.구성이 빌드 맛에 추가됩니다.하지만 dev로 변경하면 이 문제가 발생합니다.그래서 저는 그것을 위해 아래의 해결책을 추가했습니다.

매니페스트에 일반 텍스트 트래픽을 추가했습니다.

 android:usesCleartextTraffic="true"

그런 다음 Retrofit 구성 클래스 OKHttp 생성 시간에 연결 사양을 추가했습니다.

 .connectionSpecs(CollectionsKt.listOf(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT))

전체 OkHttpClient 생성은 아래와 같습니다.

OkHttpClient okHttpClient = new OkHttpClient.Builder()
        .readTimeout(10, TimeUnit.SECONDS)
        .connectTimeout(10, TimeUnit.SECONDS)
        .cache(null)
        .connectionSpecs(CollectionsKt.listOf(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT))
        .addInterceptor(new NetworkInterceptor(context))
        .addInterceptor(createLoggingInterceptor())
        .addInterceptor(createSessionExpiryInterceptor())
        .addInterceptor(createContextHeaderInterceptor())
        .build();

2019년 12월 업데이트 이온 - 4.7.1

<manifest xmlns:tools=“http://schemas.android.com/tools”>

<application android:usesCleartextTraffic=“true” tools:targetApi=“28”>

Android manifest.xml 파일에 위 내용을 추가하십시오.

이온화 이전 버전

  1. 이 있는지 하세요.config.xmlIonic 프로젝트에서:

    <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
                <application android:networkSecurityConfig="@xml/network_security_config" />
                <application android:usesCleartextTraffic="true" />
            </edit-config>
    
  2. 이온성 코르도바 빌드 안드로이드를 실행합니다.플랫폼 아래에 Android 폴더를 만듭니다.

  3. Android Studio를 열고 Project-Platforms-Android에 있는 Android 폴더를 엽니다.그라들을 만들 수 있도록 몇 분간 그대로 둡니다.

  4. 나 뒤에gradle build되었습니다. 완되었다니를 합니다. 다음을 포함하여 몇 가지 오류가 발생했습니다.minSdVersionmanifest.xml이제 우리가 하는 것은 단지 제거하는 것입니다.<uses-sdk android:minSdkVersion="19" />manifest.xml.

    다음 두 위치에서 모두 제거해야 합니다.

    1. → 앱 → 매스트페 →AndroidManifest.xml.
    2. → CordovaLib → 코르도바Lib →AndroidManifest.xml.

    이제 Gradle을 다시 구축해 보십시오. 이제 성공적으로 구축됩니다.

  5. → App → 앱 → 앱 → 앱 앱 의 앱 과 같은 내용이 합니다.Androidmanifest.xml:

    <application
    android:networkSecurityConfig="@xml/network_security_config"  android:usesCleartextTraffic="true" >
    
  6. 을 엽니다.network_security_config→ → (app → res → xml →network_security_config.xml).

    다음 코드를 추가합니다.

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

여기서xxx.yyyy.com APIHTTP API의 입니다.URL Http를 포함하지 하십시오.

참고: 이제 Android Studio(Build -- Build Bundle's/APK -- Build APK)를 사용하여 앱을 구축하면 해당 앱을 사용할 수 있으며 Android Pie에서 잘 작동합니다.이온성 Cordova 빌드 안드로이드를 사용하여 앱을 구축하려고 하면 이러한 모든 설정이 무시되므로 반드시 Android Studio를 사용하여 프로젝트를 구축해야 합니다.

이전 버전의 앱이 설치되어 있으면 제거하고 시도해 보십시오. 그렇지 않으면 다음과 같은 오류가 발생합니다.

앱이 설치되지 않음

dev와 prod 네트워크 구성을 모두 추가할 것을 제안합니다.

address/xml/network_security_config_dev.xml

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

address/xml/network_security_config_security.xml

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

Gradle Scripts(안드로이드 스튜디오)에서 build.gradle(안드로이드.app)을 찾아 빌드를 찾습니다.유형: 릴리스 디버그(존재하지 않는 경우 생성):

buildTypes {

release {
    minifyEnabled false
    manifestPlaceholders.securityConfig = "@xml/network_security_config_prod"
 }

 debug {
    manifestPlaceholders.securityConfig = "@xml/network_security_config_dev"
 }

}

AndroidManifest.xml에서 다음과 같이 securityConfig 자리 표시자를 사용합니다(build.gradle에 정의됨).

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:networkSecurityConfig="${securityConfig}"   <------- here

파일 생성 - res / xml / network_security.xml

network_security.xml ->

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

AndroidManifests.xml 열기:

 android:usesCleartextTraffic="true" //Add this line in your manifests

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
        android:theme="@style/AppTheme">
 cleartext support is disabled by default.Android in 9 and above

 Try This one I hope It will work fine

1 Step:->  add inside android build gradle (Module:App)
            useLibrary 'org.apache.http.legacy'

  android {
               compileSdkVersion 28
              useLibrary 'org.apache.http.legacy'

          }

그다음 2단계 :-> 매니페스트 앱 태그 안에 매니페스트 추가

<application
    android:networkSecurityConfig="@xml/network_security_config">//add drawable goto Step 4

   // Step --->3  add to top this line  
     <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

</application>

//4단계-->> 그리기 가능한 만들기>>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>

에 .resources/android/xml/network_security_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

이것으로 해결됩니다.Failed to load resource: net::ERR_CLEARTEXT_NOT_PERMITTEDAndroid for Cordova / Ionic은 Android를 지원합니다.

Android를 추가하기만 하면 됩니다. AndroidManifest.xml 파일의 내부에서 CleartextTraffic="true"를 사용합니다.

나의 경우에도 그 URL은 브라우저에서도 작동하지 않습니다.

저는 https://www.google.com/ 에 확인합니다.

webView.loadUrl("https://www.google.com/")

그리고 그것은 저에게 효과가 있었습니다.

사마린을 위해서.Android 개발자는 HttpClient 구현 및 SSL/TLS가 기본값으로 설정되어 있는지 확인합니다.

Andorid 옵션 -> 고급 Android 옵션에서 확인할 수 있습니다.

여기에 이미지 설명 입력

이 작업은 보안상의 이유로 수행되므로 가능한 경우 항상 HTTPS(HTTP Secure)를 사용하는 것이 좋습니다.
자세한 내용은 여기를 참조하십시오.

이 문제는 사용자의 상태에 따라 여러 가지 해결 방법이 있습니다.

제1자 서비스와 통신하려는 경우, 즉 사용자의 웹 서버

서버 측:해당 서버에 HTTPS 지원을 추가하고 HTTP 대신 HTTPS를 사용해야 합니다.요즘에는 암호화 허용 의 서비스를 사용하여 무료로 실행할 수도 있습니다.
클라이언트 측:사용 중인 경우HttpURLConnectionjava.net HttpsURLConnection의 시대의java.net.ssl패키지, 동일하지는 않지만 유사한 API를 가지고 있기 때문에 스위치를 쉽게 전환할 수 있습니다.

Google, Facebook, 날씨 서비스 등과 같은 타사 서비스를 사용하는 경우.

HTTPS를 지원), 을 "" "" "" "" "" "" "" ""에서 .http://abc.xyzhttps://abc.xyz.

마지막 방법으로 통신하려는 타사 서비스가 HTTPS 또는 다른 형태의 보안 통신을 지원하지 않는 경우 대답을 사용할 수 있지만, 이 대답은 매우 필요한 보안 기능의 목적을 충족하지 못하기 때문에 권장되지 않습니다.

ionic사용하고 있는데 네이티브 http 플러그인 중에 이 오류가 발생하면 다음 수정이 필요합니다.

에 가다resources/android/xml/network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">api.example.com(to be adjusted)</domain>
    </domain-config>
</network-security-config>

저한테 효과가 있었어요!

저는 코르도바-하이브리드-하이브리드 1.3.4와 함께 코르도바 8을 사용하고 있으며 기본적으로 앱이 인터넷에 액세스할 수 없으며 매니페스트.xml -> 안드로이드:usesCleartextTraffic="true"에 매개 변수만 추가합니다.

Cordova 8에서 변경된 mainfest 경로: platform/Android/app/src/main/AndroidManifest.xml.

 <?xml version='1.0' encoding='utf-8'?>
    <manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="io.cordova.hellocordova" xmlns:android="http://schemas.android.com/apk/res/android">
        <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
        <application 
android:hardwareAccelerated="true" 
android:icon="@mipmap/ic_launcher" 
android:label="@string/app_name" 
android:supportsRtl="true" 
android:usesCleartextTraffic="true">
            <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
                <intent-filter android:label="@string/launcher_name">
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    </manifest>

당신의 앱이 인터넷에 접속할 필요가 있다는 것이 명백하기 때문에 이것은 정말 바보 같습니다.

비디오 보기에서 이 비디오를 열 수 없음 온라인 비디오

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>

응용 프로그램의 AndroidManifest.xml 파일에 새로 추가됨:

android:networkSecurityConfig="@xml/network_security_config"

https://techprogrammingideas.blogspot.com/2021/02/android-code-for-displaying-video-with.html

https://youtu.be/90hWWAqfdUU

React Native 0.58.5 이상 버전으로 업그레이드합니다.그들은 가지고 있습니다.includeSubdomainRN 0.58.5의 구성 파일에 있습니다.

로그 변경

0은 Rn 0.58을 했습니다.5에서 그들은 선언했습니다.network_security_config서버 도메인과 함께 사용할 수 있습니다.네트워크 보안 구성을 통해 앱은 특정 도메인의 일반 텍스트 트래픽을 허용할 수 있습니다.따라서 추가적인 노력을 들일 필요가 없습니다.android:usesCleartextTraffic="true"매니페스트 파일의 응용 프로그램 태그에 있습니다.RN 버전 업그레이드 후 자동으로 해결됩니다.

API 버전 9.0을 변경한 후 xamarin, xamarin.dll 및 Android studio에서 YOUR-API.DOMAIN.COM에 대한 HTTP 트래픽 지우기가 허용되지 않습니다(targetSdkVersion="28").

사마린, 사마린.안드로이드, 안드로이드 스튜디오에서 이 오류를 해결하기 위한 두 단계.

1단계: 파일 리소스/xml/network_security_config.xml 생성

network_security_config.xml에서

<?xml version="1.0" encoding="utf-8" ?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">mobapi.3detrack.in</domain>
  </domain-config>
</network-security-config>

2단계: AndroidManifest.xml 업데이트 -

응용 프로그램 태그에 rodroid:networkSecurityConfig="@xml/network_security_config"를 추가합니다. 예:

<application android:label="your App Name" android:icon="@drawable/icon" android:networkSecurityConfig="@xml/network_security_config">

언급URL : https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted

반응형