Programming/Android
CLEARTEXT communication to [TARGET_ADDRESS] not permitted by network security policy
은곰군
2019. 11. 8. 18:27
반응형
HTTP 통신 라이브러리를 Volley
에서 Retrofit2
로 변경한 뒤, targetSDKVersion
값을 28로 변경하자 잘 되던 HTTP 통신이 동작하지 않는다. 이상하다싶어서 브레이크 포인트를 걸고 확인해보니 onResponse
도 아닌 onFailure
에 걸렸는데, CLEARTEXT communication to [TARGET_ADDRESS] not permitted by network security policy
에러가 뜨고 있었다. 다른게 아니라 Android 9.0
부터는 기본적으로 HTTP로 접속하는 것을 막기 때문이라고 한다. (참고: Protecting users with TLS by default in Android P
물론 서버에서 HTTPS로 설정할 수 있다면 만사 OK지만, 나의 경우에는 HTTP/HTTPS 모두 지원해야했다. 이러한 경우에는 AndroidManifest.xml
의 Application
항목에 usesCleartextTraffic
을 true로 설정해주면 정상적으로 동작하는 걸 확인할 수 있다.
<application
android:usesCleartextTraffic="true">
참고:
Protecting users with TLS by default in Android P
Androidの通信ライブラリの歴史を振り返る
https://gun0912.tistory.com/80, 박상권의 삽질블로그\
반응형