2022년 10월 20일 목요일

[Flutter] Android Studio에서 에뮬레이터 사용 시 알면 도움이 되는 정보

😃 안녕하세요. 10.0.2.2 ip를 이야기 해 봅니다.

Android Studio 를 사용하면서, 에뮬레이터를 통해 빌드한 화면테스트를 합니다.

대부분의 앱은 서버와의 통신으로 데이터를 화면에 표시하는 모습입니다.

서버개발자가와 협업을 하면, 서버 개발자가 API를 개발하고 개발한 API를 앱 개발자가 사용합니다.

그러나, 서버개발과 앱개발을 혼자서 하는 경우도 많습니다. 

서버에서 동작하는 API를 개발 할때, 앱개발 요청 시 API 동작의 정상여부 및 필요사항을 모두 확인해서 수정 및 완료하고, 앱개발을 들어 갈 수 있다면, 정말 좋은 개발 프로세스 일 것입니다.

하지만, 모두 테스트하고 제대로 동작하는 API를 개발했더라도, 앱개발 시, API 요청 시에, 앱에서의 요청시 좀더 부드럽고 편리한 뷰가 보이게 될 수 있습니다.

그래서 앱과 서버의 서비스 동시에 디버깅하며 서버 서비스 개발도 보완하고, 앱도 더 잘 만들고 싶을 것입니다.

그러면 서버의 서비스하는 API를 localhost에서 디버깅모드로 피시내에서 실행 할 수 있다면, 편리하게 앱도 피시에서 실행하며 서버의 API 개발 디버깅과 앱 디버깅을 동시에 할 수 있을 것 입니다. 

그 때 로컬 피시에서의 디버깅 하는 앱에서 동일한 로컬 피시에서의 디버깅 하며 실행 시킨 서버의 API 호출 요청 시, 앱에서는 http://localhost:8080 또는 http://127.0.0.1:8080 과 같은 URL을 이용하고 싶을 것 입니다.

하지만, 앱에서 http://localhost:8080 또는 http://127.0.0.1:8080 이렇게 요청을 하면(하위 경로는 편의상 생략하여 설명중) 서버의 API로부터 호출 거절 수신을 앱에서 받게 될 것 입니다.

앱에서는 localhost 또는 127.0.0.1  대신, 10.0.2.2를 사용 해야 localhost또는 127.0.0.1 로 호출 하는 것 처럼 호출이 가능합니다.

따라서, 앱에서는 http://10.0.2.2:8080 이런 식 으로 로컬 피시내의 API를 호출 해야 합니다.

앱 개발에 사용해 보세요. 이상입니다.😉


- English - 

While using Android Studio, test the screen built through the emulator.


Most apps display data on the screen by communicating with the server.


If you collaborate with a server developer, the server developer develops the API and the app developer uses the developed API.


However, there are many cases where I do server development and app development alone.


When developing an API that operates on the server, it would be a really good development process if you can check whether the API operation is normal and all the necessary requirements when requesting an app development, modify and complete it, and start developing the app.


However, even if you have tested all of them and developed an API that works properly, you may see a smoother and more convenient view when developing an app, requesting an API, or requesting from an app.


So, you will want to debug the app and the server service at the same time, complement the server service development, and make the app better.


Then, if you can run the server's serviced API on the PC in debugging mode on localhost, you can conveniently run the app on the PC and simultaneously debug the server's API development and app.


At that time, when the application debugging on the local PC requests the API call of the server that was executed while debugging on the same local PC, the app uses a URL such as http://localhost:8080 or http://127.0.0.1:8080 you will want to


However, if the app makes a request like http://localhost:8080 or http://127.0.0.1:8080 (the sub-path is omitted for convenience), the app will receive a call rejection from the server's API.


In the app, instead of localhost or 127.0.0.1, 10.0.2.2 should be used so that calls can be made as if calling localhost or 127.0.0.1 .


So, your app should call http://10.0.2.2:8080 something like this.


Try it for app development. That is all.


댓글 없음:

댓글 쓰기