250x250
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |
Tags
- Bloc
- 잡담
- Flutter
- 템플릿
- K&R
- VMware
- 개발기
- 주유소
- 에러
- 퇴근길
- 일상
- 오블완
- 리눅스
- 객체지향프로그래밍
- 오토바이
- ubuntu
- 휘발류
- 개발
- 가상머신
- podman
- C언어
- node.js
- VM
- Linux
- DART
- virtualmachine
- FreeBSD
- 인프라
- 연습문제
- 티스토리챌린지
Archives
- Today
- Total
그냥저냥
Dart/Flutter | macOS에 네트워크 권한 오류 해결하기 본문
728x90
반응형
API 서비스를 node.js로 개발중이다. 서버에 연결하여 API 테스트도 해야한다. 그래서 Flutter 프로젝트를 새로 생성했다. 사용중인 OS는 macOS이다. 프로젝트 생성하고 빠르게 Dio 패키지를 설치했다.
$ flutter pub add dio
lib/main.dart 파일에 main() 함수에 아래와 같이 수정을 했다.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final dio = Dio(BaseOptions(
baseUrl: 'http://localhost:4000',
connectTimeout: defaultConnectTimeout(),
receiveTimeout: defaultReceiveTimeout(),
));
await dio.get('/users');
// runApp(const MyApp());
}
터미널에서 flutter run -d macos 명령을 실행했다.
이후 런타임 에러가 발생하였다.
$ flutter run -d macos
Launching lib/main.dart on macOS in debug mode...
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00008103-000654E0142A001E, name:My Mac }
{ platform:macOS, arch:x86_64, id:00008103-000654E0142A001E, name:My Mac }
Building macOS application...
✓ Built build/macos/Build/Products/Debug/pitin_v2.app
Failed to foreground app; open returned 1
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: DioException [connection error]: The connection errored: Connection failed This indicates an error which most likely cannot be solved by the library.
Error: SocketException: Connection failed (OS Error: Operation not permitted, errno = 1), address = localhost, port = 4000
#0 DioMixin.fetch (package:dio/src/dio_mixin.dart:523:7)
<asynchronous suspension>
#1 main (package:pitin_v2/main.dart:16:3)
<asynchronous suspension>
Syncing files to device macOS... 312ms
Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
A Dart VM Service on macOS is available at: http://127.0.0.1:59765/7dkvzDNSd0Q=/
The Flutter DevTools debugger and profiler on macOS is available at:
http://127.0.0.1:9102?uri=http://127.0.0.1:59765/7dkvzDNSd0Q=/
Lost connection to device.
에러
위에서도 메시지가 있었지만, 에러 메시지만 다시 보면 아래와 같다.
Failed to foreground app; open returned 1
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: DioException [connection error]: The connection errored: Connection failed This indicates an error which most likely cannot be solved by the library.
Error: SocketException: Connection failed (OS Error: Operation not permitted, errno = 1), address = localhost, port = 4000
#0 DioMixin.fetch (package:dio/src/dio_mixin.dart:523:7)
<asynchronous suspension>
#1 main (package:pitin_v2/main.dart:16:3)
<asynchronous suspension>
해결 방법
macOS에서 허용하지 않은 요청을 보내서 나온 에러 메시지인 것 같다. 찾아보니 macos/Runner/*.entitlement 파일을 수정하여 네트워크 사용 권한을 부여할 수 있다고 한다.
<key>com.apple.security.network.client</key>
<true/>
위의 내용을 아래 목록의 파일들에 추가해야 한다.
- macos/Runner/DebugProfile.entitlement
- macos/Runner/Release.entitlement
macos/Runner/DebugProfile.entitlement
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
macos/Runner/Release.entitlement
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
결과
macos/Runner/*.entitlement 파일들을 각각 수정하고 flutter run -d macos 명령얼 다시 실행했다. 에러 메시지는 없어졌다. 수신된 데이터는 확인 하지 않았지만 아마도 정상일 것이라고 생각한다.
$ flutter run -d macos
Launching lib/main.dart on macOS in debug mode...
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00008103-000654E0142A001E, name:My Mac }
{ platform:macOS, arch:x86_64, id:00008103-000654E0142A001E, name:My Mac }
Building macOS application...
✓ Built build/macos/Build/Products/Debug/pitin_v2.app
Failed to foreground app; open returned 1
Syncing files to device macOS... 267ms
Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
A Dart VM Service on macOS is available at: http://127.0.0.1:59621/ubtmmvTVXDc=/
The Flutter DevTools debugger and profiler on macOS is available at:
http://127.0.0.1:9102?uri=http://127.0.0.1:59621/ubtmmvTVXDc=/
Lost connection to device.
728x90
반응형