Cordova Android 8로 업그레이드 한 후 net :: ERR_CLEARTEXT_NOT_PERMITTED 오류가 표시되는 이유는 무엇입니까?


답변:


205

Cordova Android 플랫폼의 기본 API 레벨이 업그레이드되었습니다. Android 9 장치에서 이제 일반 텍스트 통신이 기본적으로 비활성화됩니다. .

일반 텍스트 통신을 다시 허용하려면 태그의을 다음 android:usesCleartextTraffic으로 설정하십시오 .applicationtrue

<platform name="android">
  <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
      <application android:usesCleartextTraffic="true" />
  </edit-config>
</platform>

주석에서 언급했듯이 android이전에 XML 네임 스페이스를 정의하지 않은 경우 error: unbound prefix빌드 중에이 표시됩니다. 이는 widget다음과 config.xml같이 동일한에서 태그에 추가해야 함을 나타냅니다 .

<widget id="you-app-id" version="1.2.3"
xmlns="http://www.w3.org/ns/widgets" 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cdv="http://cordova.apache.org/ns/1.0">

36
error: unbound prefix.Cordova 애플리케이션을 빌드하려고 할 때 오류 ( ) 가 발생했습니다 . 이 솔루션 내에서 추가되었다 config.xml내 루트에 파일 <widget>요소 속성xmlns:android="http://schemas.android.com/apk/res/android
— apiaget

@Der Hochstapler 답변에 apiagets 코멘트를 추가 할 수 있습니까?
— Michael B

@MichaelB 모든 사람이 답변을 편집 할 수 있으며 그렇게하는 것을 환영합니다. 하지만 당연히 할게요.
— Der Hochstapler

1
@SteevJames 변경 사항이 실제로 Android 프로젝트 구조에 유지되도록 Cordova 프로젝트를 다시 빌드 했습니까? AndroidManifest.xmlAndroid 프로젝트에서 변경 사항이 적용되었는지 확인 했습니까 ?
— Der Hochstapler

이 작업은하지만 제 경우에는 플랫폼 안드로이드를 제거한 다음 작동 한 후 제거해야합니다.
— kunal shaktawat

41

config.xml에서 수정해야 할 두 가지 사항이 있으므로 정답은 xml을 추가하는 것입니다.

<widget id="com.my.awesomeapp" version="1.0.0" 
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:cdv="http://cordova.apache.org/ns/1.0">

추가로 다음을 허용하도록 구성 편집 :

<platform name="android">
  <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
      <application android:usesCleartextTraffic="true" />
  </edit-config>
</platform>

1 단계를 피하는 경우 오류 : 언 바운드 접두사. 나타날거야


35

여기서 일반 텍스트는 암호화되지 않은 정보를 나타냅니다. Android 9 이후로 앱이 HTTPS API를 호출하여 이브 드롭이 없는지 확인하는 것이 좋습니다.

그러나 여전히 HTTP API를 호출해야하는 경우 다음을 수행 할 수 있습니다.

플랫폼 : Ionic 4

project-root / resources / android / xml 아래에 network_security_config.xml 이라는 파일을 만듭니다.

다음 줄을 추가하십시오.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
   <domain-config cleartextTrafficPermitted="true">
     <domain>ip-or-domain-name</domain>
   </domain-config>
</network-security-config>

이제 project-root / config.xml 에서 다음 줄을 업데이트합니다.

<platform name="android">
    <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:usesCleartextTraffic="true" />
        <application android:networkSecurityConfig="@xml/network_security_config" />
    </edit-config>
    ... other statements...

이제 작동합니다.


감사합니다. Ionic 4에서 저에게 효과적이었습니다. 도메인 이름 <domain> example.com </ domain>을 지정했고 작동했습니다. 또한이 "도움 가지고 developer.android.com/training/articles/security-config을 "
— 자키 모하메드

앱을 실행할 때마다 "<edit-config .."가 덮어 쓰여지는 이유는 무엇입니까?
— 트 Jalle

3
이것은 작동하지만 나는이 줄을 추가 할 필요가 config.xml전과 edit-config태그 : <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />. 감사!
— tyn

@ZakiMohammed도 같은 문제에 직면하고 있습니다.
— jose

@jose 내 대답에 좀 제발
— 자키 모하메드

26

문제를 해결하기 위해 다른 옵션이 있습니다. resources / android / xml / network_security_config.xml 파일에 있습니다. 끼워 넣다:

<network-security-config>
   <base-config cleartextTrafficPermitted="true">
       <trust-anchors>
           <certificates src="system" />
       </trust-anchors>
   </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain>localhost</domain>
        <domain includeSubdomains="true">192.168.7.213:8733</domain>
    </domain-config>
</network-security-config>

제 경우에는 IP 주소를 사용하고 있는데 base-config가 필요하지만 도메인이있는 경우입니다. 도메인을 추가하기 만하면됩니다.


수용된 모든 솔루션도 필요했지만이 답변이 제가 직면 한 문제의 핵심이었습니다.
— Peter Meadley

나를 위해 일했습니다. 감사합니다
— 하일 Mushtaq

감사합니다! 나는 또한 도메인 이름 대신 IP를 사용하고 있으며 귀하의 대답은 완벽하게 맞습니다!
— 초

22

오늘 직접이 문제에 직면했고 Apache Cordova 애플리케이션에 대해 Android 9 이상에서 일반 텍스트 트래픽을 수동으로 허용하려는 번거 로움을 덜어 줄 정말 멋진 플러그인을 발견했습니다. cordova-plugin-cleartext를 설치하기 만하면 플러그인이 Android의 모든 비하인드 스토리를 처리합니다.

$ cordova plugin add cordova-plugin-cleartext
$ cordova prepare
$ cordova run android

답을 찾는 다른 사람들을 위해. 구성 수정 사항을 적용 할 때 다른 오류가 계속 발생했지만 곧바로 작동했습니다. 감사합니다 토퍼
— IvanSt

나를 위해 작동합니다. 고마워!
— iwanuschka

나를 위해 일하지 않았다.
— Eskim0

15

며칠간의 투쟁 끝에 이것은 저에게 효과적이며 이것이 당신에게도 효과가 있기를 바랍니다.

이것을 코드 상단의 CONFIG.XML에 추가 하십시오.

<access origin="*" />
<allow-navigation href="*" />

그리고 이것은 플랫폼 안드로이드에서.

<edit-config file="app/src/main/AndroidManifest.xml" 
   mode="merge" target="/manifest/application" 
   xmlns:android="http://schemas.android.com/apk/res/android">
     <application android:usesCleartextTraffic="true" />
     <application android:networkSecurityConfig="@xml/network_security_config" />
 </edit-config>
 <resource-file src="resources/android/xml/network_security_config.xml" 
 target="app/src/main/res/xml/network_security_config.xml" />

이 파일 "resources / android / 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>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">YOUR DOMAIN HERE/IP</domain>
    </domain-config>
</network-security-config>

여기에 이미지 설명 입력

여기에 이미지 설명 입력



1
솔루션 주셔서 감사합니다. 그것은 나를 위해 일한 유일한 사람입니다.
— Lud Osorio

감사합니다. 저를 위해 일한 유일한 솔루션입니다.
— Gerardo Salazar Sánchez

이것은 나를 위해 일한 솔루션이었습니다. 특히 trust-anchors태그는 다른 모든 작업을 수행하는 최종 구성 요소 인 것처럼 보였습니다 .
— rolinger

phonegab 빌드를 사용하는 경우 루트 폴더에 network_security_config를 유지하고 경로를 resource-file src = "network_security_config.xml"로 지정합니다.
— mujaffars

12

여는 <widget> 태그 내에 다음 속성을 추가하면 저에게 효과적이었습니다. Android 9 에뮬레이터에서 간단하고 실시간으로 올바르게 다시로드됩니다. xmlns : android = "http://schemas.android.com/apk/res/android"

<widget id="com.my.awesomeapp" version="1.0.0" 
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:cdv="http://cordova.apache.org/ns/1.0">

2
나는이 대답을 보았을 때 깨닫지 못했지만 이것은 수락 된 대답 의 코드 에 추가되었습니다edit-config ( unbound prefix오류 수정 )
— RishiG

@RishiG 이제 완전한 정답을 설명하는 대답입니다
— zardilior

예 @zardilior, 롤 ... 편집에 대한 답을 하이재킹에 대한 그에게 축하
— 마크 맥 코클을

5

당신은 추가해야

<base-config cleartextTrafficPermitted="true">
    <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
</base-config>

에

resources / android / xml / network_security_config.xml

이렇게

<network-security-config>
<base-config cleartextTrafficPermitted="true">
    <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
</base-config>

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

이것이 왜 중요한가요?
— Tomas Vancoillie

5

다음은 나를 위해 일한 솔루션입니다. 내가 업데이트 한 파일은 다음과 같습니다.

  1. config.xml (전체 경로 : /config.xml)
  2. network_security_config.xml (전체 경로 : /resources/android/xml/network_security_config.xml)

해당 파일의 변경 사항은 다음과 같습니다.

1. config.xml

config.xml 파일의 <application android:usesCleartextTraffic="true" />태그 내에 <edit-config>태그를 추가 했습니다.

<platform name="android">
    <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:usesCleartextTraffic="true" />
        <application android:networkSecurityConfig="@xml/network_security_config" />
    </edit-config>
    ...
<platform name="android">

2. network_security_config.xml

이 파일에서는 프로젝트 요구 사항에 따라 <domain>태그 내에 2 개의 태그 <domain-config>, 기본 도메인 및 하위 도메인을 추가했습니다.

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

도움을 주신 @Ashutosh에게 감사드립니다.

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


제 하루를 구 해주셔서 감사합니다.
— Karnan Muthukumar

5

IONIC 5.4.13, cordova 9.0.0 (cordova-lib@9.0.1)을 사용하는 Im

정보를 반복 할 수 있지만 플러그인을 추가 한 후 문제가 나타나기 시작했습니다 (아직 확실하지 않음). 위의 모든 조합을 시도했지만 아무것도 작동하지 않았습니다. 다음을 추가 한 후에 만 ​​작동하기 시작했습니다.

   <base-config cleartextTrafficPermitted="true">
       <trust-anchors>
           <certificates src="system" />
       </trust-anchors>
   </base-config>

프로젝트의 파일

resources / android / xml / network_security_config.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>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">10.1.25.10</domain>
    </domain-config>
</network-security-config>

모두에게 감사합니다.


기존 Ionic 솔루션과 어떻게 다른가요?
— Der Hochstapler

상황이 다릅니다. 사람들이 Google 검색에서 여기로 온 것을 기억하십시오. 이 문제에 다른 상황과 설정이있을 수 있습니다. 제 경우에는 프로젝트가 잘 작동했고 플랫폼 업데이트 또는 장치 업데이트를 수행하지 않은 경우에도이 오류가 발생하기 시작했습니다.
— Rajendra

1
감사합니다. 이것은 저를 위해 일했습니다. :)-시간이 지남에 따라 특히 변덕스럽고 끊임없이 변화하는 프레임 워크에서 오래된 솔루션이 더 이상 작동하지 않기 때문에 작동하는 솔루션의 버전 업데이트를 확인하는 것이 좋습니다.
— 그랜트

2
고마워요 친구, 이것이 저에게 유일한 해결책이라고 말하고 싶었습니다
— Anakin001

2
감사. 이것은 내 문제를 해결했습니다. 다른 많은 제안을 시도했지만 작동하지 않았습니다.
— MasterJedi

3

이전 ionic cli (4.2)가 제 경우에 문제를 일으켰습니다. 5로 업데이트하여 문제를 해결했습니다.


감사합니다. 이것이 나를위한 해결책이었습니다. ionic cli 명령을 실행하기 위해 ionic을 설치하는 App Center에서 별도의 빌드 프로세스를 실행했습니다. 그들은 "@ ionic / cli"를 위해 "ionic"을 더 이상 사용하지 않습니다.
— MarkHoward02

0

cordova-custom-config플러그인을 사용하여 Android 구성을 관리하고 있습니다. 이 경우 해결 방법은 다음을 새로 추가하는 custom-preference것입니다 config.xml.

    <platform name="android">

        <preference name="orientation" value="portrait" />

        <!-- ... other settings ... -->

        <!-- Allow http connections (by default Android only allows https) -->
        <!-- See: /programming/54752716/ -->
        <custom-preference
            name="android-manifest/application/@android:usesCleartextTraffic"
            value="true" />

    </platform>

개발 빌드에만이 작업을 수행하는 방법을 아는 사람이 있습니까? 릴리스 빌드가이 설정을 벗어나면 기쁩니다.false .

(iOS 구성 제안 buildType="debug"을 보았지만 이것이 Android 구성에 적용되는지 확실하지 않습니다.)


0

@Der Hochstapler 솔루션에 감사드립니다.
그러나 IONIC 4 에서는 프로젝트 config.xml의 일부 사용자 정의 나를 위해 작동합니다.

위젯 태그에 줄 추가

<widget id="com.my.awesomeapp" version="1.0.0" 
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:cdv="http://cordova.apache.org/ns/1.0">

그 후, Android 용 플랫폼 태그에서 아래의 일부 줄을 사용자 정의하고 networkSecurityConfig 및 리소스 파일 태그 뒤에 usesCleartextTraffic = true를
추가 하십시오.

 <platform name="android">
        <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" />
        </edit-config>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
        <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:usesCleartextTraffic="true" />
        </edit-config>
    </platform>

기존 Ionic 솔루션과 어떻게 다른가요?
— Der Hochstapler

나는 하나의 <edit-config> 태그 안에 "android : networkSecurityConfig ="@ xml / network_security_config "와 함께"android : usesCleartextTraffic = "true"를 추가했습니다. 그래서 그것은 나를 위해 작동하지 않았고 새로운 <edit-config> 태그를 추가했을 때 "android : usesCleartextTraffic ="true ""를 입력하고 "android : networkSecurityConfig"<edit-config> 태그 뒤에 붙여 넣으면 작동합니다
— yash

0

Ionic 4 커패시터 프로젝트에서 테스트를 위해 패키징하고 Android 폰에 배포 할 때이 오류가 발생했습니다. 커패시터를 다시 설치하고 Android 플랫폼을 업데이트하여 문제가 해결되었습니다.

npm run build --prod --release
npx cap copy
npm install --save @capacitor/core @capacitor/cli
npx cap init
npx cap update android
npx cap open android

0

NPM 및 Cordova 명령에 문제가있는 레거시 Cordova 프레임 워크가있는 경우. 아래 옵션을 제안합니다.

android / res / xml / network_security_config.xml 파일 생성-

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
    <base-config cleartextTrafficPermitted="true" />
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">Your URL(ex: 127.0.0.1)</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>

기존 Ionic 솔루션과 어떻게 다른가요?
— Der Hochstapler

일부 레거시 프로젝트는 수동으로 업데이트해야하는 NPM 및 Cordova 명령을 따르지 않습니다.
— Pradeepta

0

다음 솔루션이 나를 위해 일했습니다.

이동 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>

0

이 줄을 platform / android / app / src / main / AndroidManifest.xml 파일에 추가하십시오.

<application android : hardwareAccelerated = "true"android : icon = "@ mipmap / ic_launcher"android : label = "@ string / app_name"android : supportsRtl = "true" android : usesCleartextTraffic = "true" >

당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.