본문 바로가기
Frontend/React Native

[React Native] could not connect to development server 리액트 네이티브 오류 해결

by couque 2023. 4. 23.
반응형

리액트 네이티브로 개발하면서 발생하는 오류중에 오류 해결이 오래 걸릴때가 있는데 이번 오류가 그랬다.

해결방안을 많이 검색해서 수정해봤지만 해결되지는 않았고, 한참후에야 해결할 수 있었다.


현상

  - 앱이 실행은 되지만 소스를 수정해도 적용되지 않는다.

 

수정

  - 메트로 서버를 기동할때 npm start 명령어로 기동했는데, 아래 명령어로 실행했더니 변화가 있었다.

// 메트로 서버 기동
npx react-native start --reset-cache

// 안드로이드 시뮬레이터 기동
npx react-native run-android

npx로 기동했더니 아래와 같이 다른 오류가 발생했다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

위 오류는 Android > app > src > main > res > xml > network_security_config.xml 파일을 수정하여 해결했다.

오류메시지의 IP를 network_security_config.xml 파일의 includeSubdomains="true"로 설정하여 추가해준다.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">127.0.0.0</domain>
        <domain includeSubdomains="true">10.0.0.0</domain>
        <domain includeSubdomains="true">172.16.0.0</domain>
        <domain includeSubdomains="true">192.168.0.0</domain>
        <!-- 이곳에 오류메시지의 ip를 추가해준다. -->
    </domain-config>
</network-security-config>

 

반응형

댓글