flutter icon indicating copy to clipboard operation
flutter copied to clipboard

Flutter run unable to attach to process on iOS 17, "Not allowed to attach to process."

Open bretmh opened this issue 1 year ago • 23 comments

Steps to reproduce

  1. Create a new flutter project running the same versions above.
  2. flutter run -d {device}

Expected results

Should be able to attach to process and be able to debug the application. Note, this started happening ever since the requirement to debug with xcode.

Actual results

Receiving this output in Xcode:
error: attach by pid '518' failed -- attach failed (Not allowed to attach to process.  Look in the console messages (Console.app), near the debugserver entries, when the attach failed.  The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)
Logging Error: Failed to initialize logging system. Log messages may be missing. If this issue persists, try setting IDEPreferLogStreaming=YES in the active scheme actions environment variables.

Code sample

Just use the default app.

Screenshots or Video

Screenshots / Video demonstration image

Logs

Logs
[        ] executing: /usr/bin/arch -arm64e xcrun osascript -l JavaScript /Users/{redacted}/flutter/packages/flutter_tools/bin/xcode_debug.js check-workspace-opened --xcode-path /Applications/Xcode.app --project-path /Users/{redacted}/work/{redacted}/ios/Runner.xcodeproj --workspace-path
/Users/{redacted}/work/{redacted}/ios/Runner.xcworkspace --verbose
[ +105 ms] {"status":true,"errorMessage":null,"debugResult":null}

                    {"command":"check-workspace-opened","xcodePath":"/Applications/Xcode.app","projectPath":"/Users/{redacted}/work/{redacted}/ios/Runner.xcodeproj","projectName":null,"expectedConfigurationBuildDir":null,"workspacePath":"/Users/{redacted}/work/{redacted}/ios/Runner.xcworkspace","tar
                    getDestinationId":null,"targetSchemeName":null,"skipBuilding":null,"launchArguments":null,"closeWindowOnStop":null,"promptToSaveBeforeClose":null,"verbose":true}
[   +1 ms] executing: /usr/bin/arch -arm64e xcrun osascript -l JavaScript /Users/{redacted}/flutter/packages/flutter_tools/bin/xcode_debug.js debug --xcode-path /Applications/Xcode.app --project-path /Users/{redacted}/work/{redacted/ios/Runner.xcodeproj --workspace-path
/Users/{redacted}/work/{redacted}/ios/Runner.xcworkspace --project-name Runner --expected-configuration-build-dir /Users/{redacted}/work/{redacted}/build/ios/iphoneos --device-id {redacted} --scheme prod --skip-building --launch-args ["--enable-dart-profiling"] --verbose
[  +37 ms] stderr:
{"command":"debug","xcodePath":"/Applications/Xcode.app","projectPath":"/Users/{redacted}/work/{redacted}/ios/Runner.xcodeproj","projectName":"Runner","expectedConfigurationBuildDir":"/Users/{redacted}/work/{redacted}/build/ios/iphoneos","workspacePath":"/Users/{redacted}/work/{redacted}/ios/Runner.xcwo
rkspace","targetDestinationId":"{redacted}","targetSchemeName":"prod","skipBuilding":true,"launchArguments":["--enable-dart-profiling"],"closeWindowOnStop":null,"promptToSaveBeforeClose":null,"verbose":true}
[  +64 ms] stderr: Workspace: /Users/{redacted}/work/{redacted}/ios/Runner.xcworkspace
[  +61 ms] stderr: Device: My Mac ({redacted})
[  +53 ms] stderr: Device: {redacted-phyiscal phone} ({redacted})
[+1254 ms] stderr: CONFIGURATION_BUILD_DIR: /Users/{redacted}/work/{redacted}/build/ios/iphoneos
[ +173 ms] stderr: Action result status: running
[ +522 ms] {"status":true,"errorMessage":null,"debugResult":{"completed":false,"status":"running","errorMessage":null}}
[   +4 ms] Application launched on the device. Waiting for Dart VM Service url.
[   +3 ms] Checking for advertised Dart VM Services...
[+59999 ms] The Dart VM Service was not discovered after 60 seconds. This is taking much longer than expected...
[   +3 ms] Open the Xcode window the project is opened in to ensure the app is running. If the app is not running, try selecting "Product > Run" to fix the problem.
[        ] No path provided for Symbols directory.

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.1 23B74 darwin-arm64, locale en-US)
    • Flutter version 3.16.9 on channel stable at /Users/{redacted}/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 41456452f2 (4 days ago), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5
    • Pub download mirror {redacted}

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/{redacted}/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.0

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

[✓] Android Studio (version 2022.2)
    • 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 17.0.6+0-17.0.6b802.4-9586694)

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

[✓] Connected device (3 available)
    • {redacted} • {redacted} • ios            • iOS 17.2.1 21C66
    • macOS (desktop)                          • macos                     • darwin-arm64   • macOS 14.1 23B74 darwin-arm64
    • Chrome (web)                             • chrome                    • web-javascript • Google Chrome 121.0.6167.85

[✓] Network resources
    • All expected network resources are available.

• No issues found!

bretmh avatar Jan 30 '24 01:01 bretmh

Thanks for filing this @bretmh. This seems to be an issue with Xcode and not flutter itself, can you check out: https://stackoverflow.com/questions/37582096/could-not-attach-to-pid-unable-to-attach and https://forums.developer.apple.com/forums/thread/120282 to see if they help in your case?

dam-ease avatar Jan 30 '24 09:01 dam-ease

Thanks for filing this @bretmh. This seems to be an issue with Xcode and not flutter itself, can you check out: https://stackoverflow.com/questions/37582096/could-not-attach-to-pid-unable-to-attach and https://forums.developer.apple.com/forums/thread/120282 to see if they help in your case?

I've tried these solutions and none of the solved the problem. Many if not all of those solutions are for simulators, I need to debug on a physical device.

This began happening after a flutter update. Someone on the flutter team introduced some JS code that helps delegating the opening of Xcode and attaching. Not sure I would put this on Xcode directly.

I've also tried to debug directly in Xcode on the device with no success.

bretmh avatar Jan 30 '24 23:01 bretmh

Reinstalled Flutter, Xcode and tooling such as Ruby and Cocoa Pods with no success.

bretmh avatar Jan 30 '24 23:01 bretmh

Thanks for your response @bretmh. Please can you share the full crash logs after running flutter run -v from terminal?

dam-ease avatar Jan 31 '24 07:01 dam-ease

@dam-ease Do you have better options to share that information?

  1. code tags, the output is too large
  2. pastebin, not an option

bretmh avatar Feb 01 '24 20:02 bretmh

Or, possibly request what parts of the log file you want?

bretmh avatar Feb 01 '24 20:02 bretmh

Thanks for your response @bretmh Please paste the logs in a .txt file and upload the file here.

dam-ease avatar Feb 02 '24 06:02 dam-ease

@bretmh try this I can do Edit Scheme -> Run -> Debug executable == false

Kanaktechtree avatar Feb 02 '24 09:02 Kanaktechtree

@bretmh try this I can do Edit Scheme -> Run -> Debug executable == false

That doesn't do anything, and I would want it to be debugging.

Thanks for your response @bretmh Please paste the logs in a .txt file and upload the file here.

Here is the log DELETED

bretmh avatar Feb 08 '24 19:02 bretmh

Thanks for your response and sharing the logs.

I think it may be related to an antivirus running on my system.

Looking through the original comment again, were you able to disable this and try running again to see if issue still persists?

dam-ease avatar Feb 09 '24 07:02 dam-ease

I had the exact same problem.

My solution was to delete all Runner Profiles (debug-dev, release-live...) and recreate them from scratch.

After that everything was working again with iOS 17.4 Beta 1, macOS 14.4 (e.g. live debugging on my physical iPhone with "debug executable" enabled)

Good Luck!

Sant0ni avatar Feb 09 '24 07:02 Sant0ni

Thanks for your response and sharing the logs.

I think it may be related to an antivirus running on my system.

Looking through the original comment again, were you able to disable this and try running again to see if issue still persists?

Checked with the antivirus and it turns out that nothing was being flagged to do with Flutter/Xcode/debugserver. Safe to say no it is not the cause.

bretmh avatar Feb 09 '24 14:02 bretmh

Getting this same error. Any updates from anyone?

amit13091992 avatar Feb 10 '24 05:02 amit13091992

Here is the log flutter_run.log

The log provided here shows below entries:

[ +301 ms] {"status":true,"errorMessage":null,"debugResult":{"completed":false,"status":"running","errorMessage":null}}
[   +1 ms] Application launched on the device. Waiting for Dart VM Service url.
[   +1 ms] Checking for advertised Dart VM Services...
[        ] No path provided for Symbols directory.

Indicating the tool is failing to find the Dart VM for iOS 17 devices. @bretmh Does the app launch on the device ? Maybe you are hitting https://github.com/flutter/flutter/issues/142448

Since I don't have iOS 17 device and latest xcode to verify this, based on the report, I'll label this for team's input / attention.

/cc @vashworth

darshankawar avatar Feb 12 '24 06:02 darshankawar

Here is the log flutter_run.log

The log provided here shows below entries:

[ +301 ms] {"status":true,"errorMessage":null,"debugResult":{"completed":false,"status":"running","errorMessage":null}}
[   +1 ms] Application launched on the device. Waiting for Dart VM Service url.
[   +1 ms] Checking for advertised Dart VM Services...
[        ] No path provided for Symbols directory.

Indicating the tool is failing to find the Dart VM for iOS 17 devices. @bretmh Does the app launch on the device ? Maybe you are hitting #142448

Since I don't have iOS 17 device and latest xcode to verify this, based on the report, I'll label this for team's input / attention.

/cc @vashworth

@darshankawar The app launches on the devices, although it stops/freezes the first few frames of the splash screen.

bretmh avatar Feb 12 '24 15:02 bretmh

@bretmh Do you also get this "attach failed (Not allowed to attach to process..." error when running a native (non-Flutter) iOS app on your physical iOS 17 device from Xcode?

vashworth avatar Feb 12 '24 15:02 vashworth

@vashworth yes i am testing on real device with os 17 and getting this error. Any solutions?

amit13091992 avatar Feb 12 '24 15:02 amit13091992

@bretmh Looking at your flutter run log, looks like get-task-allow entitlement is being set to 0, which may be causing your issue. It seems to me that you're codesigning the app with a Distribution certificate rather than a Development certificate, which can cause get-task-allow to be set to 0.

Try enabling the code signing settings through Xcode using a Development certificate: https://docs.flutter.dev/get-started/install/macos/mobile-ios?tab=physical#configure-your-target-ios-device:~:text=Enable%20developer%20code%20signing%20certificates

Please let us know if that fixes it for you.

vashworth avatar Feb 12 '24 17:02 vashworth

@vashworth my project is on react native. Any suggestions?

amit13091992 avatar Feb 12 '24 17:02 amit13091992

@vashworth my project is on react native. Any suggestions?

Unfortunately, I am unfamiliar with React Native and this issue is for Flutter applications. I would recommend filing an issue with React Native.

vashworth avatar Feb 12 '24 17:02 vashworth

@vashworth my project is on react native. Any suggestions?

Unfortunately, I am unfamiliar with React Native and this issue is for Flutter applications. I would recommend filing an issue with React Native.

Thanks for the suggestion. Will raise a new issue

amit13091992 avatar Feb 12 '24 17:02 amit13091992

@bretmh Looking at your flutter run log, looks like get-task-allow entitlement is being set to 0, which may be causing your issue. It seems to me that you're codesigning the app with a Distribution certificate rather than a Development certificate, which can cause get-task-allow to be set to 0.

Try enabling the code signing settings through Xcode using a Development certificate: https://docs.flutter.dev/get-started/install/macos/mobile-ios?tab=physical#configure-your-target-ios-device:~:text=Enable%20developer%20code%20signing%20certificates

Please let us know if that fixes it for you.

I will give this a try and report back, thank you.

bretmh avatar Feb 13 '24 16:02 bretmh

  1. Xcode > Project > Clean Build Folder
  2. Close your project
  3. Delete /Users/username/Library/Developer/Xcode/DerivedData/YourProject
  4. Open your project and Run again

It works!

JWChannel avatar Feb 16 '24 07:02 JWChannel

@bretmh Looking at your flutter run log, looks like get-task-allow entitlement is being set to 0, which may be causing your issue. It seems to me that you're codesigning the app with a Distribution certificate rather than a Development certificate, which can cause get-task-allow to be set to 0.

Try enabling the code signing settings through Xcode using a Development certificate: https://docs.flutter.dev/get-started/install/macos/mobile-ios?tab=physical#configure-your-target-ios-device:~:text=Enable%20developer%20code%20signing%20certificates

Please let us know if that fixes it for you.

Thank you @vashworth for this detailed explanation. My issue is resolved, and the following steps were taken to resolve it.

  1. Make sure you are using a Develop Provisioning Profile w/ the Dev Cert. (I was using a ADHOC+DIST)
  2. rm -rf /Users/username/Library/Developer/Xcode/DerivedData/
  3. flutter clean && flutter pub get && cd ios && pod install
  4. run any other commands such as code generation flutter pub run build_runner build --delete-conflicting-outputs
  5. flutter run to your debug device or from xcode. both work now

Note: Doing this required me to deal with the annoying Keychain Access prompt many times asking for a username/password. There was no "Always Allow" option.

bretmh avatar Feb 16 '24 21:02 bretmh

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

github-actions[bot] avatar Mar 04 '24 07:03 github-actions[bot]