Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift unable to find symbols at compile-time that are present in the iOS artifacts #118832

Closed
ricoberger opened this issue Jan 19, 2023 · 10 comments · Fixed by flutter/engine#47348
Labels
engine flutter/engine repository. See also e: labels. found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-ios iOS applications specifically r: fixed Issue is closed as already fixed in a newer version team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team

Comments

@ricoberger
Copy link

ricoberger commented Jan 19, 2023

Hi, this is a duplicate of #97968 reported by @gaaclarke, sorry that I had to open a new issue, but I'm not able to comment on the other issue.

I'm also able to reproduce this on two different MacBooks (both with an M1 chip), one with a new installation of Xcode, so that I'm not sure if this is really just related to some weird caching happening locally.

Steps to Reproduce

When I want to switch to background threads on iOS as shown in the following:

+let taskQueue = registrar.messenger.makeBackgroundTaskQueue()
+let channel = FlutterMethodChannel(name: "kubenav.io", binaryMessenger: registrar.messenger(), codec: FlutterStandardMethodCodec.sharedInstance, taskQueue: taskQueue)
-let channel = FlutterMethodChannel(name: "kubenav.io", binaryMessenger: registrar.messenger())

I receive the following error for flutter run:

[   +4 ms] Swift Compiler Error (Xcode): Value of type '() -> any FlutterBinaryMessenger' has no member 'makeBackgroundTaskQueue'
           /Users/ricoberger/Documents/GitHub/kubenav/kubenav/ios/Runner/KubenavPlugin.swift:8:40

[        ] Swift Compiler Error (Xcode): Extra argument 'taskQueue' in call
           /Users/ricoberger/Documents/GitHub/kubenav/kubenav/ios/Runner/KubenavPlugin.swift:9:160

[        ] Swift Compiler Error (Xcode): Function produces expected type 'FlutterStandardMethodCodec'; did you mean to call it with '()'?
           /Users/ricoberger/Documents/GitHub/kubenav/kubenav/ios/Runner/KubenavPlugin.swift:9:133

[   +1 ms] Could not build the application for the simulator.
[        ] Error launching application on iPhone 14 Pro.
[   +3 ms]
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:713:9)
           <asynchronous suspension>
           #2      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1209:27)
           <asynchronous suspension>
           #3      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #4      CommandRunner.runCommand (package:args/command_runner.dart:209:13)
           <asynchronous suspension>
           #5      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
           <asynchronous suspension>
           #6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #7      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
           <asynchronous suspension>
           #8      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
           <asynchronous suspension>
           #9      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #10     main (package:flutter_tools/executable.dart:91:3)
           <asynchronous suspension>

The complete file can be found here: the source code of the whole file can be found here: https://github.com/kubenav/kubenav/blob/main/ios/Runner/KubenavPlugin.swift

Logs
Analyzing kubenav...
No issues found! (ran in 4.1s)
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.1 22C65 darwin-arm, locale de-DE)
    • Flutter version 3.3.10 on channel stable at /Users/ricoberger/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (5 weeks ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/ricoberger/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = /Users/ricoberger/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2021.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 11.0.12+0-b1504.28-7817840)

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

[✓] Connected device (3 available)
    • iPhone 14 Pro (mobile) • 89F2C125-1D72-4516-AEEB-1EBECB5A143A • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.1 22C65 darwin-arm
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 109.0.5414.87

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

• No issues found!
@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Jan 20, 2023
@danagbemava-nc
Copy link
Member

Hi @ricoberger,

Can you please provide a minimal complete reproducible code sample so that we can investigate this?

I tried adding the portion commented out from your code, but for me, it seems like the apis are not available.

Screenshot 2023-01-20 at 09 55 03

Thank you

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 20, 2023
@ricoberger
Copy link
Author

ricoberger commented Jan 20, 2023

Hi @danagbemava-nc, I will do so, but what you shared is exactly the problem. The question for me is why is makeBackgroundTaskQueue not defined.

If I go to the definition of FlutterPluginRegistrar and from there to the definition of FlutterBinaryMessenger in Xcode it seems to be defined:

FLUTTER_DARWIN_EXPORT
@protocol FlutterBinaryMessenger <NSObject>
/// TODO(gaaclarke): Remove optional when macos supports Background Platform Channels.
@optional
- (NSObject<FlutterTaskQueue>*)makeBackgroundTaskQueue;

- (FlutterBinaryMessengerConnection)
    setMessageHandlerOnChannel:(NSString*)channel
          binaryMessageHandler:(FlutterBinaryMessageHandler _Nullable)handler
                     taskQueue:(NSObject<FlutterTaskQueue>* _Nullable)taskQueue;

I'm not sure if it helps, but I also tried to import Flutter.FlutterBinaryMessenger in the swift file via:

import Flutter.FlutterBinaryMessenger

If I then jump to definition of the import in Xcode it looks like the following and doesn't contain makeBackgroundTaskQueue, but only the comment:

public protocol FlutterBinaryMessenger : NSObjectProtocol {

    /// TODO(gaaclarke): Remove optional when macos supports Background Platform Channels.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 20, 2023
@danagbemava-nc
Copy link
Member

@ricoberger, thanks for the clarification. I don't think the sample will be necessary anymore.

I saw the same thing as reported in #118832 (comment) when I looked up the definitions.

Labeling for further investigation.

The code sample I used is attached below.

ct.zip

flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.1 22C65 darwin-arm, locale en-GB)
    • Flutter version 3.3.10 on channel stable at /Users/nexus/dev/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (5 weeks ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

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

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

[!] Android Studio (version 2022.1)
    • 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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[!] Android Studio (version 2022.1)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Community Edition (version 2022.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.1 22C65 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 109.0.5414.87

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

! Doctor found issues in 2 categories.
[!] Flutter (Channel master, 3.7.0-24.0.pre.22, on macOS 13.1 22C65 darwin-arm64, locale en-GB)
    • Flutter version 3.7.0-24.0.pre.22 on channel master at /Users/nexus/dev/sdks/flutters
    ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ee9c9b6927 (7 hours ago), 2023-01-20 01:27:09 -0500
    • Engine revision 3876320cbd
    • Dart version 3.0.0 (build 3.0.0-136.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 /Users/nexus/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

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

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

[!] Android Studio (version 2022.1)
    • 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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[!] Android Studio (version 2022.1)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Community Edition (version 2022.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.1 22C65 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 109.0.5414.87

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

! Doctor found issues in 3 categories.

@danagbemava-nc danagbemava-nc added platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 and removed in triage Presently being triaged by the triage team labels Jan 20, 2023
@jmagman jmagman added engine flutter/engine repository. See also e: labels. and removed tool Affects the "flutter" command-line tool. See also t: labels. labels Jan 20, 2023
@jmagman
Copy link
Member

jmagman commented Jan 20, 2023

Huh I can reproduce this too on Xcode 14.1, and the reporter is on Xcode 14.2. As @ricoberger says only the required methods are in the generated Swift protocol:

public protocol FlutterBinaryMessenger : NSObjectProtocol {

    /// TODO(gaaclarke): Remove optional when macos supports Background Platform Channels.
    
    /**
     * Sends a binary message to the Flutter side on the specified channel, expecting
     * no reply.
     *
     * @param channel The channel name.
     * @param message The message.
     */
    func send(onChannel channel: String, message: Data?)

    
    /**
     * Sends a binary message to the Flutter side on the specified channel, expecting
     * an asynchronous reply.
     *
     * @param channel The channel name.
     * @param message The message.
     * @param callback A callback for receiving a reply.
     */
    func send(onChannel channel: String, message: Data?, binaryReply callback: FlutterBinaryReply? = nil)

    
    /**
     * Registers a message handler for incoming binary messages from the Flutter side
     * on the specified channel.
     *
     * Replaces any existing handler. Use a `nil` handler for unregistering the
     * existing handler.
     *
     * @param channel The channel name.
     * @param handler The message handler.
     * @return An identifier that represents the connection that was just created to the channel.
     */
    func setMessageHandlerOnChannel(_ channel: String, binaryMessageHandler handler: FlutterBinaryMessageHandler? = nil) -> FlutterBinaryMessengerConnection

    
    /**
     * Clears out a channel's message handler if that handler is still the one that
     * was created as a result of
     * `setMessageHandlerOnChannel:binaryMessageHandler:`.
     *
     * @param connection The result from `setMessageHandlerOnChannel:binaryMessageHandler:`.
     */
    func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection)
}

Objective-C code here:
https://github.com/flutter/engine/blob/3fead63ba1008d86f4c8f386896643f82bbfcb99/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h#L47-L103

I would have expected it to generate @objc and an optional func for -makeBackgroundTaskQueue and -setMessageHandlerOnChannel:::. Is there some annotation we can add to the Objective-C header to make it visible to Swift?

cc @hellohuanlin who might be interested in this.

@chinmaygarde chinmaygarde added the P2 Important issues not at the top of the work list label Jan 23, 2023
@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team labels Jul 8, 2023
@jtdLab
Copy link

jtdLab commented Oct 25, 2023

When will the definitions be available from swift? Otherwise this does not work in swift.

@hellohuanlin
Copy link
Contributor

hellohuanlin commented Oct 26, 2023

@gaaclarke curious we have tried moving the full definition of FlutterTaskQueue from platform_message_handler_ios.h to FlutterBinaryMessenger.h?

@gaaclarke
Copy link
Member

@gaaclarke curious we have tried moving the full definition of FlutterTaskQueue from platform_message_handler_ios.h to FlutterBinaryMessenger.h?

Yea, I'm doing that right now. I think that should be enough to fix it, starting to work on it: flutter/engine#47348. It's a bit tricky because I wanted to make it private. Unfortunately some people have hacked around the issue so I may have to take that into consideration.

gaaclarke added a commit to flutter/engine that referenced this issue Oct 27, 2023
fixes flutter/flutter#118832

This makes the `FlutterTaskQueue` protocol visible, but keeps the
`dispatch:` selector private. Under the covers there are runtime checks
to make sure `dispatch:` is available since we can't have compile time
checks anymore.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
@gaaclarke
Copy link
Member

fyi @chickenblood this has landed, it will take a while to roll to you though.

@chickenblood
Copy link
Contributor

Many thanks for the turnaround.

@danagbemava-nc danagbemava-nc added the r: fixed Issue is closed as already fixed in a newer version label Oct 30, 2023
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
engine flutter/engine repository. See also e: labels. found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-ios iOS applications specifically r: fixed Issue is closed as already fixed in a newer version team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants