Skip to content

Xcode build sometimes runs 'Thin Binary' script before 'Process Info.plist' which causes mDNS errors. #118058

@vashworth

Description

@vashworth

The Thin Binary script needs to run before Process Info.plist.

The Thin Binary script calls flutter_tools/bin/xcode_backend.dart, which calls a function addObservatoryBonjourService which adds NSBonjourServices and NSLocalNetworkUsageDescription to the plist when in debug mode. If Process Info.plist is run after it, though, the plist gets regenerated and the added NSBonjourServices and NSLocalNetworkUsageDescription will be overwritten.

Steps to Reproduce

  1. flutter create my_app
  2. Open app in Xcode
  3. Set Team under Signing & Capabilities
  4. Run on a physical device through Xcode
  5. Wait until it's done building and running and then on the device, click Allow to the permission popup
  6. Click Stop icon in Xcode
  7. Run on a simulator device through Xcode
  8. Wait until it's done building and running and then click the Stop icon in Xcode
  9. Run on same physical device (from step 4) through Xcode
  10. Click Stop in Xcode
  11. Run on same physical device (from step 4) through Xcode
  12. Check Xcode console for mDNS error message

This was reproducible for me every time. There may be other ways to reproduce, but this worked for me. To repeat the process, in Xcode click Product > Clean Build Folder and then do steps 4-11.

You can check to see if it's happening by checking the build log in the Report Navigator in Xcode (see screenshot) and see Process Info.plist happens after Thin Binary. You should also see an error message in the Xcode console (see Logs below for expected error message). If running in terminal with flutter run, you should also expect to see the error message, but won't be able to see the order of events.

Screenshot 2023-01-05 at 1 33 54 PM

Findings

I found the following comment that could be a potential solution: lionheart/openradar-mirror#20408 (comment)

Logs

Logs
2023-01-05 13:27:11.669919-0600 Runner[3923:327476] [VERBOSE-2:FlutterObservatoryPublisher.mm(97)] Failed to register observatory port with mDNS with error -65555.
2023-01-05 13:27:11.669952-0600 Runner[3923:327476] [VERBOSE-2:FlutterObservatoryPublisher.mm(99)] On iOS 14+, local network broadcast in apps need to be declared in the app's Info.plist. Debug and profile Flutter apps and modules host VM services on the local network to support debugging features such as hot reload and DevTools. To make your Flutter app or module attachable and debuggable, add a '_dartobservatory._tcp' value to the 'NSBonjourServices' key in your Info.plist for the Debug/Profile configurations. For more information, see https://flutter.dev/docs/development/add-to-app/ios/project-setup#local-network-privacy-permissions

flutter doctor -v

[!] Flutter (Channel unknown, 3.7.0-14.0.pre.13, on macOS 13.1 22C65 darwin-arm64, locale en)
    ! Flutter version 3.7.0-14.0.pre.13 on channel unknown at xxx
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at
      https://flutter.dev/docs/get-started/install.
    ! Unknown upstream repository.
      Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    • Framework revision b938dc13df (3 days ago), 2023-01-02 05:47:23 -0500
    • Engine revision 472e34cbbc
    • Dart version 3.0.0 (build 3.0.0-76.0.dev)
    • DevTools version 2.20.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to
      perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at xxx
    • Platform android-33, build-tools 33.0.0
    • ANDROID_SDK_ROOT = xxx
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.74.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.56.0

[✓] Connected device (3 available)
   xxx

[✓] HTTP Host Availability
    • All required HTTP hosts are available

Metadata

Metadata

Assignees

Labels

platform-iosiOS applications specificallyt: xcode"xcodebuild" on iOS and general Xcode project managementtoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions